zip docoment
parent
dca8c54e02
commit
8e091e131b
|
@ -10,6 +10,7 @@
|
||||||
<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" required="1" span="2"/>
|
<field name="staff_type" required="1" span="2"/>
|
||||||
|
<field name="zip_file" span="2"/>
|
||||||
</group>
|
</group>
|
||||||
<foot>
|
<foot>
|
||||||
<button string="Generate Report" method="do_generate" icon="arrow-right" type="default"/>
|
<button string="Generate Report" method="do_generate" icon="arrow-right" type="default"/>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<list model="clinic.print.labor.cost">
|
<list model="clinic.print.labor.cost">
|
||||||
<field name="period_id"/>
|
<field name="period_id"/>
|
||||||
<field name="report_file"/>
|
<field name="zip_file"/>
|
||||||
<field name="state"/>
|
<field name="state"/>
|
||||||
</list>
|
</list>
|
||||||
|
|
|
@ -15,8 +15,8 @@ class PrintLaborCost(Model):
|
||||||
def _get_name(self,ids,context={}):
|
def _get_name(self,ids,context={}):
|
||||||
res={}
|
res={}
|
||||||
for obj in self.browse(ids):
|
for obj in self.browse(ids):
|
||||||
year_frm,month_frm,day_frm=obj.date_from.split(",")
|
year_frm,month_frm,day_frm=obj.date_from.split("-")
|
||||||
year_to,month_to,day_to=obj.date_to.split(",")
|
year_to,month_to,day_to=obj.date_to.split("-")
|
||||||
name=''.join([year_frm,month_frm,day_frm,month_to,day_to])
|
name=''.join([year_frm,month_frm,day_frm,month_to,day_to])
|
||||||
if obj.cycle_id:
|
if obj.cycle_id:
|
||||||
name+=obj.cycle_id.name
|
name+=obj.cycle_id.name
|
||||||
|
@ -24,7 +24,7 @@ class PrintLaborCost(Model):
|
||||||
name+=obj.branch_id.name
|
name+=obj.branch_id.name
|
||||||
if obj.department_id:
|
if obj.department_id:
|
||||||
name+=obj.department_id.name
|
name+=obj.department_id.name
|
||||||
name+='-'%obj.type
|
name+='-'+obj.staff_type
|
||||||
res[obj.id]=name
|
res[obj.id]=name
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@ -48,9 +48,9 @@ class PrintLaborCost(Model):
|
||||||
'ot_report_id': fields.Many2One("clinic.report.labor.cost.overtime","Overtime Report"),
|
'ot_report_id': fields.Many2One("clinic.report.labor.cost.overtime","Overtime Report"),
|
||||||
'report_summary': fields.File("Summary"),
|
'report_summary': fields.File("Summary"),
|
||||||
'report_labor_cost': fields.File("Labor Cost"),
|
'report_labor_cost': fields.File("Labor Cost"),
|
||||||
'state': fields.Selection([['draft','Draft'],['pending','Pending'],['done','Done']],'State'),
|
'state': fields.Selection([['draft','Draft'],['waiting_doc','Waiting Document'],['done','Done']],'State'),
|
||||||
'company_id': fields.Many2One('company','Company'),
|
'company_id': fields.Many2One('company','Company'),
|
||||||
'report_file': fields.File("File"),
|
'zip_file': fields.File("File"),
|
||||||
}
|
}
|
||||||
|
|
||||||
def _get_date_from(self,context={}):
|
def _get_date_from(self,context={}):
|
||||||
|
@ -87,7 +87,7 @@ class PrintLaborCost(Model):
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def reload(self,ids,context={}):
|
def reset_data(self,ids,context={}):
|
||||||
obj=self.browse(ids)[0]
|
obj=self.browse(ids)[0]
|
||||||
context['defaults']={
|
context['defaults']={
|
||||||
'date_from': obj.date_from,
|
'date_from': obj.date_from,
|
||||||
|
@ -120,32 +120,26 @@ class PrintLaborCost(Model):
|
||||||
})
|
})
|
||||||
|
|
||||||
def do_generate(self,ids,context={}):
|
def do_generate(self,ids,context={}):
|
||||||
dom=[
|
self.trigger(ids,"do_gen")
|
||||||
['model', '=','clinic.print.labor.cost'],
|
|
||||||
['method','=','generate_report'],
|
def wkf_gen_report(self,context={},**kw):
|
||||||
]
|
print("#"*80)
|
||||||
for cj in get_model('cron.job').search_browse(dom):
|
trigger_ids=context.get("trigger_ids")
|
||||||
cj.write({
|
if not trigger_ids:
|
||||||
'state': 'waiting',
|
raise Exception("Missing trigger ids")
|
||||||
})
|
print("trigger_ids",trigger_ids)
|
||||||
vals={
|
self.generate_report(trigger_ids,context,**kw)
|
||||||
'to_id': get_active_user(),
|
|
||||||
'subject': 'Generate Report',
|
|
||||||
'body': """
|
|
||||||
Please wait until report is generated.
|
|
||||||
""",
|
|
||||||
}
|
|
||||||
get_model("message").create(vals)
|
|
||||||
return {
|
|
||||||
'next': {
|
|
||||||
'type': 'reload',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def generate_report(self,ids,context={}):
|
def generate_report(self,ids,context={}):
|
||||||
|
db=get_connection()
|
||||||
obj=self.browse(ids)[0]
|
obj=self.browse(ids)[0]
|
||||||
|
obj.write({
|
||||||
|
'state': 'waiting_doc',
|
||||||
|
'zip_file': None,
|
||||||
|
})
|
||||||
|
db.commit()
|
||||||
# clear and reload
|
# clear and reload
|
||||||
obj.reload()
|
obj.reset_data()
|
||||||
def load_report(fname,link):
|
def load_report(fname,link):
|
||||||
host=config.config['host']
|
host=config.config['host']
|
||||||
port=config.config['port']
|
port=config.config['port']
|
||||||
|
@ -154,11 +148,15 @@ class PrintLaborCost(Model):
|
||||||
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()
|
||||||
dbname=get_active_db()
|
fpath=os.path.join('/tmp/labor_cost',fname)
|
||||||
fdir=os.path.join("static","db",dbname,"files")
|
open(fpath,"wb").write(data)
|
||||||
open(os.path.join(fdir,fname),"wb").write(data)
|
|
||||||
|
dbname=get_active_db()
|
||||||
|
fdir=os.path.join("static","db",dbname,"files")
|
||||||
|
tmp_dir='/tmp/labor_cost'
|
||||||
|
if not os.path.isdir(tmp_dir):
|
||||||
|
os.system("mkdir %s"%(tmp_dir))
|
||||||
|
|
||||||
db=get_connection()
|
|
||||||
sum_id=obj.sum_report_id.id
|
sum_id=obj.sum_report_id.id
|
||||||
if not sum_id:
|
if not sum_id:
|
||||||
sum_id=get_model('clinic.report.labor.cost.summary').create({
|
sum_id=get_model('clinic.report.labor.cost.summary').create({
|
||||||
|
@ -240,9 +238,11 @@ class PrintLaborCost(Model):
|
||||||
for line in obj.lines:
|
for line in obj.lines:
|
||||||
staff=line.staff_id
|
staff=line.staff_id
|
||||||
for report_line in report_lines:
|
for report_line in report_lines:
|
||||||
name=staff.number or staff.name or staff.id
|
#name=staff.number or staff.name or staff.id
|
||||||
|
name=staff.number+"-"+(staff.name or staff.id)
|
||||||
fname='%s-%s.xlsx'%(name,report_line['report_file'])
|
fname='%s-%s.xlsx'%(name,report_line['report_file'])
|
||||||
report_file=report_line['report_file']
|
print('fname ---> ', fname)
|
||||||
|
#report_file=report_line['report_file']
|
||||||
report_model=report_line['model']
|
report_model=report_line['model']
|
||||||
report_template=report_model.replace(".","_").replace("clinic_","")
|
report_template=report_model.replace(".","_").replace("clinic_","")
|
||||||
report_id=report_line['report_id']
|
report_id=report_line['report_id']
|
||||||
|
@ -279,15 +279,24 @@ class PrintLaborCost(Model):
|
||||||
db.commit()
|
db.commit()
|
||||||
link='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({
|
|
||||||
report_file: fname,
|
|
||||||
})
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
os.system("cp -rf %s ."%tmp_dir)
|
||||||
|
os.system("mv labor_cost %s"%obj.name)
|
||||||
|
os.system("zip %s.zip %s/*"%(obj.name,obj.name))
|
||||||
|
os.system("mv %s.zip %s/"%(obj.name,fdir))
|
||||||
|
os.system("rm -r %s*"%(obj.name))
|
||||||
|
os.system("rm %s/*"%tmp_dir)
|
||||||
|
obj.write({
|
||||||
|
'zip_file': '%s.zip'%obj.name,
|
||||||
|
'state': 'done',
|
||||||
|
})
|
||||||
|
|
||||||
vals={
|
vals={
|
||||||
'to_id': get_active_user(),
|
'to_id': get_active_user(),
|
||||||
'subject': 'Generate Report',
|
'subject': 'Generate Report',
|
||||||
'body': """
|
'body': """
|
||||||
Finish to generate report.
|
Generate labor cost report for successfully.
|
||||||
""",
|
""",
|
||||||
}
|
}
|
||||||
get_model("message").create(vals)
|
get_model("message").create(vals)
|
||||||
|
@ -320,5 +329,4 @@ class PrintLaborCost(Model):
|
||||||
data['date_to']=period.date_stop
|
data['date_to']=period.date_stop
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
PrintLaborCost.register()
|
PrintLaborCost.register()
|
||||||
|
|
Loading…
Reference in New Issue