From 158648e60441f2e208f69620c3f0297802e82bf1 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 12 May 2016 17:38:04 +0200 Subject: [PATCH] Backport intrastat_product_type from 8 to 7 --- intrastat_product_type/__init__.py | 3 ++ intrastat_product_type/__openerp__.py | 45 ++++++++++++++++++ .../intrastat_product_type.py | 47 +++++++++++++++++++ intrastat_product_type/post_install_manual.py | 9 ++++ intrastat_product_type/product_view.xml | 25 ++++++++++ 5 files changed, 129 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_manual.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..61ae274 --- /dev/null +++ b/intrastat_product_type/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import intrastat_product_type diff --git a/intrastat_product_type/__openerp__.py b/intrastat_product_type/__openerp__.py new file mode 100644 index 0000000..50d0933 --- /dev/null +++ b/intrastat_product_type/__openerp__.py @@ -0,0 +1,45 @@ +# -*- 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': ['l10n_fr_intrastat_product', 'l10n_fr_intrastat_service'], + 'data': ['product_view.xml'], + '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..250a69d --- /dev/null +++ b/intrastat_product_type/intrastat_product_type.py @@ -0,0 +1,47 @@ +# -*- 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.osv import orm, fields + + +class ProductTemplate(orm.Model): + _inherit = 'product.template' + + _columns = { + 'intrastat_type': fields.selection([ + ('product', 'Product'), + ('service', 'Service'), + ], string='Intrastat Type', 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'.") + } + + _defaults = { + 'intrastat_type': 'product', + } + + +class ReportIntrastatService(orm.Model): + _inherit = "report.intrastat.service" + + def _is_service(self, cr, uid, invoice_line, context=None): + if invoice_line.product_id.intrastat_type == 'service': + return True + else: + return False + + +class ReportIntrastatProduct(orm.Model): + _inherit = 'report.intrastat.product' + + def _is_product(self, cr, uid, invoice_line, context=None): + 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_manual.py b/intrastat_product_type/post_install_manual.py new file mode 100644 index 0000000..0243756 --- /dev/null +++ b/intrastat_product_type/post_install_manual.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- + +# POST-INIT-HOOK doesn't work in v7 (only v8 and above) +# So the SQL needs to be executed manually +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..badf0f5 --- /dev/null +++ b/intrastat_product_type/product_view.xml @@ -0,0 +1,25 @@ + + + + + + + + + intrastat_product_type.product.product.form + product.product + + + + + + + + + + +