From 8c5fc5ddbc1c870fde8d50bbc12b2cbe73dc4f41 Mon Sep 17 00:00:00 2001 From: "watcha.h@almacom.co.th" Date: Tue, 13 Jan 2015 15:58:47 +0700 Subject: [PATCH] improve --- netforce_clinic/actions/clinic_branch.xml | 2 +- netforce_clinic/actions/clinic_department.xml | 2 +- netforce_clinic/actions/clinic_hospital.xml | 2 +- .../layouts/clinic_branch_form.xml | 1 - .../layouts/clinic_department_form.xml | 1 + .../layouts/clinic_dialyzer_form.xml | 5 +- .../layouts/clinic_dialyzer_list.xml | 6 +- netforce_clinic/layouts/clinic_menu.xml | 6 +- netforce_clinic/models/branch.py | 1 - netforce_clinic/models/department.py | 1 + netforce_clinic/models/dialyzer.py | 73 +++++++++++++++---- netforce_clinic/models/hd_case.py | 19 ++--- 12 files changed, 80 insertions(+), 39 deletions(-) diff --git a/netforce_clinic/actions/clinic_branch.xml b/netforce_clinic/actions/clinic_branch.xml index abcaa30..9d01a1c 100644 --- a/netforce_clinic/actions/clinic_branch.xml +++ b/netforce_clinic/actions/clinic_branch.xml @@ -1,5 +1,5 @@ - Branch + Branches multi_view clinic.branch clinic_menu diff --git a/netforce_clinic/actions/clinic_department.xml b/netforce_clinic/actions/clinic_department.xml index caf1105..e598876 100644 --- a/netforce_clinic/actions/clinic_department.xml +++ b/netforce_clinic/actions/clinic_department.xml @@ -1,5 +1,5 @@ - Deparments + Departments multi_view clinic.department clinic_menu diff --git a/netforce_clinic/actions/clinic_hospital.xml b/netforce_clinic/actions/clinic_hospital.xml index 594f747..e3ab854 100644 --- a/netforce_clinic/actions/clinic_hospital.xml +++ b/netforce_clinic/actions/clinic_hospital.xml @@ -1,5 +1,5 @@ - Hospital + Hospitals multi_view clinic.hospital clinic_menu diff --git a/netforce_clinic/layouts/clinic_branch_form.xml b/netforce_clinic/layouts/clinic_branch_form.xml index 7c4a6de..98d4f3c 100644 --- a/netforce_clinic/layouts/clinic_branch_form.xml +++ b/netforce_clinic/layouts/clinic_branch_form.xml @@ -1,5 +1,4 @@
- diff --git a/netforce_clinic/layouts/clinic_department_form.xml b/netforce_clinic/layouts/clinic_department_form.xml index c2726bb..89e6af3 100644 --- a/netforce_clinic/layouts/clinic_department_form.xml +++ b/netforce_clinic/layouts/clinic_department_form.xml @@ -1,6 +1,7 @@
+ diff --git a/netforce_clinic/layouts/clinic_dialyzer_form.xml b/netforce_clinic/layouts/clinic_dialyzer_form.xml index c546d10..b679813 100644 --- a/netforce_clinic/layouts/clinic_dialyzer_form.xml +++ b/netforce_clinic/layouts/clinic_dialyzer_form.xml @@ -7,8 +7,9 @@ - - + + + diff --git a/netforce_clinic/layouts/clinic_dialyzer_list.xml b/netforce_clinic/layouts/clinic_dialyzer_list.xml index 2af92cb..b58d647 100644 --- a/netforce_clinic/layouts/clinic_dialyzer_list.xml +++ b/netforce_clinic/layouts/clinic_dialyzer_list.xml @@ -1,9 +1,11 @@ + + + + - - diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml index 1c8b63d..9ba13e5 100644 --- a/netforce_clinic/layouts/clinic_menu.xml +++ b/netforce_clinic/layouts/clinic_menu.xml @@ -42,7 +42,6 @@
- @@ -52,8 +51,9 @@ - - + + + diff --git a/netforce_clinic/models/branch.py b/netforce_clinic/models/branch.py index 54ca024..672d15e 100644 --- a/netforce_clinic/models/branch.py +++ b/netforce_clinic/models/branch.py @@ -7,7 +7,6 @@ class Branch(Model): _fields={ "name": fields.Char("Name",required=True,search=True), "parent_id": fields.Many2One("clinic.branch","Parent"), - "pick_out_journal_id": fields.Many2One("stock.journal","Stock Journal"), } Branch.register() diff --git a/netforce_clinic/models/department.py b/netforce_clinic/models/department.py index 24daeec..49c54b6 100644 --- a/netforce_clinic/models/department.py +++ b/netforce_clinic/models/department.py @@ -12,6 +12,7 @@ class Department(Model): "parent_id": fields.Many2One("clinic.department", "Parent"), 'company_id': fields.Many2One("company","Company"), 'branch_id': fields.Many2One("clinic.branch","Branch"), + "pick_out_journal_id": fields.Many2One("stock.journal","Stock Journal",required=True), } _defaults={ diff --git a/netforce_clinic/models/dialyzer.py b/netforce_clinic/models/dialyzer.py index 6dd2a1f..698047d 100644 --- a/netforce_clinic/models/dialyzer.py +++ b/netforce_clinic/models/dialyzer.py @@ -11,6 +11,7 @@ class Dialyzer(Model): _multi_company=True _fields={ + "name": fields.Char("Name",search=True), "number": fields.Char("Number",required=True,search=True), 'ref': fields.Char("Ref."), "description": fields.Text("Description",search=True), @@ -28,6 +29,7 @@ class Dialyzer(Model): "visit_id": fields.Many2One("clinic.visit","Visit"), "hd_case_id": fields.Many2One("clinic.hd.case","HD Case"), "hd_cases": fields.One2Many("clinic.hd.case","dlz_id","HD Case"), #TODO funtion to get hd case + 'department_id': fields.Many2One("clinic.department","Department"), } def _get_number(self,context={}): @@ -94,15 +96,27 @@ class Dialyzer(Model): break if not ship_address_id: patient.simple_address() - #raise Exception("contact %s dont'have address with type shipping"%partner.name) + + #XXX st=get_model("clinic.setting").browse(1) - journal=st.stock_journal_id - if not journal: + stock_journal=st.stock_journal_id + + wh_loc_id=None + cust_loc_id=None + department=obj.department_id + if department: + stock_journal=department.pick_out_journal_id + if stock_journal: + wh_loc_id=stock_journal.location_from_id.id + cust_loc_id=stock_journal.location_to_id.id + print("get location from stock journal %s "%(stock_journal.name)) + + if not stock_journal: raise Exception("Not found stock journal") pick_vals={ "type": "out", - 'journal_id': journal.id, + 'journal_id': stock_journal.id, "ref": obj.number, "related_id": "clinic.dialyzer,%s"%obj.id, "partner_id": obj.patient_id.partner_id.id, @@ -111,18 +125,21 @@ class Dialyzer(Model): "state": "draft", } - res=get_model("stock.location").search([["type","=","customer"]]) - if not res: - raise Exception("Customer location not found") - cust_loc_id=res[0] + if not cust_loc_id: + res=get_model("stock.location").search([["type","=","customer"]]) + if not res: + raise Exception("Customer location not found") + cust_loc_id=res[0] prod=obj.product_id - wh_loc_id=prod.location_id.id # product -> tab inventory -> warehouse filed if not wh_loc_id: - res=get_model("stock.location").search([["type","=","internal"]]) - if not res: - raise Exception("Warehouse not found") - wh_loc_id=res[0] + wh_loc_id=prod.location_id.id # product -> tab inventory -> warehouse filed + if not wh_loc_id: + res=get_model("stock.location").search([["type","=","internal"]]) + if not res: + raise Exception("Warehouse not found") + wh_loc_id=res[0] + line_vals={ "product_id": prod.id, "qty": 1, @@ -209,5 +226,35 @@ class Dialyzer(Model): 'flash': 'Dializer %s is copy to %s'%(obj.number,new_obj.number), } + + def onchange_patient(self,context={}): + data=context['data'] + patient_id=data['patient_id'] + patient=get_model("clinic.patient").browse(patient_id) + department=patient.department_id + if department: + data['department_id']=department.id + return data + + def name_get(self,ids,context={}): + vals=[] + for obj in self.browse(ids): + name=obj.number or '' + if obj.name: + name+=" (%s)"%obj.name + vals.append((obj.id,name)) + return vals + + def name_search(self,name,domain=None,context={},**kw): + dom=[["name","ilike","%"+name+"%"]] + if domain: + dom=[dom,domain] + ids1=self.search(dom) + dom=[["number","ilike","%"+name+"%"]] + if domain: + dom=[dom,domain] + ids2=self.search(dom) + ids=list(set(ids1+ids2)) + return self.name_get(ids,context=context) Dialyzer.register() diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index b4f9119..a778e88 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -495,20 +495,11 @@ class HDCase(Model): # 1. from department -> branch -> stock journal -> from, to department=obj.department_id if department: - branch=department.branch_id - if branch: - stock_journal=branch.pick_out_journal_id - if stock_journal: - wh_loc_id=stock_journal.location_from_id.id - cust_loc_id=stock_journal.location_to_id.id - print("get location from stock journal %s "%(stock_journal.name)) - elif obj.branch_id: - stock_journal=obj.branch_id.pick_out_journal_id - if stock_journal: - wh_loc_id=stock_journal.location_from_id.id - cust_loc_id=stock_journal.location_to_id.id - print("get location from stock journal %s "%(stock_journal.name)) - + stock_journal=department.pick_out_journal_id + if stock_journal: + wh_loc_id=stock_journal.location_from_id.id + cust_loc_id=stock_journal.location_to_id.id + print("get location from stock journal %s "%(stock_journal.name)) pick_vals={ "type": "out",