import time from netforce.model import Model, fields, get_model class HDCaseStaff(Model): _name="clinic.hd.case.staff" _name_field="staff_id" def _get_all(self,ids,context={}): res={} for obj in self.browse(ids): hd_case=obj.hd_case_id patient=hd_case.patient_id res[obj.id]={ 'sickbed_id': hd_case.sickbed_id.id, 'patient_id': patient.id, 'patient_type_id': patient.type_id.id, 'cycle_id': hd_case.cycle_id.id, 'department_id': hd_case.department_id.id, 'state': hd_case.state, } return res _fields={ "hd_case_id": fields.Many2One("clinic.hd.case","HD Case",required=True,on_delete="cascade",search=True), "staff_id": fields.Many2One("clinic.staff","Doctor",search=True), "type": fields.Selection([("doctor","Doctor"),('nurse','Nurse'),("staff","Staff")],"Type",required=True,search=True), "priop": fields.Selection([("personal","Personal"),('other','Other')],"Priority",search=True), 'note': fields.Char("Note"), 'sickbed_id': fields.Many2One("clinic.sickbed","Sickbed",function="_get_all",function_multi=True), 'patient_id': fields.Many2One("clinic.patient","Patient",domain=[['state','=','admit']], function="_get_all",function_multi=True), 'patient_type_id': fields.Many2One("clinic.patient.type","Patient Type",function="_get_all",function_multi=True), 'cycle_id': fields.Many2One("clinic.cycle","Cycle",function="_get_all",function_multi=True), 'department_id': fields.Many2One("clinic.department","Department",function="_get_all",function_multi=True), 'date': fields.Date("Date",search=True), "state": fields.Selection([("draft","Draft"),('waiting_treatment','Waiting Treatment'),("in_progress","In Progress"),("completed","Finish Treatment"),('paid','Paid'),("waiting_payment","Waiting Payment"),("discountinued","Discountinued"),("cancelled","Cancelled")],"Status",function="_get_all",function_multi=True), } _defaults={ 'type': 'doctor', 'priop': 'personal', 'date': lambda *a: time.strftime("%Y-%m-%d"), } def recompute_cost(self,ids,context={}): obj=self.browse(ids)[0] hdcase=obj.hd_case_id citem=hdcase.cycle_item_id for lc in get_model('clinic.labor.cost').search_browse([['cycle_item_id','=',citem.id]]): lc.compute() print("Done!") HDCaseStaff.register()