report_wizard_labor_cost merge file to pdf (2)
parent
1edcbbea35
commit
95bad5cd6b
|
@ -0,0 +1,6 @@
|
|||
<record model="action">
|
||||
<field name="string">Report Wizard Labor Cost</field>
|
||||
<field name="view_cls">multi_view</field>
|
||||
<field name="model">clinic.print.wizard.labor.cost</field>
|
||||
<field name="menu">clinic_menu</field>
|
||||
</record>
|
|
@ -0,0 +1,25 @@
|
|||
<form model="clinic.print.wizard.labor.cost" title="Print Wizard Labor Cost" show_company="1">
|
||||
<head>
|
||||
<field name="state"/>
|
||||
</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="file_pdf1" span="4"/>
|
||||
<field name="file_pdf2" span="4"/>
|
||||
<field name="file_pdf3" span="4"/>
|
||||
</group>
|
||||
<group span="12" columns="1">
|
||||
<template>
|
||||
<div><b>Note:</b><span style="color:green"> <b style="color:#3477b0">"Waiting Document"</b> About 2minutes ~ 4minutes, there will be a notification at the right-hand mailbox.</span></div>
|
||||
</template>
|
||||
</group>
|
||||
<foot>
|
||||
<button string="Generate Report" states="draft" method="do_generate" icon="arrow-right" type="default"/>
|
||||
<button string="Regenerate Report" states="done" method="do_generate" icon="arrow-right" type="default"/>
|
||||
<button string="Waiting Document" states="waiting_doc" type="default"/>
|
||||
</foot>
|
||||
</form>
|
|
@ -0,0 +1,4 @@
|
|||
<list model="clinic.print.wizard.labor.cost">
|
||||
<field name="period_id"/>
|
||||
<field name="state"/>
|
||||
</list>
|
|
@ -13,6 +13,6 @@
|
|||
<foot replace="Run Report">
|
||||
<button string="PDF Summary" type="success" method="wizard_report_summary" 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"/>
|
||||
<button string="PDF Items" type="success" method="wizard_report_sub_details" icon="print"/>
|
||||
</foot>
|
||||
</form>
|
||||
|
|
|
@ -153,3 +153,4 @@ from . import report_wizard_labor_cost
|
|||
#revise
|
||||
from . import patient_move
|
||||
from . import report_hdcase_summary
|
||||
from . import print_wizard_labor_cost
|
||||
|
|
|
@ -0,0 +1,178 @@
|
|||
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
|
||||
from netforce.access import get_active_user, get_active_company, set_active_user
|
||||
import netforce.config as config
|
||||
|
||||
class PrintLaborCost(Model):
|
||||
_name="clinic.print.wizard.labor.cost"
|
||||
_string="Report Wizard Labor Cost"
|
||||
_audit_log=True
|
||||
|
||||
_fields={
|
||||
"date": fields.Date("Month"),
|
||||
"period_id": fields.Many2One("clinic.period.line", "Period", search=True),
|
||||
"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([["doctor","Doctor"],["nurse","Nurse"]],"Type"),
|
||||
'staff_id': fields.Many2One("clinic.staff","Staff"),
|
||||
'state': fields.Selection([['draft','Draft'],['waiting_doc','Waiting Document'],['done','Done']],'State',search=True),
|
||||
'company_id': fields.Many2One('company','Company'),
|
||||
'file_pdf1': fields.File("File_Labor_cost_sunmary"),
|
||||
'file_pdf2': fields.File("File_Labor_cost_details"),
|
||||
'file_pdf3': fields.File("File_Labor_cost_Sub_Deatils(Doctor)"),
|
||||
}
|
||||
|
||||
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,
|
||||
'state': 'draft',
|
||||
'company_id': get_active_company(),
|
||||
}
|
||||
return res
|
||||
|
||||
def generate_report(self,ids,context={}):
|
||||
db=get_connection()
|
||||
user_id=get_active_user()
|
||||
set_active_user(1)
|
||||
if ids:
|
||||
obj=self.browse(ids)[0]
|
||||
else:
|
||||
return
|
||||
obj.write({
|
||||
'state': 'waiting_doc',
|
||||
'file_pdf1': None,
|
||||
'file_pdf2': None,
|
||||
'file_pdf3': None,
|
||||
})
|
||||
db.commit()
|
||||
|
||||
def load_report(fname,link):
|
||||
host=config.config['host']
|
||||
port=config.config['port']
|
||||
hostname='http://%s:%s/'%(host,port)
|
||||
link=hostname+link
|
||||
req=urllib.request.Request(link)
|
||||
response=urllib.request.urlopen(req)
|
||||
data=response.read()
|
||||
fpath=os.path.join('/tmp/wizard_lc',fname)
|
||||
open(fpath,"wb").write(data)
|
||||
|
||||
dbname=get_active_db()
|
||||
fdir=os.path.join("static","db",dbname,"files")
|
||||
tmp_dir='/tmp/wizard_lc'
|
||||
if not os.path.isdir(tmp_dir):
|
||||
os.system("mkdir %s"%(tmp_dir))
|
||||
#Create File Name
|
||||
fname1='%s_wizard_sunmary_%s_to_%s.pdf'%(obj.id,obj.date_from,obj.date_to)
|
||||
fname2='%s_wizard_details_%s_to_%s.pdf'%(obj.id,obj.date_from,obj.date_to)
|
||||
fname3='%s_wizard_sub_details_%s_to_%s.pdf'%(obj.id,obj.date_from,obj.date_to)
|
||||
defaults='&data=%s&period_id=%s&date_from=%s&date_to=%s&cycle_id=%s&branch_id=%s&department_id=%s'%(obj.date_from,obj.period_id.id,obj.date_from,obj.date_to,obj.cycle_id.id or None,obj.branch_id.id or None,obj.department_id.id or None,)
|
||||
lc_id=get_model('clinic.report.wizard.labor.cost').create({})
|
||||
link1="report?convert=pdf&refer_id=%s&template=report_wizard_labor_cost_summary&model=clinic.report.wizard.labor.cost&type=report_odt2&method=get_report_wizard_summary%s&type_report=wizard&user=admin" % (lc_id,defaults)
|
||||
load_report(fname1,link1)
|
||||
link2="report?convert=pdf&refer_id=%s&template=report_wizard_labor_cost_details&model=clinic.report.wizard.labor.cost&type=report_odt2&method=get_report_wizard_details%s&type_report=wizard&user=admin" % (lc_id,defaults)
|
||||
load_report(fname2,link2)
|
||||
link3="report?convert=pdf&refer_id=%s&template=report_wizard_labor_cost_sub_details&model=clinic.report.wizard.labor.cost&type=report_odt2&method=get_report_wizard_sub_details%s&type_report=wizard&user=admin" % (lc_id,defaults)
|
||||
load_report(fname3,link3)
|
||||
|
||||
obj.write({
|
||||
'file_pdf1': '%s' % (fname1),
|
||||
'file_pdf2': '%s' % (fname2),
|
||||
'file_pdf3': '%s' % (fname3),
|
||||
'state': 'done',
|
||||
})
|
||||
os.chdir('%s'%fdir)
|
||||
os.system("mv /%s/%s* ."%(tmp_dir,obj.id))
|
||||
os.chdir('../../../../')
|
||||
set_active_user(user_id)
|
||||
vals={
|
||||
'to_id': get_active_user(),
|
||||
'subject': 'Generate Report',
|
||||
'body': """
|
||||
Generate labor cost report for successfully.
|
||||
<a href="/ui#name=clinic_print_wizard_labor_cost&mode=form&active_id=%s" class="msg-btn-ok">Open Print Wizard Labor Cost</a>
|
||||
"""%(obj.id),
|
||||
}
|
||||
get_model("message").create(vals)
|
||||
db.commit()
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic.print.wizard.labor.cost',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
}
|
||||
|
||||
def wkf_gen_report(self,context={},**kw):
|
||||
print("#"*80)
|
||||
trigger_ids=context.get("trigger_ids")
|
||||
if not trigger_ids:
|
||||
raise Exception("Missing trigger ids")
|
||||
print("trigger_ids",trigger_ids)
|
||||
self.generate_report(trigger_ids,context,**kw)
|
||||
|
||||
def do_generate(self,ids,context={}):
|
||||
self.trigger(ids,"do_gen")
|
||||
|
||||
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()
|
|
@ -50,6 +50,11 @@ class ReportLaborCost(Model):
|
|||
date_from=line.date_start
|
||||
date_to=line.date_stop
|
||||
break
|
||||
if defaults.get('report_type_wizard'):
|
||||
per = get_model('clinic.period.line').browse(int(defaults.get('period_id')))
|
||||
period_id=per.id
|
||||
date_from=per.date_start
|
||||
date_to=per.date_stop
|
||||
res={
|
||||
'period_id': period_id,
|
||||
'date': time.strftime("%Y-%m-%d"),
|
||||
|
|
|
@ -56,7 +56,7 @@ class ReportLaborCostDetail(Model):
|
|||
if not branch_id and department_id:
|
||||
dpt=get_model('clinic.department').browse(department_id)
|
||||
branch_id=dpt.branch_id.id
|
||||
print('defaults ', defaults)
|
||||
#print('defaults ', defaults)
|
||||
res={
|
||||
'date': time.strftime("%Y-%m-%d"),
|
||||
'date_from': date_from,
|
||||
|
@ -68,7 +68,7 @@ class ReportLaborCostDetail(Model):
|
|||
'cycle_id': cycle_id or None,
|
||||
'categ_id': categ_id or None,
|
||||
}
|
||||
print('res ', res)
|
||||
#print('res ', res)
|
||||
return res
|
||||
|
||||
def get_report_data(self,ids,context={}):
|
||||
|
|
|
@ -57,7 +57,7 @@ class ReportLaborCostSubDetail(Model):
|
|||
'department_id': department_id,
|
||||
'branch_id': branch_id,
|
||||
}
|
||||
print('res ', res)
|
||||
#print('res ', res)
|
||||
return res
|
||||
|
||||
def get_report_data(self,ids,context={}):
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
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
|
||||
|
@ -10,15 +9,15 @@ 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"),
|
||||
"branch_id": fields.Many2One("clinic.branch","Branch", required=False),
|
||||
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
|
||||
"department_id": fields.Many2One("clinic.department","Department"),
|
||||
"department_id": fields.Many2One("clinic.department","Department", required=False),
|
||||
"staff_type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
|
||||
"staff_id": fields.Many2One("clinic.staff","Staff")
|
||||
}
|
||||
|
@ -33,7 +32,7 @@ class ReportLaborCost(Model):
|
|||
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())
|
||||
|
@ -55,7 +54,7 @@ class ReportLaborCost(Model):
|
|||
'date_to': date_to,
|
||||
}
|
||||
return res
|
||||
|
||||
|
||||
def wizard_report_summary(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
return {
|
||||
|
@ -81,14 +80,66 @@ class ReportLaborCost(Model):
|
|||
"convert": "pdf",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def wizard_report_sub_details(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
return {
|
||||
"next": {
|
||||
"type": "report_odt",
|
||||
"model": self._name,
|
||||
"template": "report_wizard_labor_cost_sub_details",
|
||||
"refer_id": obj.id,
|
||||
"method": "get_report_wizard_sub_details",
|
||||
"convert": "pdf",
|
||||
"date_from": obj.date_from,
|
||||
}
|
||||
}
|
||||
|
||||
def get_report_data(self,ids,context={}):
|
||||
return
|
||||
|
||||
def get_report_wizard_summary(self,ids,context={}):
|
||||
obj=[]
|
||||
if ids:
|
||||
obj=self.browse(ids)[0]
|
||||
if not context.get('type_report'):
|
||||
obj = self.browse(ids)[0]
|
||||
date = obj.date
|
||||
period_id = obj.period_id.id
|
||||
date_from = obj.date_from
|
||||
date_to = obj.date_to
|
||||
cycle_id = obj.cycle_id.id or None
|
||||
staff_id = obj.staff_id.id or None
|
||||
staff_type = obj.staff_type or None
|
||||
branch_id = obj.branch_id.id or None
|
||||
department_id = obj.department_id.id or None
|
||||
else:
|
||||
date=context.get('date')
|
||||
period_id=context.get('period_id')
|
||||
date_from=context.get('date_from')
|
||||
date_to=context.get('date_to')
|
||||
if context.get('staff_type')=='None':
|
||||
staff_type=None
|
||||
else:
|
||||
staff_type=context.get('staff_type')
|
||||
if context.get('staff_id')=='None':
|
||||
staff_id=None
|
||||
else:
|
||||
staff_id=context.get('staff_id')
|
||||
if context.get('cycle_id')=='None':
|
||||
cycle_id=None
|
||||
else:
|
||||
cycle_id=context.get('cycle_id')
|
||||
if context.get('branch_id')=='None':
|
||||
branch_id=None
|
||||
else:
|
||||
branch_id=context.get('branch_id')
|
||||
if context.get('department_id')=='None':
|
||||
department_id=None
|
||||
else:
|
||||
department_id=context.get('department_id')
|
||||
if context.get('user')=='admin':
|
||||
user_id=get_active_user()
|
||||
set_active_user(1)
|
||||
company_id=get_active_company()
|
||||
if not company_id:
|
||||
set_active_company(1)
|
||||
|
@ -98,48 +149,50 @@ class ReportLaborCost(Model):
|
|||
pages2=[]
|
||||
t1=datetime.now()
|
||||
lc_vals={
|
||||
'date': obj.date_form,
|
||||
'period_id': obj.period_id.id,
|
||||
'date_from': obj.date_from,
|
||||
'date_to': obj.date_to,
|
||||
'cycle_id': obj.cycle_id.id or None,
|
||||
'branch_id': obj.branch_id.id or None,
|
||||
'date': date_from,
|
||||
'period_id': period_id,
|
||||
'date_from': date_from,
|
||||
'date_to': date_to,
|
||||
'cycle_id': cycle_id or None,
|
||||
'branch_id': branch_id or None,
|
||||
'report_type': 'cross',
|
||||
'department_id': obj.department_id.id or None,
|
||||
'department_id': department_id or None,
|
||||
'report_type_wizard':'t',
|
||||
}
|
||||
print(lc_vals)
|
||||
lc_id=get_model('clinic.report.labor.cost').create(lc_vals)
|
||||
lc_id=get_model('clinic.report.labor.cost').create({},context={'defaults':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,
|
||||
"date_from_1": date_from,
|
||||
"date_to_1": 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()
|
||||
#import pdb; pdb.set_trace()
|
||||
print('step 1 : ',t2-t1)
|
||||
|
||||
#STEP 2
|
||||
staff_data=[]
|
||||
if obj.staff_type:
|
||||
staff_data.append(obj.staff_type)
|
||||
if staff_type:
|
||||
staff_data.append(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,
|
||||
s_vals={
|
||||
'date': date_from,
|
||||
'date_from': date_from,
|
||||
'date_to': date_to,
|
||||
'staff_type': staff_type or s_line,
|
||||
'staff_id': staff_id or None,
|
||||
'cycle_id': cycle_id or None,
|
||||
'branch_id': branch_id or None,
|
||||
'department_id': department_id or None,
|
||||
}
|
||||
sum_id=get_model('clinic.report.labor.cost.summary').create({},context={
|
||||
'defaults':s_vals,
|
||||
})
|
||||
sum_data=get_model('clinic.report.labor.cost.summary').get_report_data([sum_id])
|
||||
if s_line=='doctor':
|
||||
|
@ -148,8 +201,8 @@ class ReportLaborCost(Model):
|
|||
sum_data.update({'staff_name':'ตารางพยาบาล'})
|
||||
data={
|
||||
"comp_name":company.name,
|
||||
"date_from_1": obj.date_from,
|
||||
"date_to_1": obj.date_to,
|
||||
"date_from_1": date_from,
|
||||
"date_to_1": date_to,
|
||||
"emp_type": sum_data['staff_type'] or None,
|
||||
"dpts_txt": sum_data['dpts_txt'] or None,
|
||||
"items": sum_data['items'] or None,
|
||||
|
@ -157,7 +210,9 @@ class ReportLaborCost(Model):
|
|||
}
|
||||
pages2.append(data)
|
||||
t2=datetime.now()
|
||||
print('step 2 : ',t2-t1)
|
||||
|
||||
if context.get('user')=='admin':
|
||||
set_active_user(user_id)
|
||||
if pages1 and pages2:
|
||||
pages1[-1]['is_last_page']=True
|
||||
pages2[-1]['is_last_page']=True
|
||||
|
@ -165,11 +220,49 @@ class ReportLaborCost(Model):
|
|||
"pages1": pages1,
|
||||
"pages2": pages2,
|
||||
}
|
||||
|
||||
|
||||
def get_report_wizard_details(self,ids,context={}):
|
||||
obj=[]
|
||||
if ids:
|
||||
obj=self.browse(ids)[0]
|
||||
if not context.get('type_report'):
|
||||
obj = self.browse(ids)[0]
|
||||
date = obj.date
|
||||
period_id = obj.period_id.id
|
||||
date_from = obj.date_from
|
||||
date_to = obj.date_to
|
||||
cycle_id = obj.cycle_id.id or None
|
||||
staff_id = obj.staff_id.id or None
|
||||
staff_type = obj.staff_type or None
|
||||
branch_id = obj.branch_id.id or None
|
||||
department_id = obj.department_id.id or None
|
||||
else:
|
||||
date=context.get('date')
|
||||
period_id=context.get('period_id')
|
||||
date_from=context.get('date_from')
|
||||
date_to=context.get('date_to')
|
||||
if context.get('staff_type')=='None':
|
||||
staff_type=None
|
||||
else:
|
||||
staff_type=context.get('staff_type')
|
||||
if context.get('staff_id')=='None':
|
||||
staff_id=None
|
||||
else:
|
||||
staff_id=context.get('staff_id')
|
||||
if context.get('cycle_id')=='None':
|
||||
cycle_id=None
|
||||
else:
|
||||
cycle_id=context.get('cycle_id')
|
||||
if context.get('branch_id')=='None':
|
||||
branch_id=None
|
||||
else:
|
||||
branch_id=context.get('branch_id')
|
||||
if context.get('department_id')=='None':
|
||||
department_id=None
|
||||
else:
|
||||
department_id=context.get('department_id')
|
||||
if context.get('user')=='admin':
|
||||
user_id=get_active_user()
|
||||
set_active_user(1)
|
||||
company_id=get_active_company()
|
||||
if not company_id:
|
||||
set_active_company(1)
|
||||
|
@ -181,42 +274,40 @@ class ReportLaborCost(Model):
|
|||
#STEP 2
|
||||
i=0
|
||||
staff_data=[]
|
||||
if obj.staff_type:
|
||||
staff_data.append(obj.staff_type)
|
||||
if staff_type:
|
||||
staff_data.append(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,
|
||||
'date': date_from,
|
||||
'date_from': date_from,
|
||||
'date_to': date_to,
|
||||
'staff_type': staff_type or s_line,
|
||||
'staff_id': staff_id or None,
|
||||
'cycle_id': cycle_id or None,
|
||||
'branch_id': branch_id or None,
|
||||
'department_id': department_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,
|
||||
'date': date_from,
|
||||
'date_from': date_from,
|
||||
'date_to': 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,
|
||||
'branch_id': branch_id or None,
|
||||
'department_id': department_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,
|
||||
"date_from_1": date_from,
|
||||
"date_to_1": 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,
|
||||
|
@ -229,10 +320,128 @@ class ReportLaborCost(Model):
|
|||
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
|
||||
if context.get('user')=='admin':
|
||||
set_active_user(user_id)
|
||||
if not company_id:
|
||||
set_active_company(company_id)
|
||||
return {
|
||||
"pages": pages,
|
||||
}
|
||||
|
||||
def get_report_wizard_sub_details(self,ids,context={}):
|
||||
obj=[]
|
||||
if ids:
|
||||
if not context.get('type_report'):
|
||||
obj = self.browse(ids)[0]
|
||||
date = obj.date
|
||||
period_id = obj.period_id.id
|
||||
date_from = obj.date_from
|
||||
date_to = obj.date_to
|
||||
cycle_id = obj.cycle_id.id or None
|
||||
staff_id = obj.staff_id.id or None
|
||||
staff_type = obj.staff_type or None
|
||||
branch_id = obj.branch_id.id or None
|
||||
department_id = obj.department_id.id or None
|
||||
else:
|
||||
date=context.get('date')
|
||||
period_id=context.get('period_id')
|
||||
date_from=context.get('date_from')
|
||||
date_to=context.get('date_to')
|
||||
if context.get('staff_type')=='None':
|
||||
staff_type=None
|
||||
else:
|
||||
staff_type=context.get('staff_type')
|
||||
if context.get('staff_id')=='None':
|
||||
staff_id=None
|
||||
else:
|
||||
staff_id=context.get('staff_id')
|
||||
if context.get('cycle_id')=='None':
|
||||
cycle_id=None
|
||||
else:
|
||||
cycle_id=context.get('cycle_id')
|
||||
if context.get('branch_id')=='None':
|
||||
branch_id=None
|
||||
else:
|
||||
branch_id=context.get('branch_id')
|
||||
if context.get('department_id')=='None':
|
||||
department_id=None
|
||||
else:
|
||||
department_id=context.get('department_id')
|
||||
if context.get('user')=='admin':
|
||||
user_id=get_active_user()
|
||||
set_active_user(1)
|
||||
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()
|
||||
|
||||
staff_data=[]
|
||||
if staff_type:
|
||||
staff_data.append(staff_type)
|
||||
else:
|
||||
staff_data=['doctor']
|
||||
for s_line in staff_data:
|
||||
ctx_sum={
|
||||
'date': date_from,
|
||||
'date_from': date_from,
|
||||
'date_to': date_to,
|
||||
'staff_type': staff_type or s_line,
|
||||
'staff_id': None,
|
||||
'cycle_id': None,
|
||||
'branch_id': None,
|
||||
'department_id': None,
|
||||
|
||||
}
|
||||
sum_id=get_model('clinic.report.labor.cost.summary').create({
|
||||
'date': date_from,
|
||||
'date_from': date_from,
|
||||
'date_to': date_to,
|
||||
'staff_type': staff_type or s_line,
|
||||
'staff_id': staff_id or None,
|
||||
'cycle_id': cycle_id or None,
|
||||
'branch_id': branch_id or None,
|
||||
'department_id': department_id or None,
|
||||
}, context=ctx_sum)
|
||||
sum_data=get_model('clinic.report.labor.cost.summary').get_report_data([sum_id])
|
||||
t2=datetime.now()
|
||||
for line in sum_data['lines']:
|
||||
ctx={
|
||||
'defaults': {
|
||||
'date': date_from,
|
||||
'date_from': date_from,
|
||||
'date_to': date_to,
|
||||
'staff_type': line['staff_type'] or None,
|
||||
'staff_id': line['staff_id'] or None,
|
||||
'branch_id': branch_id or None,
|
||||
'department_id': department_id or None,
|
||||
}
|
||||
}
|
||||
sub_detail_id=get_model('clinic.report.labor.cost.sub.detail').create({},context=ctx)
|
||||
sub_data=get_model('clinic.report.labor.cost.sub.detail').get_report_data([sub_detail_id])
|
||||
data={
|
||||
"date_from_1": date_from,
|
||||
"date_to_1": date_to,
|
||||
"emp_name": line['staff_name'] or None,
|
||||
"emp_type": line['staff_type'] or None,
|
||||
"lines": sub_data['lines'] or None,
|
||||
"amount_total": line['total'] or None,
|
||||
}
|
||||
print('Get Data : Name : %s, Type : %s, Total : %s'%(line['staff_name'],line['staff_type'],line['total']))
|
||||
pages.append(data)
|
||||
t2=datetime.now
|
||||
if pages:
|
||||
pages[-1]['is_last_page']=True
|
||||
if context.get('user')=='admin':
|
||||
set_active_user(user_id)
|
||||
if not company_id:
|
||||
set_active_company(company_id)
|
||||
return {
|
||||
"pages":pages,
|
||||
}
|
||||
|
||||
def onchange_date(self,context={}):
|
||||
data=context['data']
|
||||
date=data['date']
|
||||
|
@ -251,7 +460,7 @@ class ReportLaborCost(Model):
|
|||
data=context['data']
|
||||
data['date_to']=data['date_from']
|
||||
return data
|
||||
|
||||
|
||||
def onchange_period(self,context={}):
|
||||
data=context['data']
|
||||
period_id=data['period_id']
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -65,7 +65,7 @@
|
|||
<a href="#name=clinic_compute_labor_cost">{{t "Recompute Cost"}}</a>
|
||||
</div>
|
||||
<div>
|
||||
<a href="#name=clinic_report_wizard_labor_cost">{{t "Print All"}}</a>
|
||||
<a href="#name=clinic_print_wizard_labor_cost">{{t "Print All"}}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue