|
|
@ -2,7 +2,6 @@ |
|
|
|
# Copyright (C) 2015-TODAY Akretion (<http://www.akretion.com>). |
|
|
|
# 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 |