From b340622e9e743ec0bf7d54a8c982998f3d166855 Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Tue, 17 Mar 2015 22:51:56 +0700 Subject: [PATCH] sequence --- .../layouts/clinic_sequence_list.xml | 5 ++ netforce_clinic/models/dialyzer.py | 10 ++- netforce_clinic/models/hd_case.py | 6 +- netforce_clinic/models/sequence.py | 74 ++++++++++++++++++- netforce_clinic/models/staff.py | 3 +- netforce_clinic/models/visit.py | 14 ++-- 6 files changed, 98 insertions(+), 14 deletions(-) create mode 100644 netforce_clinic/layouts/clinic_sequence_list.xml diff --git a/netforce_clinic/layouts/clinic_sequence_list.xml b/netforce_clinic/layouts/clinic_sequence_list.xml new file mode 100644 index 0000000..3bbc643 --- /dev/null +++ b/netforce_clinic/layouts/clinic_sequence_list.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/netforce_clinic/models/dialyzer.py b/netforce_clinic/models/dialyzer.py index 9afe046..6176434 100644 --- a/netforce_clinic/models/dialyzer.py +++ b/netforce_clinic/models/dialyzer.py @@ -35,10 +35,10 @@ class Dialyzer(Model): def _get_number(self,context={}): while 1: - seq_name='Clinic Dialyzer' - seq_id=get_model("sequence").find_sequence(name=seq_name) + seq_type='clinic_dlz' + seq_id=get_model("sequence").find_sequence(type=seq_type) if not seq_id: - raise Exception("Can not found sequence %s"%seq_name) + raise Exception("Can not found sequence %s"%seq_type) num=get_model("sequence").get_next_number(seq_id,context=context) if not num: return None @@ -175,7 +175,9 @@ class Dialyzer(Model): pick.set_done([pick_id]) number=obj.number.replace("/","") if not number: - number=self._get_number(context) + department=obj.department_id + context['branch_id']=department.branch_id.id + number=self._get_number(context=context) obj.write({ "number": number, "state": "active", diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index 43626cd..e286f49 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -184,7 +184,8 @@ class HDCase(Model): def _get_number(self,context={}): while 1: - seq_id=get_model("sequence").find_sequence(name="Clinic HD Case") + #seq_id=get_model("sequence").find_sequence(name="Clinic HD Case") + seq_id=get_model("sequence").find_sequence(type="clinic_hdcase") num=get_model("sequence").get_next_number(seq_id,context=context) if not num: return None @@ -715,7 +716,8 @@ class HDCase(Model): 'state': 'in_progress', } if obj.number=='/': - number=self._get_number() + context['branch_id']=obj.branch_id.id + number=self._get_number(context=context) vals['number']=number # update start time diff --git a/netforce_clinic/models/sequence.py b/netforce_clinic/models/sequence.py index 8aedbec..ffebd54 100644 --- a/netforce_clinic/models/sequence.py +++ b/netforce_clinic/models/sequence.py @@ -1,10 +1,80 @@ -from netforce.model import Model, fields +from netforce.model import Model, fields, get_model +from netforce.access import get_active_company, get_active_user class Sequence(Model): _inherit="sequence" _fields={ - 'fax': fields.Char("Fax"), 'branch_id': fields.Many2One("clinic.branch","Branch"), + "type": fields.Selection([ + ["cust_invoice","Customer Invoice"], + ["supp_invoice","Supplier Invoice"], + ["cust_credit","Customer Credit Note"], + ["supp_credit","Supplier Credit Note"], + ["cust_debit","Customer Debit Note"], + ["supp_debit","Supplier Debit Note"], + ["pay_in","Incoming Payment"], + ["pay_out","Outgoing Payment"], + ["transfer","Transfer"], + ["tax_no","Tax No"], + ["wht_no","WHT No"], + ["account_move","Journal Entry"], + ["pick_in","Goods Receipt"], + ["pick_internal","Goods Transfer"], + ["pick_out","Goods Issue"], + ["stock_count","Stock Count"], + ["stock_lot","Lot / Serial Number"], + ["stock_container","Container"], + ["shipping_rates","Shipping Rates"], + ["sale_quot","Sales Quotations"], + ["sale_order","Sales Order"], + ["ecom_sale_order","Ecommerce Sales Order"], + ["purchase_order","Purchase Order"], + ["purchase_request","Purchase Request"], + ["pos_closure","POS Register Closure"], + ["production","Production Order"], + ["bom","Bill of Material"], + ["service_item","Service Item"], + ["job","Service Order"], + ["service_contract","Service Contract"], + ["employee","Employee"], + ["payrun","Payrun"], + ["leave_request","Leave Request"], + ["expense","Expense Claim"], + ["fixed_asset","Fixed Asset"], + ["claim","Product Claims"], + ["borrow","Product Borrowings"], + ["clinic_patient","Patient"], + ["clinic_staff","Staff"], + ["clinic_visit","Visit"], + ["clinic_hdcase","HD Case"], + ["clinic_dlz","Dialyzer"], + ["clinic_rdshop","RD Shop"], + ["other","Other"]],"Type",required=True,search=True), } + def find_sequence(self,type=None,name=None,context={}): + if type and name: + dom=[["type","=",type],["name","=",name]] + elif type: + dom=[["type","=",type]] + elif name: + dom=[["name","=",name]] + company_id=get_active_company() + comp_dom=dom+[["company_id","=",company_id]] + user_id=get_active_user() + user=get_model('base.user').browse(user_id) + dpt=user.department_id + if dpt: + branch_id=dpt.branch_id.id + comp_dom=comp_dom+[["branch_id","=",branch_id]] + elif context.get('branch_id'): + comp_dom=comp_dom+[["branch_id","=",context['branch_id']]] + res=self.search(comp_dom,order="id") + if res: + return res[0] + res=self.search(dom,order="id") + if res: + return res[0] + return None + Sequence.register() diff --git a/netforce_clinic/models/staff.py b/netforce_clinic/models/staff.py index eb87b82..a6badbf 100644 --- a/netforce_clinic/models/staff.py +++ b/netforce_clinic/models/staff.py @@ -170,7 +170,8 @@ class Staff(Model): def _get_number(self,context={}): while 1: - seq_id=get_model("sequence").find_sequence(name="Clinic Staff") + seq_type='clinic_staff' + seq_id=get_model("sequence").find_sequence(type=seq_type) if not seq_id: return "/" num=get_model("sequence").get_next_number(seq_id,context=context) diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py index ccd58c6..83e1ba5 100644 --- a/netforce_clinic/models/visit.py +++ b/netforce_clinic/models/visit.py @@ -55,10 +55,10 @@ class Visit(Model): def _get_number(self,context={}): while 1: - seq_name='Clinic Visit' - seq_id=get_model("sequence").find_sequence(name=seq_name) + seq_type='clinic_visit' + seq_id=get_model("sequence").find_sequence(type=seq_type) if not seq_id: - raise Exception("Can not found sequence %s"%seq_name) + raise Exception("Can not found sequence %s"%seq_type) num=get_model("sequence").get_next_number(seq_id,context=context) if not num: return None @@ -153,7 +153,9 @@ class Visit(Model): raise Exception("Can not confirm visit %s: datenow is %s"%(obj.number or "", datenow)) number=obj.number if number=="/" or not number: - number=self._get_number(context) + branch=obj.department_id.branch_id + context['branch_id']=branch.id + number=self._get_number(context=context) vals={ 'number': number, 'state': 'confirmed', @@ -439,7 +441,9 @@ class Visit(Model): obj=self.browse(ids)[0] if obj.number != '/' or obj.state not in ('draft','pending'): return - number=self._get_number(context) + branch=obj.department_id.branch_id + context['branch_id']=branch.id + number=self._get_number(context=context) obj.write({ 'number': number, })