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" _fields={ "labor_cost_id": fields.Many2One("clinic.labor.cost","Cycle Item",required=True,on_delete="cascade"), "type": fields.Selection([('staff','Staff'),("doctor","Doctor"),('nurse','Nurse')],"Type",required=True,search=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), 'date': fields.Date("Date",search=True), 'description': fields.Char("Description"), 'company_id': fields.Many2One('company','Company'), } _defaults={ "company_id": lambda *a: get_active_company(), } _order="cycle_id,level_id" def create(self,vals,**kw): staff_id=vals['staff_id'] staff=get_model("clinic.staff").browse(staff_id) if staff.type=='doctor': vals['type']='doctor' elif staff.type=='nurse': vals['type']='nurse' else: vals['type']='staff' new_id=super().create(vals,**kw) return new_id LaborCostLine.register()