From 178c1adcb90dfe2dcd98f4fc033cac9906632610 Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Tue, 17 Feb 2015 15:12:24 +0700 Subject: [PATCH] prevent to create name of staff & patient --- netforce_clinic/layouts/clinic_menu.xml | 1 - netforce_clinic/layouts/clinic_staff_form.xml | 3 +-- netforce_clinic/models/patient.py | 13 ++++++++++++- netforce_clinic/models/staff.py | 17 +++++++++++++++-- netforce_clinic/models/visit.py | 5 +---- netforce_clinic/todo.txt | 1 + 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml index b0ec025..cedf990 100644 --- a/netforce_clinic/layouts/clinic_menu.xml +++ b/netforce_clinic/layouts/clinic_menu.xml @@ -50,7 +50,6 @@ - diff --git a/netforce_clinic/layouts/clinic_staff_form.xml b/netforce_clinic/layouts/clinic_staff_form.xml index b7c8daa..787eaa3 100644 --- a/netforce_clinic/layouts/clinic_staff_form.xml +++ b/netforce_clinic/layouts/clinic_staff_form.xml @@ -11,7 +11,7 @@ - + @@ -22,7 +22,6 @@ - diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py index 756a409..d220bf4 100644 --- a/netforce_clinic/models/patient.py +++ b/netforce_clinic/models/patient.py @@ -10,7 +10,6 @@ class Patient(Model): _string="Patient" _audit_log=True _multi_company=True - _key=['number','branch_id'] def _get_age(self,ids,context): res={} @@ -40,6 +39,13 @@ class Patient(Model): res[obj.id]=hn return res + def _get_name_check(self,ids,context={}): + # remove all space for make sure + res={} + for obj in self.browse(ids): + res[obj.id]=(obj.name or "").replace(" ","") + return res + _fields={ 'type_id': fields.Many2One("clinic.patient.type","Type",search=True,required=True), "number": fields.Char("HN Number",required=True,search=True), @@ -47,6 +53,7 @@ class Patient(Model): "hn_no": fields.Char("HN",function="_get_hn_no",store=True), "hn": fields.Char("REF/HN",search=False), "name": fields.Char("Name",required=True,search=True), + "name_check": fields.Char("Name",function="_get_name_check",store=True), # prevent duplicate "reg_date": fields.Date("Reg. Date",required=False,search=True), "birthday": fields.Date("Birthday",required=False,search=True), "phone": fields.Char("Phone",required=False,search=True), @@ -149,10 +156,13 @@ class Patient(Model): 'type_id': _get_type, "active" : True, } + + _sql_constraints=("clinic_patient_key_uniq","unique(name_check,branch_id)","name should be unique"), _order="resign_date desc,number desc" def create(self, vals,**kw): obj_id=super(Patient,self).create(vals,**kw) + self.function_store([obj_id]) obj=self.browse(obj_id) partner_id=obj.partner_id if not partner_id: @@ -246,6 +256,7 @@ class Patient(Model): visit_ids=get_model('clinic.visit').search([['patient_id','=',obj.id],['state','=','draft']]) get_model('clinic.visit').delete(visit_ids) print('remove visit auto %s'%visit_ids) + self.function_store(ids) super().write(ids,vals,**kw) def name_get(self,ids,context={}): diff --git a/netforce_clinic/models/staff.py b/netforce_clinic/models/staff.py index cae6374..b7664c0 100644 --- a/netforce_clinic/models/staff.py +++ b/netforce_clinic/models/staff.py @@ -8,7 +8,6 @@ class Staff(Model): _string="Staff" _audit_log=True _multi_company=True - _key=["name","branch_id"] def _get_age(self,ids,context={}): res={} @@ -68,11 +67,19 @@ class Staff(Model): hids.append(hdcase.id) res[obj.id]=hids return res + + def _get_name_check(self,ids,context={}): + # remove all space for make sure + res={} + for obj in self.browse(ids): + res[obj.id]=(obj.name or "").replace(" ","") + return res _fields={ 'employee_id': fields.Many2One("hr.employee","Employee"), "number": fields.Char("Number",required=True,search=True), "name": fields.Char("Name",required=True,search=True), + "name_check": fields.Char("Name",function="_get_name_check",store=True), "name_eng": fields.Char("Eng Name",search=True), "nick_name": fields.Char("Nick Name",search=True), "identification" : fields.Char("Identification Card"), @@ -149,6 +156,10 @@ class Staff(Model): "company_id": lambda *a: get_active_company(), 'branch_id': _get_branch, } + + #_key=["name_check","branch_id"] #not working + _sql_constraints=("clinic_staff_key_uniq","unique(name_check,branch_id)","name should be unique"), + _order="date desc,number desc" def check_emp(self,name="", employee_id=None): @@ -180,6 +191,7 @@ class Staff(Model): if emp_id: vals['employee_id']=emp_id new_id=super().create(vals,**kw) + self.function_store([new_id]) return new_id def write(self,ids,vals,**kw): @@ -190,6 +202,7 @@ class Staff(Model): emp_id=self.check_emp(name,obj.employee_id.id) if emp_id: vals['employee_id']=emp_id + self.function_store(ids) super().write(ids,vals,**kw) def name_get(self,ids,context={}): @@ -205,7 +218,7 @@ class Staff(Model): vals.append((obj.id,name)) return vals - def name_search(self,name,domain=None,context={},**kw): + def name_search(self,name,domain=None,condition=[],context={},**kw): dom=[["name","ilike","%"+name+"%"]] if domain: dom=[dom,domain] diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py index 1e4b59e..9e080eb 100644 --- a/netforce_clinic/models/visit.py +++ b/netforce_clinic/models/visit.py @@ -295,14 +295,11 @@ class Visit(Model): obj.write({ 'cycle_item_id': item_id, }) - #XXX - set_active_user(user_id) - hd_case=hd_case_obj.browse(hd_case_id) hd_case.write({ 'cycle_item_id': item_id, }) - + set_active_user(user_id) return { 'next': { 'name': 'clinic_hd_case', diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt index 8782d4a..3ea09c5 100644 --- a/netforce_clinic/todo.txt +++ b/netforce_clinic/todo.txt @@ -1,4 +1,5 @@ todo: + - checking douplicate name - matching payment *** - script generate hd case - report doctor & nurse ***