improve and add message

conv_bal
watcha.h 2015-07-30 10:44:41 +07:00
parent 6fdfc5d154
commit 43a30a45ab
2 changed files with 41 additions and 7 deletions

View File

@ -6,9 +6,9 @@
<field name="branch_id" onchange='onchange_branch' span="2"/> <field name="branch_id" onchange='onchange_branch' 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="cycle_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]]'/>--> <!--<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_summary" span="3" readonly="1"/>
<field name="report_labor_cost" span="3" readonly="1"/> <field name="report_labor_cost" span="3" readonly="1"/>
<field name="lines" nolabel="1" readonly="1"> <field name="lines" nolabel="1" readonly="1">

View File

@ -5,6 +5,8 @@ from calendar import monthrange
from netforce.model import Model,fields,get_model from netforce.model import Model,fields,get_model
from netforce.database import get_active_db, get_connection from netforce.database import get_active_db, get_connection
from netforce.access import get_active_user
import netforce.config as config
class PrintLaborCost(Model): class PrintLaborCost(Model):
_name="clinic.print.labor.cost" _name="clinic.print.labor.cost"
@ -63,12 +65,35 @@ class PrintLaborCost(Model):
'lines': lines, '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={}): def generate_report(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
# clear and reload # clear and reload
obj.reload() obj.reload()
def load_report(fname,link): 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) req=urllib.request.Request(link)
response=urllib.request.urlopen(req) response=urllib.request.urlopen(req)
data=response.read() data=response.read()
@ -137,12 +162,12 @@ class PrintLaborCost(Model):
# generate labor costs # generate labor costs
lcname='labor.cost.xlsx' 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) load_report(lcname,link)
# generate labor cost summary # generate labor cost summary
sum_name='labor.cost-summary.xlsx' 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) load_report(sum_name,link)
obj.write({ obj.write({
@ -197,13 +222,22 @@ class PrintLaborCost(Model):
report_line['field_name']: report_id, report_line['field_name']: report_id,
}) })
db.commit() 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) load_report(fname,link)
line.write({ line.write({
report_file: fname, report_file: fname,
}) })
db.commit() db.commit()
print("Done!") 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={}): def _get_date_from(self,context={}):
year,month,day=time.strftime("%Y-%m-%d").split("-") year,month,day=time.strftime("%Y-%m-%d").split("-")