improve and add message
parent
6fdfc5d154
commit
43a30a45ab
|
@ -6,9 +6,9 @@
|
|||
<field name="branch_id" onchange='onchange_branch' span="2"/>
|
||||
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
|
||||
<field name="cycle_id" span="2"/>
|
||||
<field name="staff_type" span="2"/>
|
||||
<field name="staff_type" required="1" span="2"/>
|
||||
<!--<field name="staff_id" span="2" domain='[["type","=",staff_type]]'/>-->
|
||||
<button string="Generate Report" method="generate_report" icon="arrow-right" type="default"/>
|
||||
<button string="Generate Report" method="do_generate" 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">
|
||||
|
|
|
@ -5,6 +5,8 @@ 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
|
||||
import netforce.config as config
|
||||
|
||||
class PrintLaborCost(Model):
|
||||
_name="clinic.print.labor.cost"
|
||||
|
@ -63,12 +65,35 @@ class PrintLaborCost(Model):
|
|||
'lines': lines,
|
||||
})
|
||||
|
||||
def do_generate(self,ids,context={}):
|
||||
dom=[
|
||||
['model', '=','clinic.print.labor.cost'],
|
||||
['method','=','generate_report'],
|
||||
]
|
||||
for cj in get_model('cron.job').search_browse(dom):
|
||||
cj.write({
|
||||
'state': 'waiting',
|
||||
})
|
||||
vals={
|
||||
'to_id': get_active_user(),
|
||||
'subject': 'Generate Report',
|
||||
'body': """
|
||||
Please wait until report is generated.
|
||||
""",
|
||||
}
|
||||
db=get_connection()
|
||||
get_model("message").create(vals)
|
||||
db.commit()
|
||||
|
||||
def generate_report(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
# clear and reload
|
||||
obj.reload()
|
||||
|
||||
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()
|
||||
|
@ -134,15 +159,15 @@ class PrintLaborCost(Model):
|
|||
})
|
||||
|
||||
db.commit()
|
||||
|
||||
|
||||
# generate labor costs
|
||||
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)
|
||||
link='report_export_xls?model=clinic.report.labor.cost&template=report_labor_cost&active_id=%s'%(lc_id)
|
||||
load_report(lcname,link)
|
||||
|
||||
# generate labor cost summary
|
||||
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)
|
||||
link='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({
|
||||
|
@ -197,13 +222,22 @@ class PrintLaborCost(Model):
|
|||
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)
|
||||
link='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()
|
||||
print("Done!")
|
||||
vals={
|
||||
'to_id': get_active_user(),
|
||||
'subject': 'Generate Report',
|
||||
'body': """
|
||||
Finish to generate report.
|
||||
""",
|
||||
}
|
||||
get_model("message").create(vals)
|
||||
db.commit()
|
||||
|
||||
def _get_date_from(self,context={}):
|
||||
year,month,day=time.strftime("%Y-%m-%d").split("-")
|
||||
|
|
Loading…
Reference in New Issue