From 0175d5b9d78f20f0c48d801d52d960e5630ade60 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 23 Aug 2016 11:24:41 +0200 Subject: [PATCH] [IMP] base: remove merge_states method on res.partner.state model This function attempted to deduplicate states with same code in order to force the unique constraint creation. This is the job of a migration script and should not be execute at each update. Moreover, the current implementation is flawed and may lead to crash in some situations. --- openerp/addons/base/__openerp__.py | 1 - openerp/addons/base/res/post_base_data.xml | 6 ---- openerp/addons/base/res/res_country.py | 42 ---------------------- 3 files changed, 49 deletions(-) delete mode 100644 openerp/addons/base/res/post_base_data.xml diff --git a/openerp/addons/base/__openerp__.py b/openerp/addons/base/__openerp__.py index f9034441878..4cd21782039 100644 --- a/openerp/addons/base/__openerp__.py +++ b/openerp/addons/base/__openerp__.py @@ -63,7 +63,6 @@ The kernel of Odoo, needed for all installation. 'res/ir_property_view.xml', 'res/res_security.xml', 'security/ir.model.access.csv', - 'res/post_base_data.xml', # End because post_process ], 'demo': [ 'base_demo.xml', diff --git a/openerp/addons/base/res/post_base_data.xml b/openerp/addons/base/res/post_base_data.xml deleted file mode 100644 index 17aabd04e9c..00000000000 --- a/openerp/addons/base/res/post_base_data.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/openerp/addons/base/res/res_country.py b/openerp/addons/base/res/res_country.py index 68d1074d5d7..8b7f82d04b8 100644 --- a/openerp/addons/base/res/res_country.py +++ b/openerp/addons/base/res/res_country.py @@ -98,48 +98,6 @@ class CountryState(models.Model): name_search = location_name_search - def merge_states(self, cr, uid, ids=None, context=None): - Imd = self.pool['ir.model.data'] - State = self.pool['res.country.state'] - - query = """ - SELECT st.id, st.oldid, imd.id, imd.name, imd2.id, ids - FROM ( - SELECT st.country_id, st.code, max(st.id) as id, min(st.id) as oldid, string_agg(cast(id as text), ',') as ids - FROM res_country_state st - GROUP BY st.country_id, st.code - HAVING count(*) > 1 - ) st - LEFT JOIN ir_model_data imd on (imd.model = 'res.country.state' and imd.res_id = st.id) - LEFT JOIN ir_model_data imd2 on (imd2.model = 'res.country.state' and imd2.res_id = st.oldid) - WHERE imd.module = 'base'; - """ - cr.execute(query) - data = cr.fetchall() - - for st_id, st_oldid, imd_id, imd_name, imd2_id, ids in data: - values = dict(module=self._module) - if imd2_id: - # If duplicated record had already a xml_id we update the old xml_id and - # force to delete the new xml_id created to avoid constraint error - keepid = imd2_id - Imd.unlink(cr, uid, imd_id, context=context) - values.update(name=imd_name) - else: - # Else we point the new xml_id to the oldest duplicated state - keepid = imd_id - values.update(res_id=st_oldid) - - Imd.write(cr, uid, keepid, values, context=context) - State.unlink(cr, uid, st_id, context=context) - - duplicated_ids = set(map(int, ids.split(','))) - set([st_id, st_oldid]) - if duplicated_ids: - _logger.warning(_('State with id [%s] (%s) seems to have duplicated code: %s' % (st_oldid, imd_name, ','.join(duplicated_ids)))) - - if data: - self._add_sql_constraints(cr) - _sql_constraints = [ ('name_code_uniq', 'unique(country_id, code)', 'The code of the state must be unique by country !') ]