From 0331cc8eda1f27b0f6dfa01e83fc2c3373819175 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 31 Aug 2023 11:00:02 +0200 Subject: [PATCH] [MIG] intrastat_product_type from v12 to v14 --- intrastat_product_type/__init__.py | 3 -- intrastat_product_type/__manifest__.py | 7 ++- .../intrastat_product_type.py | 49 +++++++------------ intrastat_product_type/post_install.py | 10 ---- intrastat_product_type/product_view.xml | 2 +- 5 files changed, 21 insertions(+), 50 deletions(-) delete mode 100644 intrastat_product_type/post_install.py diff --git a/intrastat_product_type/__init__.py b/intrastat_product_type/__init__.py index d65a115..ab0440d 100644 --- a/intrastat_product_type/__init__.py +++ b/intrastat_product_type/__init__.py @@ -1,4 +1 @@ -# -*- coding: utf-8 -*- - from . import intrastat_product_type -from .post_install import set_intrastat_type_on_products diff --git a/intrastat_product_type/__manifest__.py b/intrastat_product_type/__manifest__.py index cdf6975..f51f85d 100644 --- a/intrastat_product_type/__manifest__.py +++ b/intrastat_product_type/__manifest__.py @@ -4,7 +4,7 @@ { 'name': 'Intrastat Product Type', - 'version': '12.0.1.0.0', + 'version': '14.0.1.0.0', 'category': 'Accounting', 'license': 'AGPL-3', 'summary': 'Adds a special field Intrastat Type on Products', @@ -19,9 +19,8 @@ This module adds a field *Intrastat Type* on the Product Form with 2 possible op This module has been written by Alexis de Lattre from Akretion . """, 'author': 'Akretion', - 'website': 'http://www.akretion.com', + 'website': 'https://github.com/akretion/odoo-usability', 'depends': ['intrastat_product', 'l10n_fr_intrastat_service'], 'data': ['product_view.xml'], - 'post_init_hook': 'set_intrastat_type_on_products', - 'installable': False, + 'installable': True, } diff --git a/intrastat_product_type/intrastat_product_type.py b/intrastat_product_type/intrastat_product_type.py index f19aff4..c899b20 100644 --- a/intrastat_product_type/intrastat_product_type.py +++ b/intrastat_product_type/intrastat_product_type.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# Copyright 2016-2019 Akretion (http://www.akretion.com) +# Copyright 2016-2023 Akretion (http://www.akretion.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # @author Alexis de Lattre @@ -14,50 +13,36 @@ class ProductTemplate(models.Model): intrastat_type = fields.Selection([ ('product', 'Product'), ('service', 'Service'), - ], string='Intrastat Type', default='product', required=True, + ], + compute='_compute_intrastat_type', readonly=False, store=True, + required=True, string='Intrastat Type', help="Type of product used for the intrastat declarations. " "For example, you can configure a product with " "'Product Type' = 'Consumable' and 'Intrastat Type' = 'Service'.") - @api.multi @api.constrains('type', 'intrastat_type') def check_intrastat_type(self): for pt in self: if pt.intrastat_type == 'product' and pt.type == 'service': raise ValidationError(_( - "On the product %s, you cannot set Product Type to " - "'Service' and Intrastat Type to 'Product'.") % pt.name) + "On the product '%s', you cannot set Product Type to " + "'Service' and Intrastat Type to 'Product'.") + % pt.display_name) if pt.intrastat_type == 'service' and pt.type == 'product': raise ValidationError(_( - "On the product %s, you cannot set Intrastat Type to " + "On the product '%s', you cannot set Intrastat Type to " "'Service' and Product Type to 'Stockable product' " "(but you can set Product Type to 'Consumable' or " - "'Service').") % pt.name) + "'Service').") % pt.display_name) - @api.onchange('type') - def intrastat_type_onchange(self): - if self.type in ('product', 'consu'): - self.intrastat_type = 'product' - elif self.type == 'service': - self.intrastat_type = 'service' - - @api.model - def create(self, vals): - if vals.get('type'): - if not vals.get('intrastat_type'): - if vals['type'] in ('product', 'consu'): - vals['intrastat_type'] = 'product' - elif vals['type'] == 'service': - vals['intrastat_type'] = 'service' - elif ( - vals.get('intrastat_type') == 'product' and - vals['type'] == 'service'): - # usefull because intrastat_type = 'product' by default and - # wizards in other modules that don't depend on this module - # (e.g. sale_rental) may create a product with only - # {'type': 'service'} and no 'intrastat_type' - vals['intrastat_type'] = 'service' - return super(ProductTemplate, self).create(vals) + @api.depends('type') + def _compute_intrastat_type(self): + for pt in self: + if pt.type in ('product', 'consu'): + intrastat_type = 'product' + else: + intrastat_type = 'service' + pt.intrastat_type = intrastat_type class L10nFrIntrastatServiceDeclaration(models.Model): diff --git a/intrastat_product_type/post_install.py b/intrastat_product_type/post_install.py deleted file mode 100644 index bc839d8..0000000 --- a/intrastat_product_type/post_install.py +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2016-2019 Akretion (Alexis de Lattre ) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - - -def set_intrastat_type_on_products(cr, registry): - cr.execute( - "UPDATE product_template SET intrastat_type='service' " - "WHERE type='service'") - return diff --git a/intrastat_product_type/product_view.xml b/intrastat_product_type/product_view.xml index 3aa2e02..d4e4081 100644 --- a/intrastat_product_type/product_view.xml +++ b/intrastat_product_type/product_view.xml @@ -1,6 +1,6 @@