From e3c0050755eba9b96f47dd941150fd97a9eef9b3 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Fri, 15 Apr 2016 22:01:45 +0200 Subject: [PATCH] Add module intrastat_product_type --- intrastat_product_type/__init__.py | 4 ++ intrastat_product_type/__openerp__.py | 46 +++++++++++++++++++ .../intrastat_product_type.py | 41 +++++++++++++++++ intrastat_product_type/post_install.py | 8 ++++ intrastat_product_type/product_view.xml | 25 ++++++++++ 5 files changed, 124 insertions(+) create mode 100644 intrastat_product_type/__init__.py create mode 100644 intrastat_product_type/__openerp__.py create mode 100644 intrastat_product_type/intrastat_product_type.py create mode 100644 intrastat_product_type/post_install.py create mode 100644 intrastat_product_type/product_view.xml diff --git a/intrastat_product_type/__init__.py b/intrastat_product_type/__init__.py new file mode 100644 index 0000000..d65a115 --- /dev/null +++ b/intrastat_product_type/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import intrastat_product_type +from .post_install import set_intrastat_type_on_products diff --git a/intrastat_product_type/__openerp__.py b/intrastat_product_type/__openerp__.py new file mode 100644 index 0000000..2e9d11d --- /dev/null +++ b/intrastat_product_type/__openerp__.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Intrastat Product Type module for Odoo +# Copyright (C) 2016 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + + +{ + 'name': 'Intrastat Product Type', + 'version': '0.1', + 'category': 'Accounting & Finance', + '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', + 'depends': ['intrastat_product', 'l10n_fr_intrastat_service'], + 'data': ['product_view.xml'], + 'post_init_hook': 'set_intrastat_type_on_products', + 'installable': True, +} diff --git a/intrastat_product_type/intrastat_product_type.py b/intrastat_product_type/intrastat_product_type.py new file mode 100644 index 0000000..e99ce52 --- /dev/null +++ b/intrastat_product_type/intrastat_product_type.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (http://www.akretion.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# @author Alexis de Lattre + + +from openerp import models, fields + + +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'.") + + +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/post_install.py b/intrastat_product_type/post_install.py new file mode 100644 index 0000000..5366b28 --- /dev/null +++ b/intrastat_product_type/post_install.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- + + +def set_intrastat_type_on_products(cr, pool): + 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 new file mode 100644 index 0000000..38cb4e4 --- /dev/null +++ b/intrastat_product_type/product_view.xml @@ -0,0 +1,25 @@ + + + + + + + + + intrastat_product_type.product.template.form + product.template + + + + + + + + + + +