print labor cost

conv_bal
watcha.h 2015-07-29 22:56:58 +07:00
parent af4093bc98
commit 26a77016f9
6 changed files with 129 additions and 43 deletions

View File

@ -2,8 +2,8 @@
<field name="date" mode="month" onchange="onchange_date" span="2"/> <field name="date" mode="month" onchange="onchange_date" span="2"/>
<field name="date_from" required="1" span="2"/> <field name="date_from" required="1" span="2"/>
<field name="date_to" required="1" span="2"/> <field name="date_to" required="1" span="2"/>
<field name="type" onchange="onchange_type" span="2"/> <field name="staff_type" onchange="onchange_type" span="2"/>
<field name="staff_id" domain='[["type","=",type]]' span="2"/> <field name="staff_id" domain='[["type","=",staff_type]]' span="2"/>
<field name="branch_id" span="2"/> <field name="branch_id" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/> <field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
<field name="categ_id" span="2"/> <field name="categ_id" span="2"/>

View File

@ -23,6 +23,10 @@ class PrintLaborCost(Model):
'lines': fields.One2Many("clinic.print.labor.cost.line","print_labor_cost_id","Lines"), '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"), 'sum_report_id': fields.Many2One("clinic.report.labor.cost.summary","Summary Report"),
'lc_report_id': fields.Many2One("clinic.report.labor.cost","Labor Cost 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_summary': fields.File("Summary"),
'report_labor_cost': fields.File("Labor Cost"), 'report_labor_cost': fields.File("Labor Cost"),
} }
@ -61,6 +65,8 @@ class PrintLaborCost(Model):
def generate_report(self,ids,context={}): def generate_report(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
# clear and reload
obj.reload()
def load_report(fname,link): def load_report(fname,link):
req=urllib.request.Request(link) req=urllib.request.Request(link)
@ -129,38 +135,75 @@ class PrintLaborCost(Model):
db.commit() 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' #sum_name='labor.cost-summary.xlsx'
link='http://localhost:9999/report_export_xls?model=clinic.report.labor.cost&template=report_labor_cost&active_id=%s'%(lc_id) #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(lcname,link) #load_report(sum_name,link)
sum_name='labor.cost-summary.xlsx' #obj.write({
link='http://localhost:9999/report_export_xls?model=clinic.report.labor.cost.summary&template=report_labor_cost_summary&active_id=%s'%(sum_id) #'report_summary': sum_name,
load_report(sum_name,link) #'report_labor_cost': lcname,
#})
obj.write({ #db.commit()
'report_summary': sum_name,
'report_labor_cost': lcname,
})
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: for line in obj.lines:
if count >= 2:
print("Break!")
break
staff=line.staff_id staff=line.staff_id
report_sum.write({ 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, 'staff_id': staff.id,
}) })
db.commit() db.commit()
#period_name='%sto%s'%(obj.date_from,obj.date_to[-2:]) obj.write({
#fname='%s-%s-%s-detail.xlsx'%(staff.name,period_name,active_id) report_line['field_name']: report_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) db.commit()
link='http://localhost:9999/report_export_xls?model=%s&template=%s&active_id=%s'%(report_model,report_template,report_obj.id)
#line.write({ load_report(fname,link)
#'report_detail': fname, line.write({
#}) report_file: fname,
#db.commit() })
db.commit()
count+=1
print("Done!") print("Done!")
def _get_date_from(self,context={}): def _get_date_from(self,context={}):

View File

@ -1,7 +1,7 @@
import time import time
from netforce.model import Model,fields,get_model 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): class ReportLaborCostDaily(Model):
_name="clinic.report.labor.cost.daily" _name="clinic.report.labor.cost.daily"
@ -10,10 +10,13 @@ class ReportLaborCostDaily(Model):
_fields={ _fields={
"date": fields.Date("Date"), "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_type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
'staff_id': fields.Many2One("clinic.staff","Staff"), 'staff_id': fields.Many2One("clinic.staff","Staff"),
'department_id': fields.Many2One("clinic.department",'Department'), 'department_id': fields.Many2One("clinic.department",'Department'),
'branch_id': fields.Many2One("clinic.branch","Branch"), '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): def default_get(self,field_names=None,context={},**kw):
@ -35,6 +38,14 @@ class ReportLaborCostDaily(Model):
def get_report_data(self,ids,context={}): def get_report_data(self,ids,context={}):
company_id=get_active_company() 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) comp=get_model("company").browse(company_id)
defaults=self.default_get(context=context) defaults=self.default_get(context=context)
date=defaults.get("date") date=defaults.get("date")
@ -132,6 +143,8 @@ class ReportLaborCostDaily(Model):
'lines': lines, 'lines': lines,
'date': date, 'date': date,
} }
set_active_company(company_id)
set_active_user(user_id)
return data return data
def onchange_type(self,context={}): def onchange_type(self,context={}):

View File

@ -2,7 +2,7 @@ import time
from calendar import monthrange from calendar import monthrange
from netforce.model import Model,fields,get_model 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): class ReportLaborCostDetail(Model):
_name="clinic.report.labor.cost.detail" _name="clinic.report.labor.cost.detail"
@ -15,7 +15,7 @@ class ReportLaborCostDetail(Model):
"date_to": fields.Date("To", required=True), "date_to": fields.Date("To", required=True),
'department_id': fields.Many2One("clinic.department","Department"), 'department_id': fields.Many2One("clinic.department","Department"),
'staff_id': fields.Many2One("clinic.staff","Staff"), '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"), 'department_id': fields.Many2One("clinic.department","Department"),
'branch_id': fields.Many2One("clinic.branch","Branch"), 'branch_id': fields.Many2One("clinic.branch","Branch"),
'cycle_id': fields.Many2One("clinic.cycle","Cycle"), 'cycle_id': fields.Many2One("clinic.cycle","Cycle"),
@ -61,7 +61,7 @@ class ReportLaborCostDetail(Model):
'date': time.strftime("%Y-%m-%d"), 'date': time.strftime("%Y-%m-%d"),
'date_from': date_from, 'date_from': date_from,
'date_to': date_to, 'date_to': date_to,
'type': staff_type, 'staff_type': staff_type,
'staff_id': staff_id or None, 'staff_id': staff_id or None,
'department_id': department_id or None, 'department_id': department_id or None,
'branch_id': branch_id or None, 'branch_id': branch_id or None,
@ -73,11 +73,18 @@ class ReportLaborCostDetail(Model):
def get_report_data(self,ids,context={}): def get_report_data(self,ids,context={}):
company_id=get_active_company() 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) comp=get_model("company").browse(company_id)
defaults=self.default_get(context=context) defaults=self.default_get(context=context)
date_from=defaults.get("date_from") date_from=defaults.get("date_from")
date_to=defaults.get("date_to") date_to=defaults.get("date_to")
staff_type=defaults.get("type") staff_type=defaults.get("staff_type")
staff_id=defaults.get("staff_id") staff_id=defaults.get("staff_id")
department_id=defaults.get("department_id") department_id=defaults.get("department_id")
branch_id=defaults.get("branch_id") branch_id=defaults.get("branch_id")
@ -89,7 +96,7 @@ class ReportLaborCostDetail(Model):
date_from=obj.date_from date_from=obj.date_from
date_to=obj.date_to date_to=obj.date_to
staff_id=obj.staff_id.id staff_id=obj.staff_id.id
staff_type=obj.type staff_type=obj.staff_type
department_id=obj.department_id.id department_id=obj.department_id.id
branch_id=obj.branch_id.id branch_id=obj.branch_id.id
cycle_id=obj.cycle_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_qty'%no]=int2ths(tline['qty'])
data['total_lines_txt'][0]['item%s_amt'%no]=int2ths(tline['amt']) data['total_lines_txt'][0]['item%s_amt'%no]=int2ths(tline['amt'])
no+=1 no+=1
set_active_company(company_id)
set_active_user(user_id)
return data return data
def onchange_date(self,context={}): def onchange_date(self,context={}):

View File

@ -2,7 +2,7 @@ import time
from calendar import monthrange from calendar import monthrange
from netforce.model import Model,fields,get_model 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): class ReportLaborCostOverTime(Model):
_name="clinic.report.labor.cost.overtime" _name="clinic.report.labor.cost.overtime"
@ -15,6 +15,8 @@ class ReportLaborCostOverTime(Model):
"date_to": fields.Date("To", required=True), "date_to": fields.Date("To", required=True),
'staff_id': fields.Many2One("clinic.staff","Staff"), 'staff_id': fields.Many2One("clinic.staff","Staff"),
"type": fields.Selection([["nurse","Nurse"]],"Type"), "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"), 'department_id': fields.Many2One("clinic.department","Department"),
'level_id': fields.Many2One("clinic.staff.level","Level"), 'level_id': fields.Many2One("clinic.staff.level","Level"),
'categ_id': fields.Many2One("clinic.staff.categ","Category"), 'categ_id': fields.Many2One("clinic.staff.categ","Category"),
@ -42,8 +44,16 @@ class ReportLaborCostOverTime(Model):
} }
def get_report_data(self,ids,context={}): def get_report_data(self,ids,context={}):
setting=get_model("clinic.setting").browse(1) #setting=get_model("clinic.setting").browse(1)
base_salary_day=setting.base_salary_day or 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) res=get_model("clinic.report.labor.cost.overtime").default_get(context=context)
date_from=res['date_from'] date_from=res['date_from']
date_to=res['date_to'] date_to=res['date_to']
@ -168,6 +178,8 @@ class ReportLaborCostOverTime(Model):
data['total_wage']+=line['staff_wage'] or 0 data['total_wage']+=line['staff_wage'] or 0
data['total_net_pay']+=line['net_pay'] or 0 data['total_net_pay']+=line['net_pay'] or 0
data['total_net_diff']+=line['net_diff'] or 0 data['total_net_diff']+=line['net_diff'] or 0
set_active_company(company_id)
set_active_user(user_id)
return data return data
def onchange_date(self,context={}): def onchange_date(self,context={}):

View File

@ -2,7 +2,7 @@ import time
from calendar import monthrange from calendar import monthrange
from netforce.model import Model,fields,get_model 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): class ReportLaborCostSubDetail(Model):
_name="clinic.report.labor.cost.sub.detail" _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"), "staff_type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
'branch_id': fields.Many2One("clinic.branch","Branch"), 'branch_id': fields.Many2One("clinic.branch","Branch"),
'department_id': fields.Many2One("clinic.department","Department"), 'department_id': fields.Many2One("clinic.department","Department"),
'cycle_id': fields.Many2One("clinic.cycle","Cycle"),
} }
def _get_date_from(self,context={}): def _get_date_from(self,context={}):
@ -61,6 +62,13 @@ class ReportLaborCostSubDetail(Model):
def get_report_data(self,ids,context={}): def get_report_data(self,ids,context={}):
company_id=get_active_company() 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) comp=get_model("company").browse(company_id)
defaults=self.default_get(context=context) defaults=self.default_get(context=context)
date_from=defaults.get("date_from") date_from=defaults.get("date_from")
@ -132,7 +140,6 @@ class ReportLaborCostSubDetail(Model):
line['no']=no line['no']=no
slines.append(line) slines.append(line)
no+=1 no+=1
data={ data={
'staff_name': staff_name, 'staff_name': staff_name,
'staff_id': staff_id, 'staff_id': staff_id,
@ -143,6 +150,8 @@ class ReportLaborCostSubDetail(Model):
'lines': slines, 'lines': slines,
'amount_total': amount_total, 'amount_total': amount_total,
} }
set_active_company(company_id)
set_active_user(user_id)
return data return data
def onchange_date(self,context={}): def onchange_date(self,context={}):