From e145f651cd99ac061826c1b0db8e77aefd655636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Pigeon?= Date: Tue, 20 Jun 2017 11:40:29 +0200 Subject: [PATCH] [FIX] avoid monkey patch and error on foreign key constraint --- pos_remove_pos_category/README.rst | 1 + pos_remove_pos_category/__manifest__.py | 5 ++- pos_remove_pos_category/models/product.py | 50 ++++------------------- 3 files changed, 11 insertions(+), 45 deletions(-) diff --git a/pos_remove_pos_category/README.rst b/pos_remove_pos_category/README.rst index bcdee09d..16d72ba4 100644 --- a/pos_remove_pos_category/README.rst +++ b/pos_remove_pos_category/README.rst @@ -48,6 +48,7 @@ Contributors * Sylvain Calador * Simone Orsi +* Cédric Pigeon Maintainer ---------- diff --git a/pos_remove_pos_category/__manifest__.py b/pos_remove_pos_category/__manifest__.py index bec002cd..581b129e 100644 --- a/pos_remove_pos_category/__manifest__.py +++ b/pos_remove_pos_category/__manifest__.py @@ -3,8 +3,9 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'POS Remove POS Category', - 'version': '10.0.0.1.0', - 'author': 'Akretion, Camptocamp SA, Odoo Community Association (OCA)', + 'version': '10.0.2.0.0', + 'author': 'Akretion, Camptocamp SA, ACSONE SA/NV, ' + 'Odoo Community Association (OCA)', 'category': 'Sales Management', 'depends': [ 'point_of_sale', diff --git a/pos_remove_pos_category/models/product.py b/pos_remove_pos_category/models/product.py index a7ae6ca7..a63c2fb5 100644 --- a/pos_remove_pos_category/models/product.py +++ b/pos_remove_pos_category/models/product.py @@ -2,7 +2,6 @@ # Copyright (C) 2015-TODAY Akretion (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -import sys from odoo import models, fields, api, tools @@ -10,7 +9,13 @@ class ProductTemplate(models.Model): _inherit = 'product.template' pos_categ_id = fields.Many2one('product.category', - store=True, related='categ_id') + store=False, + related='categ_id', + search='_search_pos_categ_id') + + @api.multi + def _search_pos_categ_id(self, operator, value): + return [('categ_id', operator, value)] @api.model def create(self, vals): @@ -50,44 +55,3 @@ class ProductCategory(models.Model): def _set_image(self): return self.write( {'image': tools.image_resize_image_big(self.image_medium)}) - - -_auto_end_original = models.BaseModel._auto_end - - -@api.model -def _auto_end(self): - """ Create the foreign keys recorded by _auto_init. - (pos_remove_pos_category monkey patching) - """ - module = self._context['module'] - foreign_keys = [] - patched = 'odoo.addons.pos_remove_pos_category' in sys.modules - - for fk in self._foreign_keys: - t = fk[0] - k = fk[1] - if patched and (t, k) == ('product_template', 'pos_categ_id'): - if module == 'pos_remove_pos_category': - self._cr.execute(''' - ALTER TABLE product_template - DROP CONSTRAINT IF EXISTS - product_template_pos_categ_id_fkey - ''') - self._cr.execute(''' - UPDATE product_template - SET pos_categ_id = categ_id; - ''') - self._cr.execute(''' - ALTER TABLE product_template ADD CONSTRAINT - "product_template_pos_categ_id_fkey" - FOREIGN KEY (pos_categ_id) - REFERENCES product_category(id) ON DELETE SET NULL; - ''') - continue - foreign_keys.append(fk) - self._foreign_keys = foreign_keys - return _auto_end_original - - -models.BaseModel._auto_end = _auto_end