print labor cost
							parent
							
								
									6cb01fd8ef
								
							
						
					
					
						commit
						8437e7adfd
					
				| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
<record model="action">
 | 
			
		||||
    <field name="name">clinic_print_labor_cost</field>
 | 
			
		||||
    <field name="view_cls">form_view</field>
 | 
			
		||||
    <field name="model">clinic.print.labor.cost</field>
 | 
			
		||||
    <field name="view_xml">clinic_print_labor_cost</field>
 | 
			
		||||
    <field name="active_id">1</field>
 | 
			
		||||
    <field name="menu">account_menu</field>
 | 
			
		||||
</record>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1,28 +1,28 @@
 | 
			
		|||
<inherit inherit="account_menu">
 | 
			
		||||
    <item string="Settings" position="before">
 | 
			
		||||
        <item string="Ratchawat">
 | 
			
		||||
            <item string="Labor Costs" action="clinic_labor_cost"/>
 | 
			
		||||
            <item string="Account Product" action="clinic_setting_account_product"/>
 | 
			
		||||
            <item string="Account Patient" action="clinic_setting_account_patient"/>
 | 
			
		||||
            <item string="Payment Matching" action="clinic_matching_payment"/>
 | 
			
		||||
            <item string="Payment Invoices" action="clinic_invoice_payment"/>
 | 
			
		||||
            <item string="HD Cases Matching" action="clinic_matching_hdcase_acc"/>
 | 
			
		||||
            <divider/>
 | 
			
		||||
            <header string="REPORTS"/>
 | 
			
		||||
            <item string="HD Case Expense" action="clinic_report_account_hd_case_summary"/>
 | 
			
		||||
            <item string="RD Shop Expense" action="clinic_report_account_shop"/>
 | 
			
		||||
            <item string="Labor Cost Overview" action="clinic_report_labor_cost"/>
 | 
			
		||||
            <!--<item string="Labor Cost Summary" action="clinic_report_labor_cost_summary"/>-->
 | 
			
		||||
            <!--<item string="Labor Cost Detail" action="clinic_report_labor_cost_detail"/>-->
 | 
			
		||||
            <!--<item string="Labor Cost Sub Detail" action="clinic_report_labor_cost_sub_detail"/>-->
 | 
			
		||||
            <!--<item string="Labor Cost Daily" action="clinic_report_labor_cost_daily"/>-->
 | 
			
		||||
            <item string="Labor Cost Overtime" action="clinic_report_labor_cost_overtime"/>
 | 
			
		||||
            <item string="HD Cases Matching" action="clinic_matching_hdcase_acc"/>
 | 
			
		||||
            <item string="Payment Matching" action="clinic_matching_payment"/>
 | 
			
		||||
            <item string="Payment Invoices" action="clinic_invoice_payment"/>
 | 
			
		||||
            <divider/>
 | 
			
		||||
            <header string="OTHERS"/>
 | 
			
		||||
            <item string="Ratchawat Settings" action="clinic_account_setting"/>
 | 
			
		||||
            <item string="Compute Labor Cost" action="clinic_compute_labor_cost"/>
 | 
			
		||||
            <item string="Recompute Cost" action="clinic_compute_labor_cost"/>
 | 
			
		||||
            <item string="Print Labor Cost" action="clinic_print_labor_cost"/>
 | 
			
		||||
            <item string="Labor Costs" action="clinic_report_labor_cost"/>
 | 
			
		||||
            <item string="Labor Cost Summary" action="clinic_report_labor_cost_summary"/>
 | 
			
		||||
            <item string="Labor Cost Detail" action="clinic_report_labor_cost_detail"/>
 | 
			
		||||
            <item string="Labor Cost Sub Detail" action="clinic_report_labor_cost_sub_detail"/>
 | 
			
		||||
            <item string="Labor Cost Daily" action="clinic_report_labor_cost_daily"/>
 | 
			
		||||
            <item string="Labor Cost Overtime" action="clinic_report_labor_cost_overtime"/>
 | 
			
		||||
        </item>
 | 
			
		||||
    </item>
 | 
			
		||||
    <item string="Financial Settings" position="after">
 | 
			
		||||
            <item string="Ratchawat Settings" action="clinic_account_setting"/>
 | 
			
		||||
            <item string="Labor Costs" action="clinic_labor_cost"/>
 | 
			
		||||
    </item>
 | 
			
		||||
    <item string="Conversion Balances" position="after">
 | 
			
		||||
        <item string="Pay Period" action="clinic_period"/>
 | 
			
		||||
    </item>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,4 @@
 | 
			
		|||
<form model="clinic.compute.labor.cost" title="Compute Labor Cost">
 | 
			
		||||
<!--<field name="date" span="2" mode="month" onchange="onchange_date"/>-->
 | 
			
		||||
<form model="clinic.compute.labor.cost" title="Recompute Cost">
 | 
			
		||||
    <field name="period_id" domain='[["state","=","open"]]' onchange="onchange_period" span="4"/>
 | 
			
		||||
    <field name="date_from" span="4"/>
 | 
			
		||||
    <field name="date_to" span="4"/>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,23 @@
 | 
			
		|||
<form model="clinic.print.labor.cost" title="Print Labor Cost">
 | 
			
		||||
    <head>
 | 
			
		||||
        <button string="Print" method="do_print" icon="print" type="default"/>
 | 
			
		||||
    </head>
 | 
			
		||||
    <group form_layout="stacked">
 | 
			
		||||
        <field name="period_id" domain='[["state","=","open"]]' onchange="onchange_period" span="2"/>
 | 
			
		||||
        <field name="date_from" span="2"/>
 | 
			
		||||
        <field name="date_to" span="2"/>
 | 
			
		||||
        <field name="branch_id" onchange='onchange_branch' span="2"/>
 | 
			
		||||
        <field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
 | 
			
		||||
        <field name="cycle_id" span="2"/>
 | 
			
		||||
        <field name="staff_type" span="2"/>
 | 
			
		||||
        <button string="Reload" method="reload" icon="repeat" type="primary"/>
 | 
			
		||||
        <field name="lines" nolabel="1">
 | 
			
		||||
            <list>
 | 
			
		||||
                <field name="staff_id" domain='[["type","=",parent.staff_type]]'/>
 | 
			
		||||
            </list>
 | 
			
		||||
        </field>
 | 
			
		||||
    </group>
 | 
			
		||||
    <foot replace="1">
 | 
			
		||||
    <!--<button string="Print" method="do_print" icon="print" type="default"/>-->
 | 
			
		||||
    </foot>
 | 
			
		||||
</form>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
from . import clinic_setting
 | 
			
		||||
from . import hdcase
 | 
			
		||||
from . import print_labor_cost
 | 
			
		||||
#from . import hdcase
 | 
			
		||||
#from . import remove_conv_bal
 | 
			
		||||
#from . import import_acc
 | 
			
		||||
#from . import update_labor_cost_line
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,25 +9,6 @@ class Migration(migration.Migration):
 | 
			
		|||
        res=get_model("clinic.setting").search([])
 | 
			
		||||
        if not res:
 | 
			
		||||
            get_model("clinic.setting").create({})
 | 
			
		||||
 | 
			
		||||
        seq_names=[
 | 
			
		||||
            ('HDC-','Clinic HD Case'),
 | 
			
		||||
            ('VS-', 'Clinic Visit'),
 | 
			
		||||
            ('PS-', 'Clinic Personal'),
 | 
			
		||||
            ('PT-', 'Clinic Patient'),
 | 
			
		||||
            ('DT-', 'Clinic Doctor'),
 | 
			
		||||
            ('NS-', 'Clinic Nurse'),
 | 
			
		||||
            ]
 | 
			
		||||
        for prefix, seq_name in seq_names:
 | 
			
		||||
            seq_ids=get_model('sequence').search([['name','=',seq_name]])
 | 
			
		||||
            if not seq_ids:
 | 
			
		||||
                get_model("sequence").create({
 | 
			
		||||
                    'prefix': prefix,
 | 
			
		||||
                    'name': seq_name,
 | 
			
		||||
                    'type': 'other',
 | 
			
		||||
                })
 | 
			
		||||
                print("create seq %s successfully " % seq_name)
 | 
			
		||||
        # insert into clinic_personal(number,name,type, state,picture, active) select number, name,'doctor','temporary', picture,  true  from clinic_doctor;
 | 
			
		||||
        return
 | 
			
		||||
 | 
			
		||||
Migration.register()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,37 @@
 | 
			
		|||
import time
 | 
			
		||||
 | 
			
		||||
from netforce.model import get_model
 | 
			
		||||
from netforce import migration
 | 
			
		||||
from netforce.access import set_active_user, get_active_user, set_active_company, get_active_company
 | 
			
		||||
 | 
			
		||||
class Migration(migration.Migration):
 | 
			
		||||
    _name="clinic.print.labor.cost"
 | 
			
		||||
    _version="2.11.0"
 | 
			
		||||
    
 | 
			
		||||
    def migrate(self):
 | 
			
		||||
        user_id=get_active_user()
 | 
			
		||||
        company_id=get_active_company()
 | 
			
		||||
        set_active_company(1)
 | 
			
		||||
        set_active_user(1)
 | 
			
		||||
        date_from=get_model("clinic.report.labor.cost")._get_date_from()
 | 
			
		||||
        date_to=get_model("clinic.report.labor.cost")._get_date_to()
 | 
			
		||||
        yearnow=date_from.split("-")[0]
 | 
			
		||||
        for period in get_model('clinic.period').search_browse([['name','=',yearnow]]):
 | 
			
		||||
            for line in period.lines:
 | 
			
		||||
                if line.state=='open':
 | 
			
		||||
                    period_id=line.id
 | 
			
		||||
                    date_from=line.date_start
 | 
			
		||||
                    date_to=line.date_stop
 | 
			
		||||
                    break
 | 
			
		||||
        vals={
 | 
			
		||||
            'period_id': period_id,
 | 
			
		||||
            'date': time.strftime("%Y-%m-%d"),
 | 
			
		||||
            'date_from': date_from,
 | 
			
		||||
            'date_to': date_to,
 | 
			
		||||
        }
 | 
			
		||||
        get_model('clinic.print.labor.cost').create(vals)
 | 
			
		||||
        set_active_company(company_id)
 | 
			
		||||
        set_active_user(user_id)
 | 
			
		||||
        return True
 | 
			
		||||
 | 
			
		||||
Migration.register()
 | 
			
		||||
| 
						 | 
				
			
			@ -138,5 +138,5 @@ from . import province
 | 
			
		|||
from . import change_visit
 | 
			
		||||
from . import share_location
 | 
			
		||||
from . import report_cycle_setting
 | 
			
		||||
#from . import district
 | 
			
		||||
#from . import subdistrict
 | 
			
		||||
from . import print_labor_cost
 | 
			
		||||
from . import print_labor_cost_line
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,109 @@
 | 
			
		|||
import time
 | 
			
		||||
from calendar import monthrange
 | 
			
		||||
 | 
			
		||||
from netforce.model import Model,fields,get_model
 | 
			
		||||
 | 
			
		||||
class PrintLaborCost(Model):
 | 
			
		||||
    _name="clinic.print.labor.cost"
 | 
			
		||||
    _string="Print Report Labor Cost"
 | 
			
		||||
    
 | 
			
		||||
    _fields={
 | 
			
		||||
        "date": fields.Date("Month"),
 | 
			
		||||
        "period_id": fields.Many2One("clinic.period.line","Period"),
 | 
			
		||||
        "date_from": fields.Date("From", required=True),
 | 
			
		||||
        "date_to": fields.Date("To", required=True),
 | 
			
		||||
        "cycle_id": fields.Many2One("clinic.cycle","Cycle"),
 | 
			
		||||
        "branch_id": fields.Many2One("clinic.branch","Branch"),
 | 
			
		||||
        "department_id": fields.Many2One("clinic.department","Department"),
 | 
			
		||||
        "staff_type": fields.Selection([['staff','Staff'],["doctor","Doctor"],["nurse","Nurse"]],"Type"),
 | 
			
		||||
        'lines': fields.One2Many("clinic.print.labor.cost.line","print_labor_cost_id","Lines"),
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    def reload(self,ids,context={}):
 | 
			
		||||
        obj=self.browse(ids)[0]
 | 
			
		||||
        context['defaults']={
 | 
			
		||||
            'date_from': obj.date_from,
 | 
			
		||||
            'date_to': obj.date_to,
 | 
			
		||||
            'cycle_id': obj.cycle_id.id,
 | 
			
		||||
            'branch_id': obj.branch_id.id,
 | 
			
		||||
            'department_id': obj.department_id.id,
 | 
			
		||||
            'staff_type': obj.staff_type,
 | 
			
		||||
        }
 | 
			
		||||
        cost_lines=get_model('clinic.report.labor.cost.summary').get_report_data(ids=[],context=context)['lines']
 | 
			
		||||
        for line in obj.lines:
 | 
			
		||||
            line.delete()
 | 
			
		||||
        lines=[]
 | 
			
		||||
        for cost_line in cost_lines:
 | 
			
		||||
            staff_id=cost_line['staff_id']
 | 
			
		||||
            lines.append(('create',{
 | 
			
		||||
                'staff_id': staff_id,
 | 
			
		||||
            }))
 | 
			
		||||
        obj.write({
 | 
			
		||||
            'lines': lines,
 | 
			
		||||
        })
 | 
			
		||||
        return
 | 
			
		||||
    
 | 
			
		||||
    def do_print(self,ids,context={}):
 | 
			
		||||
        data={}
 | 
			
		||||
        return data
 | 
			
		||||
 | 
			
		||||
    def _get_date_from(self,context={}):
 | 
			
		||||
        year,month,day=time.strftime("%Y-%m-%d").split("-")
 | 
			
		||||
        #return '%s-%s-01'%(year,month)
 | 
			
		||||
        return '%s-%s-%s'%(year,month,day)
 | 
			
		||||
 | 
			
		||||
    def _get_date_to(self,context={}):
 | 
			
		||||
        year,month,day=time.strftime("%Y-%m-%d").split("-")
 | 
			
		||||
        weekday, total_day=monthrange(int(year), int(month))
 | 
			
		||||
        #return "%s-%s-%s"%(year,month,total_day)
 | 
			
		||||
        return "%s-%s-%s"%(year,month,day)
 | 
			
		||||
 | 
			
		||||
    def default_get(self,field_names=None,context={},**kw):
 | 
			
		||||
        defaults=context.get("defaults",{})
 | 
			
		||||
        date_from=defaults.get("date_from", self._get_date_from())
 | 
			
		||||
        date_to=defaults.get("date_to", self._get_date_to())
 | 
			
		||||
        print('defaults ', defaults)
 | 
			
		||||
        yearnow=date_from.split("-")[0]
 | 
			
		||||
        for period in get_model('clinic.period').search_browse([['name','=',yearnow]]):
 | 
			
		||||
            for line in period.lines:
 | 
			
		||||
                if line.state=='open':
 | 
			
		||||
                    period_id=line.id
 | 
			
		||||
                    date_from=line.date_start
 | 
			
		||||
                    date_to=line.date_stop
 | 
			
		||||
                    break
 | 
			
		||||
        res={
 | 
			
		||||
            'period_id': period_id,
 | 
			
		||||
            'date': time.strftime("%Y-%m-%d"),
 | 
			
		||||
            'date_from': date_from,
 | 
			
		||||
            'date_to': date_to,
 | 
			
		||||
        }
 | 
			
		||||
        return res
 | 
			
		||||
    
 | 
			
		||||
    def onchange_date(self,context={}):
 | 
			
		||||
        data=context['data']
 | 
			
		||||
        date=data['date']
 | 
			
		||||
        year,month,day=date.split("-")
 | 
			
		||||
        weekday, total_day=monthrange(int(year), int(month))
 | 
			
		||||
        data['date_from']="%s-%s-01"%(year,month)
 | 
			
		||||
        data['date_to']="%s-%s-%s"%(year,month,total_day)
 | 
			
		||||
        return data
 | 
			
		||||
 | 
			
		||||
    def onchange_branch(self,context={}):
 | 
			
		||||
        data=context['data']
 | 
			
		||||
        data['department_id']=None
 | 
			
		||||
        return data
 | 
			
		||||
 | 
			
		||||
    def onchange_from(self,context={}):
 | 
			
		||||
        data=context['data']
 | 
			
		||||
        data['date_to']=data['date_from']
 | 
			
		||||
        return data
 | 
			
		||||
    
 | 
			
		||||
    def onchange_period(self,context={}):   
 | 
			
		||||
        data=context['data']
 | 
			
		||||
        period_id=data['period_id']
 | 
			
		||||
        period=get_model('clinic.period.line').browse(period_id)
 | 
			
		||||
        data['date_from']=period.date_start
 | 
			
		||||
        data['date_to']=period.date_stop
 | 
			
		||||
        return data
 | 
			
		||||
 | 
			
		||||
PrintLaborCost.register()
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,18 @@
 | 
			
		|||
from netforce.model import Model,fields
 | 
			
		||||
 | 
			
		||||
class PrintLaborCostLine(Model):
 | 
			
		||||
    _name="clinic.print.labor.cost.line"
 | 
			
		||||
    _string="Print Report Labor Cost Line"
 | 
			
		||||
    
 | 
			
		||||
    _fields={
 | 
			
		||||
        "print_labor_cost_id": fields.Many2One("clinic.print.labor.cost","Print Labor Cost",required=True,on_delete="cascade"),
 | 
			
		||||
        'staff_id': fields.Many2One("clinic.staff","Staff"),
 | 
			
		||||
        'print': fields.Boolean("Print"),
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    _defaults={
 | 
			
		||||
        'print': True,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
PrintLaborCostLine.register()
 | 
			
		||||
| 
						 | 
				
			
			@ -2,7 +2,7 @@ import time
 | 
			
		|||
from calendar import monthrange
 | 
			
		||||
 | 
			
		||||
from netforce.model import Model,fields,get_model
 | 
			
		||||
from netforce.access import get_active_company
 | 
			
		||||
from netforce.access import get_active_company, set_active_user, get_active_user, set_active_company
 | 
			
		||||
 | 
			
		||||
class ReportLaborCostSummary(Model):
 | 
			
		||||
    _name="clinic.report.labor.cost.summary"
 | 
			
		||||
| 
						 | 
				
			
			@ -121,14 +121,14 @@ class ReportLaborCostSummary(Model):
 | 
			
		|||
                return r
 | 
			
		||||
            return "{0:,.0f}".format(r) 
 | 
			
		||||
        total_hdcase=0
 | 
			
		||||
        print("----> ", dom)
 | 
			
		||||
        for line in get_model("clinic.labor.cost.line").search_browse(dom):
 | 
			
		||||
            lcost=line.labor_cost_id
 | 
			
		||||
            citem=lcost.cycle_item_id
 | 
			
		||||
            dpt=citem.department_id
 | 
			
		||||
            qty=line.qty or 0 #XXX
 | 
			
		||||
            qty=line.qty or 0
 | 
			
		||||
            total_hdcase+=qty
 | 
			
		||||
            #amt=line.pay_amount or 0 #XXX
 | 
			
		||||
            amt=line.amount or 0 #XXX
 | 
			
		||||
            amt=line.amount or 0
 | 
			
		||||
            staff=line.staff_id
 | 
			
		||||
            categ_name=''
 | 
			
		||||
            categ_id=None
 | 
			
		||||
| 
						 | 
				
			
			@ -313,6 +313,10 @@ class ReportLaborCostSummary(Model):
 | 
			
		|||
        for tline in data['total_lines']:
 | 
			
		||||
            data['total_lines_txt'][0]['item%s'%no]=tline['amt']
 | 
			
		||||
            no+=1
 | 
			
		||||
 | 
			
		||||
        #for nline in nlines:
 | 
			
		||||
            #for sub_line in nline['sub_lines']:
 | 
			
		||||
                #print(nline['staff_name'], sub_line)
 | 
			
		||||
        return data
 | 
			
		||||
 | 
			
		||||
    def onchange_date(self,context={}):
 | 
			
		||||
| 
						 | 
				
			
			@ -334,4 +338,6 @@ class ReportLaborCostSummary(Model):
 | 
			
		|||
        data['department_id']=None
 | 
			
		||||
        return data
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
ReportLaborCostSummary.register()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue