clinic/netforce_clinic/models/print_labor_cost.py

110 lines
3.8 KiB
Python
Raw Normal View History

2015-07-29 01:44:03 +00:00
import time
from calendar import monthrange
from netforce.model import Model,fields,get_model
class PrintLaborCost(Model):
_name="clinic.print.labor.cost"
_string="Print Report Labor Cost"
_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),
"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([['staff','Staff'],["doctor","Doctor"],["nurse","Nurse"]],"Type"),
'lines': fields.One2Many("clinic.print.labor.cost.line","print_labor_cost_id","Lines"),
}
def reload(self,ids,context={}):
obj=self.browse(ids)[0]
context['defaults']={
'date_from': obj.date_from,
'date_to': obj.date_to,
'cycle_id': obj.cycle_id.id,
'branch_id': obj.branch_id.id,
'department_id': obj.department_id.id,
'staff_type': obj.staff_type,
}
cost_lines=get_model('clinic.report.labor.cost.summary').get_report_data(ids=[],context=context)['lines']
for line in obj.lines:
line.delete()
lines=[]
for cost_line in cost_lines:
staff_id=cost_line['staff_id']
lines.append(('create',{
'staff_id': staff_id,
}))
obj.write({
'lines': lines,
})
return
def do_print(self,ids,context={}):
data={}
return data
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,
}
return res
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()