prevent to create name of staff & patient

conv_bal
watcha.h 2015-02-17 15:12:24 +07:00
parent 5867a9bcfb
commit 178c1adcb9
6 changed files with 30 additions and 10 deletions

View File

@ -50,7 +50,6 @@
<item string="Reporting" perm="clinic_report">
<item string="Visit Summary" action="clinic_report_visit"/>
<item string="HD Case Summary" action="clinic_report_hd_case_summary"/>
<item string="HD Cases Matching" action="clinic_matching_hdcase" perm="clinic_matching_hdcase"/>
<item string="Medical Summary" action="clinic_report_medical_summary"/>
<item string="Recent Patient" action="clinic_report_recent_patient"/>
<item string="Discontinue Patient" action="clinic_report_discontinue_patient"/>

View File

@ -11,7 +11,7 @@
<field name="name_eng"/>
<field name="nick_name"/>
<field name="branch_id" required="1"/>
<field name="department_id" required="1"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' required="1"/>
<field name="company_id" invisible="1"/>
<tabs>
<tab string="General">
@ -22,7 +22,6 @@
<field name="birthday"/>
<field name="nation_id"/>
<field name="categ_id" domain="[['type','=',type]]"/>
<!--<field name="state"/>-->
</group>
<group span="6" columns="1">
<field name="image"/>

View File

@ -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={}):

View File

@ -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]

View File

@ -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',

View File

@ -1,4 +1,5 @@
todo:
- checking douplicate name
- matching payment ***
- script generate hd case
- report doctor & nurse ***