report_wizard_labor_cost merge file to pdf

dev_sa
saharat.i@netforce.co.th 2017-11-14 18:01:03 +07:00
parent aa2448888d
commit 54af83fcfa
12 changed files with 291 additions and 5 deletions

View File

@ -17,6 +17,7 @@
<item string="Labor Cost Sub Detail" action="clinic_report_labor_cost_sub_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 Daily" action="clinic_report_labor_cost_daily"/>
<item string="Labor Cost Overtime" action="clinic_report_labor_cost_overtime"/> <item string="Labor Cost Overtime" action="clinic_report_labor_cost_overtime"/>
<item string="Wizard Labor Cost" action="clinic_report_wizard_labor_cost"/>
</item> </item>
<item string="Matching"> <item string="Matching">
<item string="Payment Matching" action="clinic_payment_matching"/> <item string="Payment Matching" action="clinic_payment_matching"/>

View File

@ -0,0 +1,18 @@
<form model="clinic.report.wizard.labor.cost">
<group form_layout="stacked">
<field name="period_id" onchange="onchange_period" domain='[["state","=","open"]]' span="2"/>
<field name="date_from" onchange="onchange_from" required="1" span="2"/>
<field name="date_to" required="1" span="2"/>
<field name="branch_id" onchange="onchange_branch" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
<field name="staff_type" onchange="onchange_type" span="2" />
<field name="staff_id" domain='[["type","=",staff_type]]' span="2" />
<!--<field name="cycle_id" span="2"/>-->
<!--<field name="staff_type" required="1" span="2"/>-->
</group>
<foot replace="Run Report">
<button string="PDF Summany" type="success" method="wizard_report_summany" icon="print"/>
<button string="PDF Details" type="success" method="wizard_report_details" icon="print"/>
<button string="PDF Items" type="success" method="wizard_report_items" icon="print"/>
</foot>
</form>

View File

@ -148,3 +148,4 @@ from . import payment_matching
from . import create_invoice_payment from . import create_invoice_payment
from . import report_stock_card from . import report_stock_card
from . import report_receipt_summary from . import report_receipt_summary
from . import report_wizard_labor_cost

View File

@ -404,7 +404,7 @@ class ReportLaborCost(Model):
if key=='name': if key=='name':
vals['desc']=True vals['desc']=True
for line in lines: for line in lines:
vals[no]=con2float(line[key]) vals['l%s'%(no)]=con2float(line[key])
no+=1 no+=1
lines2.append(vals) lines2.append(vals)
return lines2 return lines2

View File

@ -279,12 +279,12 @@ class ReportLaborCostDetail(Model):
'dpt_lines': dpt_lines, 'dpt_lines': dpt_lines,
'show_all': show_count <=1 and True or False, 'show_all': show_count <=1 and True or False,
} }
data['dpts_txt']=[{0: '#', 1: 'วันที่'}] data['dpts_txt']=[{'l0': '#', 'l1': 'วันที่'}]
vals={} vals={}
no=0 no=0
dpt_len=len(data['dpts_txt'][0]) dpt_len=len(data['dpts_txt'][0])
for dpt in dpts: for dpt in dpts:
data['dpts_txt'][0][no+dpt_len]=dpt['name'] data['dpts_txt'][0]['l%s'% (no+dpt_len)]=dpt['name']
vals[no]=0 vals[no]=0
no+=1 no+=1
count=1 count=1

View File

@ -69,7 +69,7 @@ class ReportLaborCostSummary(Model):
'level_id': level_id or None, 'level_id': level_id or None,
'cycle_id': cycle_id or None, 'cycle_id': cycle_id or None,
} }
print('res ', res) #print('res ', res)
return res return res
def get_report_data(self,ids,context={}): def get_report_data(self,ids,context={}):
@ -295,7 +295,7 @@ class ReportLaborCostSummary(Model):
no=0 no=0
dpt_len=len(data['dpts_txt'][0]) dpt_len=len(data['dpts_txt'][0])
for dpt in dpts: for dpt in dpts:
data['dpts_txt'][0][no+dpt_len]=dpt['name'] data['dpts_txt'][0]['l%s'%(no+dpt_len)]=dpt['name']
vals[no]=0 vals[no]=0
no+=1 no+=1
count=1 count=1

View File

@ -0,0 +1,266 @@
import time
from datetime import datetime
from calendar import monthrange
from netforce.model import Model,fields,get_model
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):
_name="clinic.report.wizard.labor.cost"
_string="Report Wizard Labor Cost"
_transient=True
_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),
"branch_id": fields.Many2One("clinic.branch","Branch"),
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
"department_id": fields.Many2One("clinic.department","Department"),
"staff_type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
"staff_id": fields.Many2One("clinic.staff","Staff")
}
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]
period_id=None
for period in get_model('clinic.period').search_browse([[]]):
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 wizard_report_summany(self,ids,context={}):
obj=self.browse(ids)[0]
return {
"next": {
"type": "report_odt2",
"model": self._name,
"template": "report_wizard_labor_cost_summany",
"refer_id": obj.id,
"method": "get_report_wizard_summany",
"convert": "pdf",
}
}
def wizard_report_details(self,ids,context={}):
obj=self.browse(ids)[0]
return {
"next": {
"type": "report_odt2",
"model": self._name,
"template": "report_wizard_labor_cost_details",
"refer_id": obj.id,
"method": "get_report_wizard_details",
"convert": "pdf",
}
}
def get_report_data(self,ids,context={}):
return
def get_report_wizard_summany(self,ids,context={}):
obj=[]
if ids:
obj=self.browse(ids)[0]
company_id=get_active_company()
if not company_id:
set_active_company(1)
company_id=1
company=get_model("company").browse(company_id)
pages1=[]
pages2=[]
t1=datetime.now()
lc_vals={
'date': obj.date_form,
'period_id': obj.period_id.id,
'date_from': obj.date_form,
'date_to': obj.date_to,
'cycle_id': obj.cycle_id.id or None,
'branch_id': obj.branch_id.id or None,
'report_type': 'cross',
'department_id': obj.department_id.id or None,
}
lc_id=get_model('clinic.report.labor.cost').create(lc_vals)
lc_data=get_model('clinic.report.labor.cost').get_report_data([lc_id])
#data['lc_data'].append(lc_data) # END STEP 1
data={
"comp_name":company.name,
"date_from_1": obj.date_from,
"date_to_1": obj.date_to,
"dlines2": lc_data['dlines2'] or None,
"nlines2": lc_data['nlines2'] or None,
"ctlines2": lc_data['ctlines2'] or None,
}
pages1.append(data)
t2=datetime.now()
print('step 1 : ',t2-t1)
#STEP 2
staff_data=[]
if obj.staff_type:
staff_data.append(obj.staff_type)
else:
staff_data=['doctor','nurse']
for s_line in staff_data:
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 or s_line,
'staff_id': obj.staff_id or None,
'cycle_id': obj.cycle_id.id or None,
'branch_id': obj.branch_id.id or None,
'department_id': obj.department_id.id or None,
})
sum_data=get_model('clinic.report.labor.cost.summary').get_report_data([sum_id])
if s_line=='doctor':
sum_data.update({'staff_name':'ตารางหมอ'})
elif s_line=='nurse':
sum_data.update({'staff_name':'ตารางพยาบาล'})
data={
"comp_name":company.name,
"date_from_1": obj.date_from,
"date_to_1": obj.date_to,
"emp_type": sum_data['staff_type'] or None,
"dpts_txt": sum_data['dpts_txt'] or None,
"items": sum_data['items'] or None,
"total_lines_txt": sum_data['total_lines_txt'] or None,
}
pages2.append(data)
t2=datetime.now()
print('step 2 : ',t2-t1)
if pages1 and pages2:
pages1[-1]['is_last_page']=True
pages2[-1]['is_last_page']=True
return {
"pages1": pages1,
"pages2": pages2,
}
def get_report_wizard_details(self,ids,context={}):
obj=[]
if ids:
obj=self.browse(ids)[0]
company_id=get_active_company()
if not company_id:
set_active_company(1)
company_id=1
company=get_model("company").browse(company_id)
pages=[]
t1=datetime.now()
#STEP 2
i=0
staff_data=[]
if obj.staff_type:
staff_data.append(obj.staff_type)
else:
staff_data=['doctor','nurse']
for s_line in staff_data:
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': s_line,
'staff_type': obj.staff_type or s_line,
'staff_id': obj.staff_id or None,
'cycle_id': obj.cycle_id.id or None,
'branch_id': obj.branch_id.id or None,
'department_id': obj.department_id.id or None,
})
sum_data=get_model('clinic.report.labor.cost.summary').get_report_data([sum_id])
t2=datetime.now()
print('step 2 : ',t2-t1)
#STEP 3
for detail_line in sum_data['lines']:
detail_id=get_model('clinic.report.labor.cost.detail').create({
'date': obj.date_from,
'date_from': obj.date_from,
'date_to': obj.date_to,
'staff_type': detail_line['staff_type'] or None,
'staff_id': detail_line['staff_id'] or None,
'cycle_id': None,
'branch_id': obj.branch_id.id or None,
'department_id': obj.department_id.id or None,
})
detail_data=get_model('clinic.report.labor.cost.detail').get_report_data([detail_id])
data={
"date_from_1": obj.date_from,
"date_to_1": obj.date_to,
"emp_type": detail_line['staff_type'] or None,
"emp_name": detail_line['staff_name'] or None,
"detail_dpts_txt": detail_data['dpts_txt'] or None,
"detail_items": detail_data['items'] or None,
"detail_total_lines_txt": detail_data['total_lines_txt'] or None,
}
pages.append(data)
t2=datetime.now()
i=i+1
print('step 3 : ',t2-t1,' item in %d and name %s >>>>>>>> %s'%(i,detail_line['staff_name'],detail_line['staff_type']))
if pages:
pages[-1]['is_last_page']=True
return {
"pages": pages,
}
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
def onchange_type(self,context={}):
data=context['data']
data['staff_id']=None
return data
ReportLaborCost.register()