diff --git a/netforce_clinic/layouts/clinic_make_apt.xml b/netforce_clinic/layouts/clinic_make_apt.xml index e147a72..c4f3cae 100644 --- a/netforce_clinic/layouts/clinic_make_apt.xml +++ b/netforce_clinic/layouts/clinic_make_apt.xml @@ -4,7 +4,7 @@ - + diff --git a/netforce_clinic/models/make_apt.py b/netforce_clinic/models/make_apt.py index 6b8ac78..b2d150a 100644 --- a/netforce_clinic/models/make_apt.py +++ b/netforce_clinic/models/make_apt.py @@ -48,6 +48,28 @@ class MakeAPT(Model): dom.append(['cycle_id','=',obj.cycle_id.id]) branch_id=obj.branch_id.id pcs=get_model("clinic.patient.cycle").search_browse(dom) + if not pcs: + # Create patient cycle with that department + for pt in get_model("clinic.patient").search_browse([['department_id','=',obj.department_id.id]]): + for pc in pt.cycles: + vals={ + 'patient_id': pt.id, + 'department_id': pt.department_id.id, + 'cycle_id': pc.cycle_id.id, + 'day': pc.day, + } + res=get_model("clinic.patient.cycle").search([[ + ['patient_id','=',pt.id], + ['day','=',pc.day], + ['cycle_id','=',pc.cycle_id.id], + ['department_id','=', pt.department_id.id], + ]]) + if not res: + pcycle_id=get_model("clinic.patient.cycle").create(vals) + print("create ", pcycle_id) + else: + print("exist ", res) + pcs=get_model("clinic.patient.cycle").search_browse(dom) if not pcs: raise Exception("Please go to menu 'Patients -> Patient Cycles' and import data for %s"%(obj.department_id.name)) for pc in pcs: @@ -109,7 +131,7 @@ class MakeAPT(Model): 'mode': 'form', 'active_id': obj.id, }, - 'flash': 'Reload Successfully', + 'flash': 'Ready to generate', } def gen(self,ids,context={}): @@ -229,5 +251,10 @@ class MakeAPT(Model): data['date_from']="%s-%s-01"%(year,month) data['date_to']="%s-%s-%s"%(year,month,total_day) return data + + def onchange_branch(self,context={}): + data=context['data'] + data['department_id']=None + return data MakeAPT.register() diff --git a/netforce_clinic/models/patient_cycle.py b/netforce_clinic/models/patient_cycle.py index b64adab..fdded01 100644 --- a/netforce_clinic/models/patient_cycle.py +++ b/netforce_clinic/models/patient_cycle.py @@ -3,7 +3,6 @@ from netforce.model import Model, fields class PatientCycle(Model): _name="clinic.patient.cycle" _string="Patient Cycle" - _key=['patient_id','cycle_id','day'] _fields={ "patient_id": fields.Many2One('clinic.patient',"Patient",required=True,on_delete="cascade",search=True), @@ -11,5 +10,6 @@ class PatientCycle(Model): "department_id": fields.Many2One('clinic.department',"Department",search=True), 'day': fields.Selection([('mon', 'Monday'), ('tue','Tuesday'), ('wed','Wednesday'),('thu','Thursday'),('fri','Friday'),('sat','Saturday'),('sun','Sunday')], 'Day',search=True), } + _sql_constraints=("pcycle_uniq","unique(patient_id,cycle_id,day,department_id)","patient_id,cycle_id,day,department_id should be unique"), PatientCycle.register()