From 1a712b1203cfe3a7f55453f44d0577135c682d20 Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Wed, 18 Mar 2015 08:39:03 +0700 Subject: [PATCH] improve --- netforce_clinic/layouts/clinic_user_form.xml | 1 + netforce_clinic/models/account_invoice.py | 42 +++++++++++++++++++- netforce_clinic/models/account_payment.py | 24 +++++++++++ netforce_clinic/models/base_user.py | 1 + netforce_clinic/models/login.py | 3 ++ netforce_clinic/models/select_company.py | 8 ++-- netforce_clinic/models/sequence.py | 5 +++ netforce_clinic/models/shop.py | 12 ++++-- 8 files changed, 87 insertions(+), 9 deletions(-) diff --git a/netforce_clinic/layouts/clinic_user_form.xml b/netforce_clinic/layouts/clinic_user_form.xml index 20f36fc..d1dddc5 100644 --- a/netforce_clinic/layouts/clinic_user_form.xml +++ b/netforce_clinic/layouts/clinic_user_form.xml @@ -1,6 +1,7 @@ + diff --git a/netforce_clinic/models/account_invoice.py b/netforce_clinic/models/account_invoice.py index a7d05eb..aaf0679 100644 --- a/netforce_clinic/models/account_invoice.py +++ b/netforce_clinic/models/account_invoice.py @@ -1,5 +1,3 @@ -import time - from netforce.model import Model, fields, get_model class AccountInvoice(Model): @@ -9,6 +7,46 @@ class AccountInvoice(Model): 'department_id': fields.Many2One("clinic.department","Department",search=True), 'patient_partner_id': fields.Many2One("partner","Patient",search=True), } + + def _get_number(self,context={}): + defaults=context.get("defaults") + if defaults: # XXX + type=defaults.get("type") + inv_type=defaults.get("inv_type") + else: + type=context.get("type") + inv_type=context.get("inv_type") + seq_type=None + if type=="out": + if inv_type in ("invoice","prepay"): + seq_type="cust_invoice" + elif inv_type=="credit": + seq_type="cust_credit" + elif inv_type=="debit": + seq_type="cust_debit" + elif type=="in": + if inv_type in ("invoice","prepay"): + seq_type="supp_invoice" + elif inv_type=="credit": + seq_type="supp_credit" + elif inv_type=="debit": + seq_type="supp_debit" + if not seq_type: + return + seq_id=get_model("sequence").find_sequence(type=seq_type,context=context) + if not seq_id: + return None + while 1: + num=get_model("sequence").get_next_number(seq_id,context=context) + res=self.search([["number","=",num]]) + if not res: + return num + get_model("sequence").increment_number(seq_id,context=context) + + _defaults={ + "number": _get_number, + } + AccountInvoice.register() diff --git a/netforce_clinic/models/account_payment.py b/netforce_clinic/models/account_payment.py index 4233cee..1a4b701 100644 --- a/netforce_clinic/models/account_payment.py +++ b/netforce_clinic/models/account_payment.py @@ -4,7 +4,31 @@ class AccountPayment(Model): _inherit="account.payment" _fields={ 'rd_cust': fields.Boolean("RD Customize"), + 'number': fields.Char("Number",required=True,search=True), } + + def _get_number(self,context={}): + type=context.get("type") + if type=="in": + seq_type="pay_in" + elif type=="out": + seq_type="pay_out" + else: + return + seq_id=get_model("sequence").find_sequence(type=seq_type,context=context) # force to use context + if not seq_id: + return None + while 1: + num=get_model("sequence").get_next_number(seq_id,context=context) + res=self.search([["number","=",num]]) + if not res: + return num + get_model("sequence").increment_number(seq_id,context=context) + + _defaults={ + 'number': _get_number, + } + def run_report(self,ids,context={}): obj=self.browse(ids)[0] diff --git a/netforce_clinic/models/base_user.py b/netforce_clinic/models/base_user.py index ea454c4..bfd9536 100644 --- a/netforce_clinic/models/base_user.py +++ b/netforce_clinic/models/base_user.py @@ -5,6 +5,7 @@ class User(Model): _fields={ 'department_profile_id': fields.Many2One("clinic.department.profile","Department Profile"), 'department_id': fields.Many2One("clinic.department","Current Department"), + 'branch_id': fields.Many2One("clinic.branch","Branch"), 'old_profile_id': fields.Many2One('profile', "Old Profile"), } diff --git a/netforce_clinic/models/login.py b/netforce_clinic/models/login.py index b0f28b6..fe5f1c2 100644 --- a/netforce_clinic/models/login.py +++ b/netforce_clinic/models/login.py @@ -10,8 +10,11 @@ class Login(Model): user_id=get_active_user() user=get_model('base.user').browse(user_id) department=user.department_id + branch=user.branch_id if department: cookies['company_name']='%s (%s)'%(cookies['company_name'], department.name or "") + elif branch: + cookies['company_name']='%s (%s)'%(cookies['company_name'], branch.name or "") return res Login.register() diff --git a/netforce_clinic/models/select_company.py b/netforce_clinic/models/select_company.py index ad6dad7..af201dd 100644 --- a/netforce_clinic/models/select_company.py +++ b/netforce_clinic/models/select_company.py @@ -171,10 +171,12 @@ class SelectCompany(Model): 'profile_id': pf_id, }) res=super().select(ids,context) - if department_name: - cookies=res.get("cookies") - if cookies: + cookies=res.get("cookies") + if cookies: + if department_name: cookies['company_name']='%s (%s)'%(cookies['company_name'], department_name) + elif user.branch_id: + cookies['company_name']='%s (%s)'%(cookies['company_name'], user.branch_id.name or "") return res def get_select(self,context={}): diff --git a/netforce_clinic/models/sequence.py b/netforce_clinic/models/sequence.py index ffebd54..e91c818 100644 --- a/netforce_clinic/models/sequence.py +++ b/netforce_clinic/models/sequence.py @@ -64,11 +64,16 @@ class Sequence(Model): user_id=get_active_user() user=get_model('base.user').browse(user_id) dpt=user.department_id + branch=user.branch_id if dpt: branch_id=dpt.branch_id.id comp_dom=comp_dom+[["branch_id","=",branch_id]] + elif branch: + branch_id=branch.id + comp_dom=comp_dom+[["branch_id","=",branch_id]] elif context.get('branch_id'): comp_dom=comp_dom+[["branch_id","=",context['branch_id']]] + print('com_dom ', comp_dom) res=self.search(comp_dom,order="id") if res: return res[0] diff --git a/netforce_clinic/models/shop.py b/netforce_clinic/models/shop.py index 1c33583..984f22c 100644 --- a/netforce_clinic/models/shop.py +++ b/netforce_clinic/models/shop.py @@ -273,6 +273,7 @@ class Shop(Model): due_date=obj.date[1:10] # XXX context['type']='out' context['inv_type']='invoice' + context['branch_id']=obj.branch_id.id cst=get_model('clinic.setting').browse(1) prod_acc=cst.get_product_account partner=obj.contact_id @@ -310,8 +311,7 @@ class Shop(Model): 'account_id': account_id, 'ar_debit_id': ar_debit_id, })) - - inv_id=get_model("account.invoice").create(vals,context) + inv_id=get_model("account.invoice").create(vals,context=context) inv=get_model("account.invoice").browse(inv_id) inv.post() obj.make_pickings() @@ -390,6 +390,7 @@ class Shop(Model): context={ 'pick_type': 'out', 'journal_id': pick_vals['journal_id'], + 'branch_id': obj.branch_id.id, } pick_id=picking_obj.create(pick_vals,context=context) pick=picking_obj.browse(pick_id) @@ -406,7 +407,6 @@ class Shop(Model): raise Exception("No Cash Account") if not income_account_id: raise Exception("No Income Account") - company_id=get_active_company() vals={ "partner_id": partner.id, @@ -438,7 +438,11 @@ class Shop(Model): 'account_id': account_id, })) - payment_id=get_model("account.payment").create(vals,context={"type":"in"}) + context={ + 'type': 'in', + 'branch_id': obj.branch_id.id, + } + payment_id=get_model("account.payment").create(vals,context=context) payment=get_model('account.payment').browse(payment_id) payment.post() obj.make_pickings()