2015-02-26 00:56:41 +00:00
|
|
|
import time
|
|
|
|
from calendar import monthrange
|
|
|
|
|
|
|
|
from netforce.model import Model,fields,get_model
|
|
|
|
|
|
|
|
class ComputeLaborCost(Model):
|
|
|
|
_name="clinic.compute.labor.cost"
|
|
|
|
_string="Compute Labor Cost"
|
|
|
|
_transient=True
|
|
|
|
|
|
|
|
_fields={
|
|
|
|
"date": fields.Date("Month"),
|
|
|
|
"date_from": fields.Date("From", required=True),
|
|
|
|
"date_to": fields.Date("To", required=True),
|
2015-03-05 11:10:56 +00:00
|
|
|
'branch_id': fields.Many2One("clinic.branch","Branch"),
|
|
|
|
'department_id': fields.Many2One("clinic.department","Department"),
|
2015-02-26 00:56:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def _get_date_from(self,context={}):
|
|
|
|
year,month=time.strftime("%Y-%m").split("-")
|
|
|
|
return '%s-%s-01'%(year,month)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
_defaults={
|
|
|
|
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
|
|
|
'date_from': _get_date_from,
|
|
|
|
'date_to': _get_date_to,
|
|
|
|
}
|
|
|
|
|
|
|
|
def compute(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
dom=[]
|
|
|
|
dom.append(['date','>=', obj.date_from])
|
|
|
|
dom.append(['date','<=', obj.date_to])
|
2015-03-05 11:10:56 +00:00
|
|
|
if obj.branch_id:
|
|
|
|
dom.append(['branch_id','=',obj.branch_id.id])
|
|
|
|
if obj.department_id:
|
|
|
|
dom.append(['department_id','=',obj.department_id.id])
|
2015-02-26 00:56:41 +00:00
|
|
|
for lcost in get_model("clinic.labor.cost").search_browse(dom):
|
|
|
|
print("compute %s ....", lcost.cycle_item_id.name)
|
2015-03-05 11:10:56 +00:00
|
|
|
#item=lcost.cycle_item_id
|
|
|
|
#item.to_draft()
|
|
|
|
#item.validate()
|
2015-02-26 00:56:41 +00:00
|
|
|
lcost.compute()
|
|
|
|
print("Done!")
|
|
|
|
return {
|
|
|
|
'next': {
|
|
|
|
'name': 'clinic_compute_labor_cost',
|
|
|
|
'mode': 'form',
|
|
|
|
'active_id': obj.id,
|
|
|
|
},
|
|
|
|
'flash': 'Compute Successfully',
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-04-07 04:43:32 +00:00
|
|
|
def onchange_branch(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
data['department_id']=None
|
|
|
|
return data
|
|
|
|
|
2015-02-26 00:56:41 +00:00
|
|
|
ComputeLaborCost.register()
|