From f3d09104f9537f77c17b08bf060a440bb8e222db Mon Sep 17 00:00:00 2001 From: Vishmita Date: Thu, 29 Nov 2012 12:53:34 +0530 Subject: [PATCH 1/3] [FIX]onchange method for state bzr revid: vja@tinyerp.com-20121129072334-mz4ydyni8toz1u8p --- openerp/addons/base/res/res_company.py | 8 ++++++-- openerp/addons/base/res/res_company_view.xml | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/openerp/addons/base/res/res_company.py b/openerp/addons/base/res/res_company.py index b2f3e812145..2fe919886cf 100644 --- a/openerp/addons/base/res/res_company.py +++ b/openerp/addons/base/res/res_company.py @@ -123,7 +123,7 @@ class res_company(osv.osv): 'street2': fields.function(_get_address_data, fnct_inv=_set_address_data, size=128, type='char', string="Street2", multi='address'), 'zip': fields.function(_get_address_data, fnct_inv=_set_address_data, size=24, type='char', string="Zip", multi='address'), 'city': fields.function(_get_address_data, fnct_inv=_set_address_data, size=24, type='char', string="City", multi='address'), - 'state_id': fields.function(_get_address_data, fnct_inv=_set_address_data, type='many2one', domain="[('country_id', '=', country_id)]", relation='res.country.state', string="Fed. State", multi='address'), + 'state_id': fields.function(_get_address_data, fnct_inv=_set_address_data, type='many2one', relation='res.country.state', string="Fed. State", multi='address'), 'bank_ids': fields.one2many('res.partner.bank','company_id', 'Bank Accounts', help='Bank accounts related to this company'), 'country_id': fields.function(_get_address_data, fnct_inv=_set_address_data, type='many2one', relation='res.country', string="Country", multi='address'), 'email': fields.function(_get_address_data, fnct_inv=_set_address_data, size=64, type='char', string="Email", multi='address'), @@ -160,7 +160,11 @@ class res_company(osv.osv): res += '\n%s: %s' % (title, ', '.join(name for id, name in account_names)) return {'value': {'rml_footer': res, 'rml_footer_readonly': res}} - + def onchange_state(self, cr, uid, ids, state_id, context=None): + if state_id: + country_id = self.pool.get('res.country.state').browse(cr, uid, state_id, context).country_id.id + return {'value':{'country_id':country_id}} + return {} def on_change_country(self, cr, uid, ids, country_id, context=None): currency_id = self._get_euro(cr, uid, context=context) if country_id: diff --git a/openerp/addons/base/res/res_company_view.xml b/openerp/addons/base/res/res_company_view.xml index 1cc9b5bd833..c0893e2a42e 100644 --- a/openerp/addons/base/res/res_company_view.xml +++ b/openerp/addons/base/res/res_company_view.xml @@ -46,7 +46,7 @@
- +
From 6f953c189a0e090521e8ddb78e558aca24737960 Mon Sep 17 00:00:00 2001 From: "Vishmita Jadeja (openerp)" Date: Wed, 15 May 2013 16:28:46 +0530 Subject: [PATCH 2/3] [FIX]Improve Code bzr revid: vja@tinyerp.com-20130515105846-zkflow45bsbhe3ym --- openerp/addons/base/res/res_company.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/openerp/addons/base/res/res_company.py b/openerp/addons/base/res/res_company.py index d19af9fd403..57b0f393821 100644 --- a/openerp/addons/base/res/res_company.py +++ b/openerp/addons/base/res/res_company.py @@ -176,14 +176,13 @@ class res_company(osv.osv): return {'value': {'rml_footer': res, 'rml_footer_readonly': res}} def onchange_state(self, cr, uid, ids, state_id, context=None): if state_id: - country_id = self.pool.get('res.country.state').browse(cr, uid, state_id, context).country_id.id - return {'value':{'country_id':country_id}} + return {'value':{'country_id': self.pool.get('res.country.state').browse(cr, uid, state_id, context).country_id.id }} return {} def on_change_country(self, cr, uid, ids, country_id, context=None): currency_id = self._get_euro(cr, uid, context=context) if country_id: currency_id = self.pool.get('res.country').browse(cr, uid, country_id, context=context).currency_id.id - return {'value': {'currency_id': currency_id}} + return {'value': {'currency_id': currency_id, 'state_id': False},'domain':{'state_id': [('country_id','=',country_id)]}} def _search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False, access_rights_uid=None): From 8c9675e75ed704527f089b02a78c814e3a21295d Mon Sep 17 00:00:00 2001 From: "Vishmita Jadeja (openerp)" Date: Wed, 15 May 2013 19:04:50 +0530 Subject: [PATCH 3/3] [IMP]on change of country > If the selected state is of same country then don't change it and if it is of any other country then make it blank bzr revid: vja@tinyerp.com-20130515133450-db0xs8fmm67t9orj --- openerp/addons/base/res/res_company.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/openerp/addons/base/res/res_company.py b/openerp/addons/base/res/res_company.py index 57b0f393821..40b3b021751 100644 --- a/openerp/addons/base/res/res_company.py +++ b/openerp/addons/base/res/res_company.py @@ -179,10 +179,13 @@ class res_company(osv.osv): return {'value':{'country_id': self.pool.get('res.country.state').browse(cr, uid, state_id, context).country_id.id }} return {} def on_change_country(self, cr, uid, ids, country_id, context=None): + res = {'domain': {'state_id': []}} currency_id = self._get_euro(cr, uid, context=context) if country_id: currency_id = self.pool.get('res.country').browse(cr, uid, country_id, context=context).currency_id.id - return {'value': {'currency_id': currency_id, 'state_id': False},'domain':{'state_id': [('country_id','=',country_id)]}} + res['domain'] = {'state_id': [('country_id','=',country_id)]} + res['value'] = {'currency_id': currency_id} + return res def _search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False, access_rights_uid=None):