clinic/netforce_clinic/models/labor_cost_line.py

68 lines
2.7 KiB
Python
Raw Normal View History

2014-12-09 07:29:30 +00:00
from netforce.model import Model, fields, get_model
2014-12-08 11:35:39 +00:00
from netforce.access import get_active_company
class LaborCostLine(Model):
_name="clinic.labor.cost.line"
2014-12-09 00:11:39 +00:00
_string="Labor Cost Item"
2014-12-08 11:35:39 +00:00
_name_field="labor_cost_id"
2015-02-23 04:47:51 +00:00
def _get_store(self,ids,context={}):
res={}
for obj in self.browse(ids):
staff_type=obj.staff_id.type
citem=obj.labor_cost_id.cycle_item_id
dpt=citem.department_id
br=dpt.branch_id
res[obj.id]={
'type': staff_type,
'branch_id': br.id,
'department_id': dpt.id,
}
return res
2015-04-07 06:14:25 +00:00
def _get_all(self,ids,context={}):
res={}
for obj in self.browse(ids):
res[obj.id]={
'pay_amount': round(obj.amount,0),
}
return res
2015-02-23 04:47:51 +00:00
2014-12-08 11:35:39 +00:00
_fields={
2015-02-23 07:12:30 +00:00
"labor_cost_id": fields.Many2One("clinic.labor.cost","Labor Cost",required=True,on_delete="cascade"),
2015-02-23 04:47:51 +00:00
"type": fields.Selection([('staff','Staff'),("doctor","Doctor"),('nurse','Nurse')],"Staff Type",required=True,search=True,function="_get_store",function_multi=True),
2014-12-09 00:11:39 +00:00
'staff_id': fields.Many2One("clinic.staff", "Staff",search=True),
'level_id': fields.Many2One("clinic.staff.level", "Level",search=True),
'cycle_id': fields.Many2One("clinic.cycle", "Cycle",search=True),
2015-02-23 04:47:51 +00:00
'qty': fields.Integer("Qty"),
2014-12-08 14:54:25 +00:00
'rate': fields.Float("Rate",scale=2),
2014-12-08 11:35:39 +00:00
'amount': fields.Float("Amount",scale=2),
2015-04-07 06:14:25 +00:00
'pay_amount': fields.Float("Pay Amount",function="_get_all",function_multi=True),
2014-12-09 00:11:39 +00:00
'date': fields.Date("Date",search=True),
2014-12-09 07:29:30 +00:00
'description': fields.Char("Description"),
2014-12-08 11:35:39 +00:00
'company_id': fields.Many2One('company','Company'),
2015-02-08 08:48:08 +00:00
'categ_id': fields.Many2One("clinic.staff.categ", "Category",domain=[['type','=','nurse']],search=True),
2015-02-23 04:47:51 +00:00
'branch_id': fields.Many2One('clinic.branch','Branch',function="_get_store",function_multi=True,store=True,search=True),
'department_id': fields.Many2One('clinic.department','Department',function="_get_store",function_multi=True,store=True,search=True),
'note': fields.Text("Note"),
}
2014-12-08 11:35:39 +00:00
_defaults={
"company_id": lambda *a: get_active_company(),
}
2014-12-08 14:54:25 +00:00
_order="cycle_id,level_id"
2014-12-09 07:29:30 +00:00
def create(self,vals,**kw):
new_id=super().create(vals,**kw)
2015-02-23 04:47:51 +00:00
self.function_store([new_id])
2014-12-09 07:29:30 +00:00
return new_id
2014-12-08 11:35:39 +00:00
2015-02-23 04:47:51 +00:00
def write(self,ids,vals,**kw):
self.function_store(ids)
super().write(ids,vals,**kw)
def onchange_vals(self,context={}):
data=context['data']
data['amount']=(data['rate'] or 0)*(data['qty'] or 0)
return data
2014-12-08 11:35:39 +00:00
LaborCostLine.register()