From 954dcedd6633e22fdfb5f9335d7cf1674a3d913e Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Wed, 18 Mar 2015 10:51:38 +0700 Subject: [PATCH] address --- netforce_clinic/models/fin_setting.py | 19 ++++++++++++++++- netforce_clinic/models/hd_case.py | 30 +++++++++++++++------------ netforce_clinic/models/shop.py | 28 +++++++++++++------------ 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/netforce_clinic/models/fin_setting.py b/netforce_clinic/models/fin_setting.py index 9ae3190..efde72d 100644 --- a/netforce_clinic/models/fin_setting.py +++ b/netforce_clinic/models/fin_setting.py @@ -1,4 +1,5 @@ -from netforce.model import Model, fields +from netforce.model import Model, fields, get_model +from netforce.access import get_active_user class Settings(Model): _inherit="settings" @@ -9,4 +10,20 @@ class Settings(Model): "ap_doctor_id": fields.Many2One("account.account","Account Payment Doctor"), } + def get_default_address(self,ids,context={}): + branch_id=None + if context.get("branch_id"): + branch_id=context['branch_id'] + else: + user_id=get_active_user() + user=get_model("base.user").browse(user_id) + branch_id=user.branch_id.id + vals={} + for obj in self.browse(ids): + vals[obj.id]=obj.addresses and obj.addresses[0].id or None + if branch_id: + branch=get_model("clinic.branch").browse(branch_id) + vals[obj.id]=branch.addresses and branch.addresses[0].id or None + return vals + Settings.register() diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index e286f49..4df3ce9 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -1000,12 +1000,21 @@ class HDCase(Model): payment=get_model("account.payment").browse(int(payment_id)) comp_id=get_active_company() comp=get_model('company').browse(comp_id) - st=get_model('settings').browse(1) + hdcase=payment.related_id + if hdcase: + context['branch_id']=hdcase.branch_id.id + st=get_model('settings').browse(1,context=context) cst=get_model('clinic.setting').browse(1) - addresses=st.addresses comp_addr='' - if addresses: - comp_addr=addresses[0].address_text + if st.default_address_id: + comp_addr='\n'.join([ + st.default_address_id.address or "", + st.default_address_id.city or "", + st.default_address_id.postal_code or "", + st.default_address_id.country_id.name or "", + st.default_address_id.phone and "Phone: %s"%st.default_address_id.phone or "", + st.default_address_id.fax and "Fax: %s"%st.default_address_id.fax or "" + ]) cust=payment.partner_id cust_name=cust.name or '' cust_addr='' @@ -1038,16 +1047,11 @@ class HDCase(Model): pay_type=payment.pay_type or '' user_id=get_active_user() user=get_model("base.user").browse(user_id) - #XXX remove , - index=0 - for ca in comp_addr: - ca=ca.replace(" ","") - if ca==',': - break - index+=1 - comp_addr=comp_addr[index+1:] + comp_name=comp.name or "" + if st.default_address_id.company: + comp_name=st.default_address_id.company or "" data={ - 'comp_name': comp.name or '', + 'comp_name': comp_name, 'comp_addr': comp_addr or '', 'tax_no': st.tax_no or '', 'number': payment.number or '', diff --git a/netforce_clinic/models/shop.py b/netforce_clinic/models/shop.py index 984f22c..5f5a237 100644 --- a/netforce_clinic/models/shop.py +++ b/netforce_clinic/models/shop.py @@ -498,12 +498,19 @@ class Shop(Model): shop=self.browse(shop_id) comp_id=get_active_company() comp=get_model('company').browse(comp_id) - st=get_model('settings').browse(1) + context['branch_id']=shop.branch_id.id + st=get_model('settings').browse(1,context=context) cst=get_model('clinic.setting').browse(1) - addresses=st.addresses comp_addr='' - if addresses: - comp_addr=addresses[0].address_text + if st.default_address_id: + comp_addr='\n'.join([ + st.default_address_id.address or "", + st.default_address_id.city or "", + st.default_address_id.postal_code or "", + st.default_address_id.country_id.name or "", + st.default_address_id.phone and "Phone: %s"%st.default_address_id.phone or "", + st.default_address_id.fax and "Fax: %s"%st.default_address_id.fax or "" + ]) cust=shop.contact_id cust_name=cust.name or '' cust_addr='' @@ -538,16 +545,11 @@ class Shop(Model): pay_type=shop.pay_type or '' user_id=get_active_user() user=get_model("base.user").browse(user_id) - #XXX remove , - index=0 - for ca in comp_addr: - ca=ca.replace(" ","") - if ca==',': - break - index+=1 - comp_addr=comp_addr[index+1:] + comp_name=comp.name or "" + if st.default_address_id.company: + comp_name=st.default_address_id.company or "" data={ - 'comp_name': comp.name or '', + 'comp_name': comp_name, 'comp_addr': comp_addr or '', 'tax_no': st.tax_no or '', 'number': shop.number or '',