From 9ea7a79d218168dd4cad158bbbd2d7b3632bb6b3 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 11 Dec 2024 22:45:45 +0100 Subject: [PATCH] [MIG] intrastat_product_type from v14 to v16 --- intrastat_product_type/README.rst | 19 +++++ intrastat_product_type/__init__.py | 5 +- intrastat_product_type/__manifest__.py | 21 ++--- intrastat_product_type/i18n/fr.po | 69 ++++++++++++++++ .../intrastat_product_type.py | 82 ------------------- intrastat_product_type/models/__init__.py | 3 + .../models/intrastat_product_declaration.py | 17 ++++ .../l10n_fr_intrastat_service_declaration.py | 15 ++++ intrastat_product_type/models/product.py | 41 ++++++++++ intrastat_product_type/post_install.py | 10 --- .../{product_view.xml => views/product.xml} | 6 +- 11 files changed, 173 insertions(+), 115 deletions(-) create mode 100644 intrastat_product_type/README.rst create mode 100644 intrastat_product_type/i18n/fr.po delete mode 100644 intrastat_product_type/intrastat_product_type.py create mode 100644 intrastat_product_type/models/__init__.py create mode 100644 intrastat_product_type/models/intrastat_product_declaration.py create mode 100644 intrastat_product_type/models/l10n_fr_intrastat_service_declaration.py create mode 100644 intrastat_product_type/models/product.py delete mode 100644 intrastat_product_type/post_install.py rename intrastat_product_type/{product_view.xml => views/product.xml} (71%) diff --git a/intrastat_product_type/README.rst b/intrastat_product_type/README.rst new file mode 100644 index 0000000..a83ba74 --- /dev/null +++ b/intrastat_product_type/README.rst @@ -0,0 +1,19 @@ +Intrastat Product Type +====================== + +This module is designed for a very special usage scenario: some companies want to handle the delivery of services the same way as they handle the delivery of goods; they want to show the services in the delivery note. So, those companies configure the services with Type = *Consumable*. This works well to have the services on the outgoing pickings, but it is a problem for the intrastat declarations. + +This module adds a field *Intrastat Type* on *Consumable* products with 2 possible options: *Product* or *Service*. The intrastat declaration will use this field instead of the native *Type* field. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* Alexis de Lattre diff --git a/intrastat_product_type/__init__.py b/intrastat_product_type/__init__.py index d65a115..0650744 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 +from . import models diff --git a/intrastat_product_type/__manifest__.py b/intrastat_product_type/__manifest__.py index cdf6975..986704b 100644 --- a/intrastat_product_type/__manifest__.py +++ b/intrastat_product_type/__manifest__.py @@ -1,27 +1,16 @@ -# Copyright 2016-2019 Akretion (http://www.akretion.com) +# Copyright 2016-2024 Akretion France (http://www.akretion.com) # @author Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Intrastat Product Type', - 'version': '12.0.1.0.0', + 'version': '16.0.1.0.0', 'category': 'Accounting', 'license': 'AGPL-3', 'summary': 'Adds a special field Intrastat Type on Products', - 'description': """ -Intrastat Product Type -====================== - -This module is designed for a very special usage scenario. Some companies want to handle the delivery of services the same way as they handle the delivery of goods ; they want to show the services in the delivery note, etc. So, those companies configure the services with Type = *Consumable*. This works well to have the services on the outgoing pickings, but it is a problem for the intrastat declarations. - -This module adds a field *Intrastat Type* on the Product Form with 2 possible options: *Product* or *Service*. The intrastat declaration will use this field instead of the native *Type* field. - -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, + 'data': ['views/product.xml'], + 'installable': True, } diff --git a/intrastat_product_type/i18n/fr.po b/intrastat_product_type/i18n/fr.po new file mode 100644 index 0000000..92cc55d --- /dev/null +++ b/intrastat_product_type/i18n/fr.po @@ -0,0 +1,69 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * intrastat_product_type +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-12-11 21:40+0000\n" +"PO-Revision-Date: 2024-12-11 21:40+0000\n" +"Last-Translator: Alexis de Lattre \n" +"Language-Team: \n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: intrastat_product_type +#: model:ir.model,name:intrastat_product_type.model_l10n_fr_intrastat_service_declaration +msgid "DES" +msgstr "DES" + +#. module: intrastat_product_type +#: model:ir.model,name:intrastat_product_type.model_intrastat_product_declaration +msgid "EMEBI" +msgstr "EMEBI" + +#. module: intrastat_product_type +#: model:ir.model.fields,field_description:intrastat_product_type.field_product_product__intrastat_type +#: model:ir.model.fields,field_description:intrastat_product_type.field_product_template__intrastat_type +msgid "Intrastat Type" +msgstr "Type intrastat" + +#. module: intrastat_product_type +#. odoo-python +#: code:addons/intrastat_product_type/models/product.py:0 +#, python-format +msgid "" +"On product '%s' which is not a consumable, Intrastat Type must have the same " +"value as Type." +msgstr "" +"Pour le produit '%s' qui n'est pas un consommable, le type intrastat doit avoir " +"la même valeur que le type." + +#. module: intrastat_product_type +#: model:ir.model,name:intrastat_product_type.model_product_template +#: model:ir.model.fields.selection,name:intrastat_product_type.selection__product_template__intrastat_type__product +msgid "Product" +msgstr "Produit" + +#. module: intrastat_product_type +#: model:ir.model.fields.selection,name:intrastat_product_type.selection__product_template__intrastat_type__service +msgid "Service" +msgstr "Service" + +#. module: intrastat_product_type +#: model:ir.model.fields,help:intrastat_product_type.field_product_product__intrastat_type +#: model:ir.model.fields,help:intrastat_product_type.field_product_template__intrastat_type +msgid "" +"Type of product used for the intrastat declarations. It allows you to " +"configure a service product as 'Consumable' to have it in pickings but " +"configure it with Intrastat Type = 'Service' to consider it as a service for " +"intrastat declarations." +msgstr "" +"Type de produit utilisé pour la DES et l'EMEBI. Cela vous permet de " +"configurer un produit de service comme 'consommable' pour l'avoir dans les " +"bons de livraison mais de le configurer avec type intrastat = 'Service' pour le " +"considérer comme un service pour la DES et l'EMEBI." diff --git a/intrastat_product_type/intrastat_product_type.py b/intrastat_product_type/intrastat_product_type.py deleted file mode 100644 index f19aff4..0000000 --- a/intrastat_product_type/intrastat_product_type.py +++ /dev/null @@ -1,82 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2016-2019 Akretion (http://www.akretion.com) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -# @author Alexis de Lattre - - -from odoo import models, fields, api, _ -from odoo.exceptions import ValidationError - - -class ProductTemplate(models.Model): - _inherit = 'product.template' - - intrastat_type = fields.Selection([ - ('product', 'Product'), - ('service', 'Service'), - ], string='Intrastat Type', default='product', required=True, - 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) - if pt.intrastat_type == 'service' and pt.type == 'product': - raise ValidationError(_( - "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) - - @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) - - -class L10nFrIntrastatServiceDeclaration(models.Model): - _inherit = "l10n.fr.intrastat.service.declaration" - - def _is_service(self, invoice_line): - if invoice_line.product_id.intrastat_type == 'service': - return True - else: - return False - - -class IntrastatProductDeclaration(models.Model): - _inherit = 'intrastat.product.declaration' - - def _is_product(self, invoice_line): - if ( - invoice_line.product_id and - invoice_line.product_id.intrastat_type == 'product'): - return True - else: - return False diff --git a/intrastat_product_type/models/__init__.py b/intrastat_product_type/models/__init__.py new file mode 100644 index 0000000..8d41419 --- /dev/null +++ b/intrastat_product_type/models/__init__.py @@ -0,0 +1,3 @@ +from . import product +from . import intrastat_product_declaration +from . import l10n_fr_intrastat_service_declaration diff --git a/intrastat_product_type/models/intrastat_product_declaration.py b/intrastat_product_type/models/intrastat_product_declaration.py new file mode 100644 index 0000000..ba08581 --- /dev/null +++ b/intrastat_product_type/models/intrastat_product_declaration.py @@ -0,0 +1,17 @@ +# Copyright 2016-2024 Akretion France (https://www.akretion.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# @author Alexis de Lattre + +from odoo import models + + +class IntrastatProductDeclaration(models.Model): + _inherit = 'intrastat.product.declaration' + + def _is_product(self, invoice_line): + if ( + invoice_line.product_id and + invoice_line.product_id.intrastat_type == 'product'): + return True + else: + return False diff --git a/intrastat_product_type/models/l10n_fr_intrastat_service_declaration.py b/intrastat_product_type/models/l10n_fr_intrastat_service_declaration.py new file mode 100644 index 0000000..47802ab --- /dev/null +++ b/intrastat_product_type/models/l10n_fr_intrastat_service_declaration.py @@ -0,0 +1,15 @@ +# Copyright 2016-2024 Akretion France (https://www.akretion.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# @author Alexis de Lattre + +from odoo import models + + +class L10nFrIntrastatServiceDeclaration(models.Model): + _inherit = "l10n.fr.intrastat.service.declaration" + + def _is_service(self, invoice_line): + if invoice_line.product_id.intrastat_type == 'service': + return True + else: + return False diff --git a/intrastat_product_type/models/product.py b/intrastat_product_type/models/product.py new file mode 100644 index 0000000..5f1cd1f --- /dev/null +++ b/intrastat_product_type/models/product.py @@ -0,0 +1,41 @@ +# Copyright 2016-2024 Akretion France (https://www.akretion.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# @author Alexis de Lattre + + +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + intrastat_type = fields.Selection([ + ('product', 'Product'), + ('service', 'Service'), + ], + compute='_compute_intrastat_type', + readonly=False, store=True, precompute=True, required=True, + help="Type of product used for the intrastat declarations. " + "It allows you to configure a service product as 'Consumable' " + "to have it in pickings but configure it with " + "Intrastat Type = 'Service' to consider it as a " + "service for intrastat declarations.") + + @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 + + @api.constrains('type', 'intrastat_type') + def _check_intrastat_type(self): + for pt in self: + if pt.type != 'consu' and pt.intrastat_type != pt.type: + raise ValidationError(_( + "On product '%s' which is not a consumable, " + "Intrastat Type must have the same value as Type.") + % pt.display_name) 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/views/product.xml similarity index 71% rename from intrastat_product_type/product_view.xml rename to intrastat_product_type/views/product.xml index 3aa2e02..fe5ff7c 100644 --- a/intrastat_product_type/product_view.xml +++ b/intrastat_product_type/views/product.xml @@ -1,6 +1,6 @@ @@ -13,8 +13,8 @@ product.template - - + +