print labor cost

conv_bal
watcha.h 2015-07-29 18:36:31 +07:00
parent 8437e7adfd
commit af4093bc98
5 changed files with 162 additions and 18 deletions

View File

@ -1,7 +1,4 @@
<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"/>
@ -10,10 +7,21 @@
<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">
<!--<field name="staff_id" span="2" domain='[["type","=",staff_type]]'/>-->
<button string="Generate Report" method="generate_report" icon="arrow-right" type="default"/>
<field name="report_summary" span="3" readonly="1"/>
<field name="report_labor_cost" span="3" readonly="1"/>
<field name="lines" nolabel="1" readonly="1">
<list>
<field name="staff_id" domain='[["type","=",parent.staff_type]]'/>
<!--<field name="staff_id" domain='[["type","=",parent.staff_type]]'/>-->
<field name="staff_name" readonly="1"/>
<!--<field name="report_summary" readonly="1"/>-->
<field name="report_detail" readonly="1"/>
<field name="report_sub_detail" readonly="1"/>
<field name="report_daily" readonly="1"/>
<field name="report_ot" readonly="1"/>
<!--<field name="total_qty" readonly="1"/>-->
<!--<field name="total_amount" readonly="1"/>-->
</list>
</field>
</group>

View File

@ -1,7 +1,10 @@
import os
import time
import urllib
from calendar import monthrange
from netforce.model import Model,fields,get_model
from netforce.database import get_active_db, get_connection
class PrintLaborCost(Model):
_name="clinic.print.labor.cost"
@ -15,8 +18,13 @@ class PrintLaborCost(Model):
"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"),
"staff_type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"]],"Type"),
'staff_id': fields.Many2One("clinic.staff","Staff"),
'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"),
'report_summary': fields.File("Summary"),
'report_labor_cost': fields.File("Labor Cost"),
}
def reload(self,ids,context={}):
@ -35,17 +43,125 @@ class PrintLaborCost(Model):
lines=[]
for cost_line in cost_lines:
staff_id=cost_line['staff_id']
staff_name=cost_line['staff_name']
total_amount=0
total_qty=0
for sub_line in cost_line['sub_lines']:
total_qty+=sub_line['qty']
total_amount+=sub_line['amt']
lines.append(('create',{
'staff_id': staff_id,
'staff_name': staff_name,
'total_amount': total_amount,
'total_qty': total_qty,
}))
obj.write({
'lines': lines,
})
return
def do_print(self,ids,context={}):
data={}
return data
def generate_report(self,ids,context={}):
obj=self.browse(ids)[0]
def load_report(fname,link):
req=urllib.request.Request(link)
response=urllib.request.urlopen(req)
data=response.read()
dbname=get_active_db()
fdir=os.path.join("static","db",dbname,"files")
open(os.path.join(fdir,fname),"wb").write(data)
db=get_connection()
sum_id=obj.sum_report_id.id
if not sum_id:
sum_id=get_model('clinic.report.labor.cost.summary').create({
'date': obj.date_from,
'date_from': obj.date_from,
'date_to': obj.date_to,
'staff_type': obj.staff_type,
'cycle_id': obj.cycle_id.id,
'branch_id': obj.branch_id.id,
'department_id': obj.department_id.id,
})
obj.write({
'sum_report_id': sum_id,
})
report_sum=get_model("clinic.report.labor.cost.summary").browse(sum_id)
report_sum.write({
'date': obj.date_from,
'date_from': obj.date_from,
'date_to': obj.date_to,
'staff_type': obj.staff_type,
'cycle_id': obj.cycle_id.id,
'branch_id': obj.branch_id.id,
'department_id': obj.department_id.id,
'staff_id': None,
})
lc_id=obj.lc_report_id.id
if not lc_id:
lc_vals={
'date': obj.date_from,
'period_id': obj.period_id.id,
'date_from': obj.date_from,
'date_to': obj.date_to,
'cycle_id': obj.cycle_id.id,
'branch_id': obj.branch_id.id,
'report_type': 'cross',
'department_id': obj.department_id.id,
}
lc_id=get_model('clinic.report.labor.cost').create(lc_vals)
obj.write({
'lc_report_id': lc_id,
})
report_lc=get_model("clinic.report.labor.cost").browse(lc_id)
report_lc.write({
'date': obj.date_from,
'period_id': obj.period_id.id,
'date_from': obj.date_from,
'date_to': obj.date_to,
'cycle_id': obj.cycle_id.id,
'branch_id': obj.branch_id.id,
'report_type': 'cross',
'department_id': obj.department_id.id,
})
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)
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,
#})
#db.commit()
print("Done!")
def _get_date_from(self,context={}):
year,month,day=time.strftime("%Y-%m-%d").split("-")

View File

@ -7,11 +7,17 @@ class PrintLaborCostLine(Model):
_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"),
'staff_name': fields.Char("Staff Name"),
'total_qty': fields.Float("Total Qty"),
'total_amount': fields.Float("Total Amount"),
'report_summary': fields.File("Summary"),
'report_detail': fields.File("Detail"),
'report_sub_detail': fields.File("Sub Detail"),
'report_daily': fields.File("Daily"),
'report_ot': fields.File("OT"),
}
_defaults={
'print': True,
}

View File

@ -3,7 +3,7 @@ from datetime import datetime
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
from netforce.database import get_connection
class ReportLaborCost(Model):
@ -60,6 +60,13 @@ class ReportLaborCost(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
company=get_model("company").browse(company_id)
defaults=self.default_get(context=context)
date_from=defaults['date_from']
@ -425,6 +432,8 @@ class ReportLaborCost(Model):
'show_detail': show_detail,
'report_type': report_type,
}
set_active_company(company_id)
set_active_user(user_id)
return data
def onchange_date(self,context={}):

View File

@ -73,6 +73,12 @@ class ReportLaborCostSummary(Model):
return res
def get_report_data(self,ids,context={}):
user_id=get_active_user()
company_id=get_active_company()
set_active_user(1)
set_active_company(1)
defaults=self.default_get(context=context)
date_from=defaults['date_from']
date_to=defaults['date_to']
@ -314,9 +320,8 @@ class ReportLaborCostSummary(Model):
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)
set_active_user(user_id)
set_active_company(company_id)
return data
def onchange_date(self,context={}):