clinic/netforce_clinic/models/labor_cost_line.py

69 lines
2.7 KiB
Python

from netforce.model import Model, fields, get_model
from netforce.access import get_active_company
class LaborCostLine(Model):
_name="clinic.labor.cost.line"
_string="Labor Cost Item"
_name_field="labor_cost_id"
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
def _get_all(self,ids,context={}):
res={}
for obj in self.browse(ids):
res[obj.id]={
'pay_amount': round(obj.amount,0),
}
return res
_fields={
"labor_cost_id": fields.Many2One("clinic.labor.cost","Labor Cost",required=True,on_delete="cascade"),
"type": fields.Selection([('staff','Staff'),("doctor","Doctor"),('nurse','Nurse')],"Staff Type",required=True,search=True,function="_get_store",function_multi=True),
'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),
'qty': fields.Integer("Qty"),
'rate': fields.Float("Rate",scale=2),
'amount': fields.Float("Amount",scale=2),
'pay_amount': fields.Float("Pay Amount",function="_get_all",function_multi=True),
'date': fields.Date("Date",search=True),
'description': fields.Char("Description"),
'company_id': fields.Many2One('company','Company'),
'categ_id': fields.Many2One("clinic.staff.categ", "Category",domain=[['type','=','nurse']],search=True),
'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"),
}
_defaults={
"company_id": lambda *a: get_active_company(),
}
_order="cycle_id,level_id"
def create(self,vals,**kw):
new_id=super().create(vals,**kw)
self.function_store([new_id])
return new_id
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
LaborCostLine.register()