print labor cost
parent
af4093bc98
commit
26a77016f9
|
@ -2,8 +2,8 @@
|
|||
<field name="date" mode="month" onchange="onchange_date" span="2"/>
|
||||
<field name="date_from" required="1" span="2"/>
|
||||
<field name="date_to" required="1" span="2"/>
|
||||
<field name="type" onchange="onchange_type" span="2"/>
|
||||
<field name="staff_id" domain='[["type","=",type]]' span="2"/>
|
||||
<field name="staff_type" onchange="onchange_type" span="2"/>
|
||||
<field name="staff_id" domain='[["type","=",staff_type]]' span="2"/>
|
||||
<field name="branch_id" span="2"/>
|
||||
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
|
||||
<field name="categ_id" span="2"/>
|
||||
|
|
|
@ -23,6 +23,10 @@ class PrintLaborCost(Model):
|
|||
'lines': fields.One2Many("clinic.print.labor.cost.line","print_labor_cost_id","Lines"),
|
||||
'sum_report_id': fields.Many2One("clinic.report.labor.cost.summary","Summary Report"),
|
||||
'lc_report_id': fields.Many2One("clinic.report.labor.cost","Labor Cost Report"),
|
||||
'dt_report_id': fields.Many2One("clinic.report.labor.cost.detail","Detail Report"),
|
||||
'sub_dt_report_id': fields.Many2One("clinic.report.labor.cost.sub.detail","Sub Detail Report"),
|
||||
'dl_report_id': fields.Many2One("clinic.report.labor.cost.daily","Daily Report"),
|
||||
'ot_report_id': fields.Many2One("clinic.report.labor.cost.overtime","Overtime Report"),
|
||||
'report_summary': fields.File("Summary"),
|
||||
'report_labor_cost': fields.File("Labor Cost"),
|
||||
}
|
||||
|
@ -61,6 +65,8 @@ class PrintLaborCost(Model):
|
|||
|
||||
def generate_report(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
# clear and reload
|
||||
obj.reload()
|
||||
|
||||
def load_report(fname,link):
|
||||
req=urllib.request.Request(link)
|
||||
|
@ -129,38 +135,75 @@ class PrintLaborCost(Model):
|
|||
|
||||
db.commit()
|
||||
|
||||
#period_name='%sto%s'%(obj.date_from,obj.date_to[-2:])
|
||||
#lcname='labor.cost.xlsx'
|
||||
#link='http://localhost:9999/report_export_xls?model=clinic.report.labor.cost&template=report_labor_cost&active_id=%s'%(lc_id)
|
||||
#load_report(lcname,link)
|
||||
|
||||
lcname='labor.cost.xlsx'
|
||||
link='http://localhost:9999/report_export_xls?model=clinic.report.labor.cost&template=report_labor_cost&active_id=%s'%(lc_id)
|
||||
load_report(lcname,link)
|
||||
#sum_name='labor.cost-summary.xlsx'
|
||||
#link='http://localhost:9999/report_export_xls?model=clinic.report.labor.cost.summary&template=report_labor_cost_summary&active_id=%s'%(sum_id)
|
||||
#load_report(sum_name,link)
|
||||
|
||||
sum_name='labor.cost-summary.xlsx'
|
||||
link='http://localhost:9999/report_export_xls?model=clinic.report.labor.cost.summary&template=report_labor_cost_summary&active_id=%s'%(sum_id)
|
||||
load_report(sum_name,link)
|
||||
|
||||
obj.write({
|
||||
'report_summary': sum_name,
|
||||
'report_labor_cost': lcname,
|
||||
})
|
||||
db.commit()
|
||||
|
||||
for line in obj.lines:
|
||||
staff=line.staff_id
|
||||
report_sum.write({
|
||||
'staff_id': staff.id,
|
||||
})
|
||||
db.commit()
|
||||
|
||||
#period_name='%sto%s'%(obj.date_from,obj.date_to[-2:])
|
||||
#fname='%s-%s-%s-detail.xlsx'%(staff.name,period_name,active_id)
|
||||
#link='http://localhost:9999/report_export_xls?model=clinic.report.labor.cost.summary&template=report_labor_cost_summary&active_id=%s'%(active_id)
|
||||
#load_report(fname,link)
|
||||
|
||||
#line.write({
|
||||
#'report_detail': fname,
|
||||
#obj.write({
|
||||
#'report_summary': sum_name,
|
||||
#'report_labor_cost': lcname,
|
||||
#})
|
||||
#db.commit()
|
||||
#db.commit()
|
||||
|
||||
report_lines=[
|
||||
{'report_file': 'report_detail','model': 'clinic.report.labor.cost.detail', 'report_id': obj.dt_report_id.id,'field_name': 'dt_report_id'},
|
||||
{'report_file': 'report_sub_detail','model': 'clinic.report.labor.cost.sub.detail', 'report_id': obj.sub_dt_report_id.id,'field_name': 'sub_dt_report_id'},
|
||||
{'report_file': 'report_daily','model': 'clinic.report.labor.cost.daily', 'report_id': obj.dl_report_id.id,'field_name': 'dl_report_id'},
|
||||
{'report_file': 'report_ot','model': 'clinic.report.labor.cost.overtime', 'report_id': obj.ot_report_id.id,'field_name': 'ot_report_id'},
|
||||
]
|
||||
count=0
|
||||
for line in obj.lines:
|
||||
if count >= 2:
|
||||
print("Break!")
|
||||
break
|
||||
staff=line.staff_id
|
||||
for report_line in report_lines:
|
||||
name=staff.number or staff.name or staff.id
|
||||
fname='%s-%s.xlsx'%(name,report_line['report_file'])
|
||||
report_file=report_line['report_file']
|
||||
report_model=report_line['model']
|
||||
report_template=report_model.replace(".","_").replace("clinic_","")
|
||||
report_id=report_line['report_id']
|
||||
if not report_id:
|
||||
report_id=get_model(report_model).create({
|
||||
'date': obj.date_from,
|
||||
'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_id': staff.id,
|
||||
})
|
||||
report_obj=get_model(report_model).browse(report_id)
|
||||
db.commit()
|
||||
else:
|
||||
report_obj=get_model(report_model).browse(report_id)
|
||||
report_obj.write({
|
||||
'date': obj.date_from,
|
||||
'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_id': staff.id,
|
||||
})
|
||||
db.commit()
|
||||
|
||||
obj.write({
|
||||
report_line['field_name']: report_id,
|
||||
})
|
||||
db.commit()
|
||||
link='http://localhost:9999/report_export_xls?model=%s&template=%s&active_id=%s'%(report_model,report_template,report_obj.id)
|
||||
load_report(fname,link)
|
||||
line.write({
|
||||
report_file: fname,
|
||||
})
|
||||
db.commit()
|
||||
count+=1
|
||||
print("Done!")
|
||||
|
||||
def _get_date_from(self,context={}):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import time
|
||||
|
||||
from netforce.model import Model,fields,get_model
|
||||
from netforce.access import get_active_company
|
||||
from netforce.access import get_active_company, set_active_company, get_active_user, set_active_user
|
||||
|
||||
class ReportLaborCostDaily(Model):
|
||||
_name="clinic.report.labor.cost.daily"
|
||||
|
@ -10,10 +10,13 @@ class ReportLaborCostDaily(Model):
|
|||
|
||||
_fields={
|
||||
"date": fields.Date("Date"),
|
||||
"date_from": fields.Date("From"), # use for generate
|
||||
"date_to": fields.Date("To"), # use for generate
|
||||
"staff_type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
|
||||
'staff_id': fields.Many2One("clinic.staff","Staff"),
|
||||
'department_id': fields.Many2One("clinic.department",'Department'),
|
||||
'branch_id': fields.Many2One("clinic.branch","Branch"),
|
||||
'cycle_id': fields.Many2One("clinic.cycle","Cycle"), # use for generate
|
||||
}
|
||||
|
||||
def default_get(self,field_names=None,context={},**kw):
|
||||
|
@ -35,6 +38,14 @@ class ReportLaborCostDaily(Model):
|
|||
|
||||
def get_report_data(self,ids,context={}):
|
||||
company_id=get_active_company()
|
||||
user_id=get_active_user()
|
||||
if not company_id:
|
||||
set_active_company(1)
|
||||
company_id=1
|
||||
if not user_id:
|
||||
set_active_user(1)
|
||||
user_id=1
|
||||
|
||||
comp=get_model("company").browse(company_id)
|
||||
defaults=self.default_get(context=context)
|
||||
date=defaults.get("date")
|
||||
|
@ -132,6 +143,8 @@ class ReportLaborCostDaily(Model):
|
|||
'lines': lines,
|
||||
'date': date,
|
||||
}
|
||||
set_active_company(company_id)
|
||||
set_active_user(user_id)
|
||||
return data
|
||||
|
||||
def onchange_type(self,context={}):
|
||||
|
|
|
@ -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_company, get_active_user, set_active_user
|
||||
|
||||
class ReportLaborCostDetail(Model):
|
||||
_name="clinic.report.labor.cost.detail"
|
||||
|
@ -15,7 +15,7 @@ class ReportLaborCostDetail(Model):
|
|||
"date_to": fields.Date("To", required=True),
|
||||
'department_id': fields.Many2One("clinic.department","Department"),
|
||||
'staff_id': fields.Many2One("clinic.staff","Staff"),
|
||||
"type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
|
||||
"staff_type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
|
||||
'department_id': fields.Many2One("clinic.department","Department"),
|
||||
'branch_id': fields.Many2One("clinic.branch","Branch"),
|
||||
'cycle_id': fields.Many2One("clinic.cycle","Cycle"),
|
||||
|
@ -61,7 +61,7 @@ class ReportLaborCostDetail(Model):
|
|||
'date': time.strftime("%Y-%m-%d"),
|
||||
'date_from': date_from,
|
||||
'date_to': date_to,
|
||||
'type': staff_type,
|
||||
'staff_type': staff_type,
|
||||
'staff_id': staff_id or None,
|
||||
'department_id': department_id or None,
|
||||
'branch_id': branch_id or None,
|
||||
|
@ -73,11 +73,18 @@ class ReportLaborCostDetail(Model):
|
|||
|
||||
def get_report_data(self,ids,context={}):
|
||||
company_id=get_active_company()
|
||||
user_id=get_active_user()
|
||||
if not company_id:
|
||||
set_active_company(1)
|
||||
company_id=1
|
||||
if not user_id:
|
||||
set_active_user(1)
|
||||
user_id=1
|
||||
comp=get_model("company").browse(company_id)
|
||||
defaults=self.default_get(context=context)
|
||||
date_from=defaults.get("date_from")
|
||||
date_to=defaults.get("date_to")
|
||||
staff_type=defaults.get("type")
|
||||
staff_type=defaults.get("staff_type")
|
||||
staff_id=defaults.get("staff_id")
|
||||
department_id=defaults.get("department_id")
|
||||
branch_id=defaults.get("branch_id")
|
||||
|
@ -89,7 +96,7 @@ class ReportLaborCostDetail(Model):
|
|||
date_from=obj.date_from
|
||||
date_to=obj.date_to
|
||||
staff_id=obj.staff_id.id
|
||||
staff_type=obj.type
|
||||
staff_type=obj.staff_type
|
||||
department_id=obj.department_id.id
|
||||
branch_id=obj.branch_id.id
|
||||
cycle_id=obj.cycle_id.id
|
||||
|
@ -309,6 +316,8 @@ class ReportLaborCostDetail(Model):
|
|||
data['total_lines_txt'][0]['item%s_qty'%no]=int2ths(tline['qty'])
|
||||
data['total_lines_txt'][0]['item%s_amt'%no]=int2ths(tline['amt'])
|
||||
no+=1
|
||||
set_active_company(company_id)
|
||||
set_active_user(user_id)
|
||||
return data
|
||||
|
||||
def onchange_date(self,context={}):
|
||||
|
|
|
@ -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_company, get_active_user, set_active_user
|
||||
|
||||
class ReportLaborCostOverTime(Model):
|
||||
_name="clinic.report.labor.cost.overtime"
|
||||
|
@ -15,6 +15,8 @@ class ReportLaborCostOverTime(Model):
|
|||
"date_to": fields.Date("To", required=True),
|
||||
'staff_id': fields.Many2One("clinic.staff","Staff"),
|
||||
"type": fields.Selection([["nurse","Nurse"]],"Type"),
|
||||
'branch_id': fields.Many2One("clinic.branch","Branch"), #use for generate
|
||||
'cycle_id': fields.Many2One("clinic.cycle","Cycle"), #use for generate
|
||||
'department_id': fields.Many2One("clinic.department","Department"),
|
||||
'level_id': fields.Many2One("clinic.staff.level","Level"),
|
||||
'categ_id': fields.Many2One("clinic.staff.categ","Category"),
|
||||
|
@ -42,8 +44,16 @@ class ReportLaborCostOverTime(Model):
|
|||
}
|
||||
|
||||
def get_report_data(self,ids,context={}):
|
||||
setting=get_model("clinic.setting").browse(1)
|
||||
base_salary_day=setting.base_salary_day or 1
|
||||
#setting=get_model("clinic.setting").browse(1)
|
||||
#base_salary_day=setting.base_salary_day or 1
|
||||
company_id=get_active_company()
|
||||
user_id=get_active_user()
|
||||
if not company_id:
|
||||
set_active_company(1)
|
||||
company_id=1
|
||||
if not user_id:
|
||||
set_active_user(1)
|
||||
user_id=1
|
||||
res=get_model("clinic.report.labor.cost.overtime").default_get(context=context)
|
||||
date_from=res['date_from']
|
||||
date_to=res['date_to']
|
||||
|
@ -168,6 +178,8 @@ class ReportLaborCostOverTime(Model):
|
|||
data['total_wage']+=line['staff_wage'] or 0
|
||||
data['total_net_pay']+=line['net_pay'] or 0
|
||||
data['total_net_diff']+=line['net_diff'] or 0
|
||||
set_active_company(company_id)
|
||||
set_active_user(user_id)
|
||||
return data
|
||||
|
||||
def onchange_date(self,context={}):
|
||||
|
|
|
@ -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_company, get_active_user, set_active_user
|
||||
|
||||
class ReportLaborCostSubDetail(Model):
|
||||
_name="clinic.report.labor.cost.sub.detail"
|
||||
|
@ -17,6 +17,7 @@ class ReportLaborCostSubDetail(Model):
|
|||
"staff_type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
|
||||
'branch_id': fields.Many2One("clinic.branch","Branch"),
|
||||
'department_id': fields.Many2One("clinic.department","Department"),
|
||||
'cycle_id': fields.Many2One("clinic.cycle","Cycle"),
|
||||
}
|
||||
|
||||
def _get_date_from(self,context={}):
|
||||
|
@ -61,6 +62,13 @@ class ReportLaborCostSubDetail(Model):
|
|||
|
||||
def get_report_data(self,ids,context={}):
|
||||
company_id=get_active_company()
|
||||
user_id=get_active_user()
|
||||
if not company_id:
|
||||
set_active_company(1)
|
||||
company_id=1
|
||||
if not user_id:
|
||||
set_active_user(1)
|
||||
user_id=1
|
||||
comp=get_model("company").browse(company_id)
|
||||
defaults=self.default_get(context=context)
|
||||
date_from=defaults.get("date_from")
|
||||
|
@ -132,7 +140,6 @@ class ReportLaborCostSubDetail(Model):
|
|||
line['no']=no
|
||||
slines.append(line)
|
||||
no+=1
|
||||
|
||||
data={
|
||||
'staff_name': staff_name,
|
||||
'staff_id': staff_id,
|
||||
|
@ -143,6 +150,8 @@ class ReportLaborCostSubDetail(Model):
|
|||
'lines': slines,
|
||||
'amount_total': amount_total,
|
||||
}
|
||||
set_active_company(company_id)
|
||||
set_active_user(user_id)
|
||||
return data
|
||||
|
||||
def onchange_date(self,context={}):
|
||||
|
|
Loading…
Reference in New Issue