From b5f1d9ac8f1c219046576159f72f3d014a240037 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 5 Apr 2011 00:57:21 +0200 Subject: [PATCH] [ADD] intrastat_base: Redesign for 6.1 Complete change of design for intrastat_type ! Now that report_intrastat_product/service object is stored in database, we don't need the legal_intrastat state on invoices any more, because we will be able to create entry lines for DEB for a repair of equipment under warranty without using a legal_intrastat. Report_intrastat_type is now only required for DEB -> object moved to module l10n_fr_intrastat_product. For DEB, the button "regenerate lines" only regenerate DEB lines related to invoices. Renamed intrastat base module, because it doesn't have France-specific parameters any more. Add demo data. Full re-design of intrastat types : probably requires deleting the report_intrastat_type table, restarting OpenERP and re-creating intrastat types. Moved intrastat departments from stock.warehouse to stock.location. Dropped SQL queries ; replaced by traditionnal python code logic. No more need to have one rate per day for invoices with foreign currency. Add total fiscal value for DEB More code factorization. Prepare translation work. Moved some demo data from l10n_fr_intrastat_product to intrastat_base Moved configuration about taxes from company form to tax form Some modifications to ease v5 -> v6 migration : - object report_intrastat_code now belong to group account manager - button functions now return True Tried to implement the following feature : open attachement form when the XML file as been generated : works on v6, but make client crash en v5 -> code has been commented DEB lines with procedure code = 25 are now deducted from the fiscal total. Round invoice total. Moved the field exclude_from_intrastat_if_present of account.tax from l10n_fr_intrastat_product to intrastat_base, because it should also be used in the module l10n_fr_intrastat_service. Take this field into account in the generation of DEB lines (module l10n_fr_intrastat_service). It is now possible to set the H.S. code on the product category. Some "return None" changed to "return True" Implemented the fiscal representative : for example, when you ship to the EU but invoice outside of the EU, your customer needs to have a fiscal representative inside the EU, which will be used for the DEB . depend on base_vat instead of account. Same modification as my previous commit for DEB : when we sell to a physical person in the EU with VAT, the move is not declared in DEB, so it must not block with a "raise" if the partner doesn't have a VAT number. Add option "is_accessory_cost" on product.template : If the invoice has is_accessory_cost services but no regular product -> DES If the invoice has is_accessory_cost services and regular product -> added to the cost of products in DEB Now allows "pricelist for statistical value" which is not in EUR (the currency conversion will be made from the pricelist currency to EUR) Usability improvements : - Order for DEB and DES tree view : "the more recent at the top" - distinction between "Information to declare" and "Additionnal information" in intrastat lines Better string. Update French translation. Use the new logger API of OpenERP 6.1 Move the "EU fiscal representative" field in order to avoid the "compression" of the VAT field that made it too small. Code clean-up : - context is not passed in constraints - don't use lambda when not necessary IMPORTANT CHANGE : - All EU countries should now be intrastat=True, including your own country - When generating lines for Intrastat Product/Service, all invoices for which country == Company's country are excluded Update help message according to my change of commit 61. Fix copyright header. --- intrastat_base/__init__.py | 28 ++++ intrastat_base/__openerp__.py | 54 ++++++ intrastat_base/country.py | 35 ++++ intrastat_base/country_data.xml | 87 ++++++++++ intrastat_base/country_view.xml | 36 ++++ intrastat_base/i18n/fr_FR.po | 176 ++++++++++++++++++++ intrastat_base/i18n/intrastat_base.pot | 166 ++++++++++++++++++ intrastat_base/intrastat_common.py | 132 +++++++++++++++ intrastat_base/intrastat_demo.xml | 57 +++++++ intrastat_base/intrastat_menu.xml | 16 ++ intrastat_base/partner_address.py | 35 ++++ intrastat_base/product.py | 49 ++++++ intrastat_base/product_view.xml | 53 ++++++ intrastat_base/security/ir.model.access.csv | 2 + intrastat_base/tax.py | 33 ++++ intrastat_base/tax_view.xml | 28 ++++ 16 files changed, 987 insertions(+) create mode 100644 intrastat_base/__init__.py create mode 100644 intrastat_base/__openerp__.py create mode 100644 intrastat_base/country.py create mode 100644 intrastat_base/country_data.xml create mode 100644 intrastat_base/country_view.xml create mode 100644 intrastat_base/i18n/fr_FR.po create mode 100644 intrastat_base/i18n/intrastat_base.pot create mode 100644 intrastat_base/intrastat_common.py create mode 100644 intrastat_base/intrastat_demo.xml create mode 100644 intrastat_base/intrastat_menu.xml create mode 100644 intrastat_base/partner_address.py create mode 100644 intrastat_base/product.py create mode 100644 intrastat_base/product_view.xml create mode 100644 intrastat_base/security/ir.model.access.csv create mode 100644 intrastat_base/tax.py create mode 100644 intrastat_base/tax_view.xml diff --git a/intrastat_base/__init__.py b/intrastat_base/__init__.py new file mode 100644 index 0000000..13ca149 --- /dev/null +++ b/intrastat_base/__init__.py @@ -0,0 +1,28 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Report intrastat base module for OpenERP +# Copyright (C) 2011 Akretion (http://www.akretion.com). All Rights Reserved +# @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 . +# +############################################################################## + +import country +import product +import tax +import partner_address +import intrastat_common + diff --git a/intrastat_base/__openerp__.py b/intrastat_base/__openerp__.py new file mode 100644 index 0000000..089173a --- /dev/null +++ b/intrastat_base/__openerp__.py @@ -0,0 +1,54 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Report intrastat base module for OpenERP +# Copyright (C) 2011 Akretion (http://www.akretion.com). All Rights Reserved +# @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': 'Base module for Intrastat reporting', + 'version': '1.1', + 'category': 'Localisation/Report Intrastat', + 'license': 'AGPL-3', + 'description': """This module contains the common functions for 2 other modules : +- l10n_fr_intrastat_service : the module for the "Déclaration Européenne des Services" (DES) +- l10n_fr_intrastat_product : the module for the "Déclaration d'Echange de Biens" (DEB) +This module is not usefull if it's not used together with one of those 2 modules. + +This module doesn't have any France-specific stuff. So it can be used as a basis for other intrastat modules for other EU countries. + +WARNING : this module conflicts with the module "report_intrastat" from the addons. If you have already installed the module "report_intrastat", you should uninstall it first before installing this module. + +Please contact Alexis de Lattre from Akretion for any help or question about this module. + """, + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['base_vat'], + 'init_xml': ['country_data.xml'], + 'update_xml': [ + 'security/ir.model.access.csv', + 'product_view.xml', + 'country_view.xml', + 'tax_view.xml', + 'intrastat_menu.xml', + ], + 'demo_xml': ['intrastat_demo.xml'], + 'installable': True, + 'active': False, +} diff --git a/intrastat_base/country.py b/intrastat_base/country.py new file mode 100644 index 0000000..2542d72 --- /dev/null +++ b/intrastat_base/country.py @@ -0,0 +1,35 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Report intrastat base module for OpenERP +# Copyright (C) 2011-2013 Akretion (http://www.akretion.com). All Rights Reserved +# @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 . +# +############################################################################## + +from osv import osv, fields + +class res_country(osv.osv): + _inherit = 'res.country' + _columns = { + 'intrastat': fields.boolean('EU country', help="Set to True for all European Union countries."), + } + + _defaults = { + 'intrastat': False, + } + +res_country() diff --git a/intrastat_base/country_data.xml b/intrastat_base/country_data.xml new file mode 100644 index 0000000..04fb439 --- /dev/null +++ b/intrastat_base/country_data.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/intrastat_base/country_view.xml b/intrastat_base/country_view.xml new file mode 100644 index 0000000..bf62fa3 --- /dev/null +++ b/intrastat_base/country_view.xml @@ -0,0 +1,36 @@ + + + + + + + + + + intrastat.base.country.tree + res.country + + + + + + + + + + intrastat.base.country.form + res.country + + + + + + + + + + + diff --git a/intrastat_base/i18n/fr_FR.po b/intrastat_base/i18n/fr_FR.po new file mode 100644 index 0000000..c3a85fe --- /dev/null +++ b/intrastat_base/i18n/fr_FR.po @@ -0,0 +1,176 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * intrastat_base +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 6.0.4\n" +"Report-Msgid-Bugs-To: support@openerp.com\n" +"POT-Creation-Date: 2012-06-05 13:28+0000\n" +"PO-Revision-Date: 2012-06-05 13:28+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: intrastat_base +#: model:ir.ui.menu,name:intrastat_base.menu_intrastat_base_root +msgid "Intrastat reporting" +msgstr "DEB et DES" + +#. module: intrastat_base +#: sql_constraint:res.country:0 +msgid "The code of the country must be unique !" +msgstr "Le code du pays doit être unique !" + +#. module: intrastat_base +#: constraint:product.template:0 +msgid "Error: The default UOM and the purchase UOM must be in the same category." +msgstr "Erreur: l'UdM par défaut et l'UdM d'achat doivent appartenir à la même catégorie." + +#. module: intrastat_base +#: code:addons/intrastat_base/intrastat_common.py:64 +#: code:addons/intrastat_base/intrastat_common.py:70 +#: code:addons/intrastat_base/intrastat_common.py:85 +#: code:addons/intrastat_base/intrastat_common.py:93 +#: code:addons/intrastat_base/product.py:41 +#, python-format +msgid "Error :" +msgstr "Erreur :" + +#. module: intrastat_base +#: model:ir.model,name:intrastat_base.model_account_tax +msgid "account.tax" +msgstr "account.tax" + +#. module: intrastat_base +#: field:account.tax,exclude_from_intrastat_if_present:0 +msgid "Exclude invoice line from intrastat if this tax is present" +msgstr "Exclue la ligne de facture de la DEB/DES si cette taxe est présente" + +#. module: intrastat_base +#: help:res.country,intrastat:0 +msgid "Set as True for countries that must be selected in the intrastat reports, i.e. for all European Union countries other than your own country." +msgstr "Activer cette option pour les pays qui doivent être inclus dans la DEB et la DES, i.e. tous les pays de l'Union Européenne sauf votre propre pays." + +#. module: intrastat_base +#: view:product.product:0 +#: view:product.template:0 +msgid "Intrastat properties" +msgstr "Paramètres pour la DEB et la DES" + +#. module: intrastat_base +#: model:ir.module.module,description:intrastat_base.module_meta_information +msgid "This module contains the common functions for 2 other modules :\n" +"- l10n_fr_intrastat_service : the module for the \"Déclaration Européenne des Services\" (DES)\n" +"- l10n_fr_intrastat_product : the module for the \"Déclaration d'Echange de Biens\" (DEB)\n" +"This module is not usefull if it's not used together with one of those 2 modules.\n" +"\n" +"This module doesn't have any France-specific stuff. So it can be used as a basis for other intrastat modules for other EU countries.\n" +"\n" +"WARNING : this module conflicts with the module \"report_intrastat\" from the addons. If you have already installed the module \"report_intrastat\", you should uninstall it first before installing this module.\n" +"\n" +"Please contact Alexis de Lattre from Akretion for any help or question about this module.\n" +" " +msgstr "This module contains the common functions for 2 other modules :\n" +"- l10n_fr_intrastat_service : the module for the \"Déclaration Européenne des Services\" (DES)\n" +"- l10n_fr_intrastat_product : the module for the \"Déclaration d'Echange de Biens\" (DEB)\n" +"This module is not usefull if it's not used together with one of those 2 modules.\n" +"\n" +"This module doesn't have any France-specific stuff. So it can be used as a basis for other intrastat modules for other EU countries.\n" +"\n" +"WARNING : this module conflicts with the module \"report_intrastat\" from the addons. If you have already installed the module \"report_intrastat\", you should uninstall it first before installing this module.\n" +"\n" +"Please contact Alexis de Lattre from Akretion for any help or question about this module.\n" +" " + +#. module: intrastat_base +#: sql_constraint:res.country:0 +msgid "The name of the country must be unique !" +msgstr "Le nom du pays doit être unique !" + +#. module: intrastat_base +#: constraint:product.template:0 +msgid "Error msg is in raise" +msgstr "Error msg is in raise" + +#. module: intrastat_base +#: help:account.tax,exclude_from_intrastat_if_present:0 +msgid "If this tax is present on an invoice line, this invoice line will be skipped when generating Intrastat Product or Service lines from invoices." +msgstr "Si cette taxe est présente sur une ligne de facture, cette ligne de facture ne sera pas prise en compte lors de la génération de la DEB et de la DES depuis les factures." + +#. module: intrastat_base +#: field:product.template,is_accessory_cost:0 +msgid "Is accessory cost" +msgstr "Frais accessoires" + +#. module: intrastat_base +#: field:res.country,intrastat:0 +msgid "Intrastat country" +msgstr "Pays intrastat" + +#. module: intrastat_base +#: help:product.template,exclude_from_intrastat:0 +msgid "If set to True, the product or service will not be taken into account for Intrastat Product or Service reports. So you should leave this field to False unless you have a very good reason." +msgstr "Si l'option est activée, le produit ou service ne sera pris en compte ni pour la DEB ni pour la DES. Cette option doit donc rester désactivée sauf si vous avez une très bonne raison." + +#. module: intrastat_base +#: code:addons/intrastat_base/intrastat_common.py:64 +#, python-format +msgid "The company currency must be 'EUR', but is currently '%s'." +msgstr "La monnaie de la société doit être 'EUR', mais est actuellement '%s'." + +#. module: intrastat_base +#: code:addons/intrastat_base/intrastat_common.py:70 +#, python-format +msgid "The VAT number is not set for the partner '%s'." +msgstr "Le numéro de TVA n'est pas renseigné pour le partenaire '%s'." + +#. module: intrastat_base +#: model:ir.model,name:intrastat_base.model_report_intrastat_common +msgid "Common functions for intrastat reports for products and services" +msgstr "Common functions for intrastat reports for products and services" + +#. module: intrastat_base +#: model:ir.model,name:intrastat_base.model_res_country +msgid "Country" +msgstr "Pays" + +#. module: intrastat_base +#: model:ir.model,name:intrastat_base.model_product_template +msgid "Product Template" +msgstr "Modèle de produit" + +#. module: intrastat_base +#: model:ir.module.module,shortdesc:intrastat_base.module_meta_information +msgid "Base module for Intrastat reporting" +msgstr "Module de base pour les rapports intrastat" + +#. module: intrastat_base +#: field:product.template,exclude_from_intrastat:0 +msgid "Exclude from Intrastat reports" +msgstr "Exclure de la DEB et de la DES" + +#. module: intrastat_base +#: help:product.template,is_accessory_cost:0 +msgid "Activate this option for shipping costs, packaging costs and all services related to the sale of products. This option is used for Intrastat reports." +msgstr "Activez cette option pour les frais de port, les frais d'emballage et tous les services liés à la vente de produits physiques. Cette option est utilisée pour la DEB et la DES." + +#. module: intrastat_base +#: model:product.template,name:intrastat_base.shipping_costs_exclude_product_template +msgid "Shipping costs" +msgstr "Frais de port" + +#. module: intrastat_base +#: code:addons/intrastat_base/intrastat_common.py:85 +#, python-format +msgid "The generated XML file is not valid against the official XML Schema Definition. The generated XML file and the full error have been written in the server logs. Here is the error, which may give you an idea on the cause of the problem : %s." +msgstr "La validation du fichier XML avec le schéma XML officiel a échoué. Le fichier XML généré et le détail de l'erreur ont été écrits dans les logs du serveur. Voici le message d'erreur, qui peut vous donner une idée de la cause du problème : %s." + +#. module: intrastat_base +#: model:ir.model,name:intrastat_base.model_res_partner_address +msgid "Partner Addresses" +msgstr "Carnet d'adresses" + diff --git a/intrastat_base/i18n/intrastat_base.pot b/intrastat_base/i18n/intrastat_base.pot new file mode 100644 index 0000000..d7baf12 --- /dev/null +++ b/intrastat_base/i18n/intrastat_base.pot @@ -0,0 +1,166 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * intrastat_base +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 6.0.4\n" +"Report-Msgid-Bugs-To: support@openerp.com\n" +"POT-Creation-Date: 2012-06-05 13:28+0000\n" +"PO-Revision-Date: 2012-06-05 13:28+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: intrastat_base +#: model:ir.ui.menu,name:intrastat_base.menu_intrastat_base_root +msgid "Intrastat reporting" +msgstr "" + +#. module: intrastat_base +#: sql_constraint:res.country:0 +msgid "The code of the country must be unique !" +msgstr "" + +#. module: intrastat_base +#: constraint:product.template:0 +msgid "Error: The default UOM and the purchase UOM must be in the same category." +msgstr "" + +#. module: intrastat_base +#: code:addons/intrastat_base/intrastat_common.py:64 +#: code:addons/intrastat_base/intrastat_common.py:70 +#: code:addons/intrastat_base/intrastat_common.py:85 +#: code:addons/intrastat_base/intrastat_common.py:93 +#: code:addons/intrastat_base/product.py:41 +#, python-format +msgid "Error :" +msgstr "" + +#. module: intrastat_base +#: model:ir.model,name:intrastat_base.model_account_tax +msgid "account.tax" +msgstr "" + +#. module: intrastat_base +#: field:account.tax,exclude_from_intrastat_if_present:0 +msgid "Exclude invoice line from intrastat if this tax is present" +msgstr "" + +#. module: intrastat_base +#: help:res.country,intrastat:0 +msgid "Set as True for countries that must be selected in the intrastat reports, i.e. for all European Union countries other than your own country." +msgstr "" + +#. module: intrastat_base +#: view:product.product:0 +#: view:product.template:0 +msgid "Intrastat properties" +msgstr "" + +#. module: intrastat_base +#: model:ir.module.module,description:intrastat_base.module_meta_information +msgid "This module contains the common functions for 2 other modules :\n" +"- l10n_fr_intrastat_service : the module for the \"Déclaration Européenne des Services\" (DES)\n" +"- l10n_fr_intrastat_product : the module for the \"Déclaration d'Echange de Biens\" (DEB)\n" +"This module is not usefull if it's not used together with one of those 2 modules.\n" +"\n" +"This module doesn't have any France-specific stuff. So it can be used as a basis for other intrastat modules for other EU countries.\n" +"\n" +"WARNING : this module conflicts with the module \"report_intrastat\" from the addons. If you have already installed the module \"report_intrastat\", you should uninstall it first before installing this module.\n" +"\n" +"Please contact Alexis de Lattre from Akretion for any help or question about this module.\n" +" " +msgstr "" + +#. module: intrastat_base +#: sql_constraint:res.country:0 +msgid "The name of the country must be unique !" +msgstr "" + +#. module: intrastat_base +#: constraint:product.template:0 +msgid "Error msg is in raise" +msgstr "" + +#. module: intrastat_base +#: help:account.tax,exclude_from_intrastat_if_present:0 +msgid "If this tax is present on an invoice line, this invoice line will be skipped when generating Intrastat Product or Service lines from invoices." +msgstr "" + +#. module: intrastat_base +#: field:product.template,is_accessory_cost:0 +msgid "Is accessory cost" +msgstr "" + +#. module: intrastat_base +#: field:res.country,intrastat:0 +msgid "Intrastat country" +msgstr "" + +#. module: intrastat_base +#: help:product.template,exclude_from_intrastat:0 +msgid "If set to True, the product or service will not be taken into account for Intrastat Product or Service reports. So you should leave this field to False unless you have a very good reason." +msgstr "" + +#. module: intrastat_base +#: code:addons/intrastat_base/intrastat_common.py:64 +#, python-format +msgid "The company currency must be 'EUR', but is currently '%s'." +msgstr "" + +#. module: intrastat_base +#: code:addons/intrastat_base/intrastat_common.py:70 +#, python-format +msgid "The VAT number is not set for the partner '%s'." +msgstr "" + +#. module: intrastat_base +#: model:ir.model,name:intrastat_base.model_report_intrastat_common +msgid "Common functions for intrastat reports for products and services" +msgstr "" + +#. module: intrastat_base +#: model:ir.model,name:intrastat_base.model_res_country +msgid "Country" +msgstr "" + +#. module: intrastat_base +#: model:ir.model,name:intrastat_base.model_product_template +msgid "Product Template" +msgstr "" + +#. module: intrastat_base +#: model:ir.module.module,shortdesc:intrastat_base.module_meta_information +msgid "Base module for Intrastat reporting" +msgstr "" + +#. module: intrastat_base +#: field:product.template,exclude_from_intrastat:0 +msgid "Exclude from Intrastat reports" +msgstr "" + +#. module: intrastat_base +#: help:product.template,is_accessory_cost:0 +msgid "Activate this option for shipping costs, packaging costs and all services related to the sale of products. This option is used for Intrastat reports." +msgstr "" + +#. module: intrastat_base +#: model:product.template,name:intrastat_base.shipping_costs_exclude_product_template +msgid "Shipping costs" +msgstr "" + +#. module: intrastat_base +#: code:addons/intrastat_base/intrastat_common.py:85 +#, python-format +msgid "The generated XML file is not valid against the official XML Schema Definition. The generated XML file and the full error have been written in the server logs. Here is the error, which may give you an idea on the cause of the problem : %s." +msgstr "" + +#. module: intrastat_base +#: model:ir.model,name:intrastat_base.model_res_partner_address +msgid "Partner Addresses" +msgstr "" + diff --git a/intrastat_base/intrastat_common.py b/intrastat_base/intrastat_common.py new file mode 100644 index 0000000..8320b8a --- /dev/null +++ b/intrastat_base/intrastat_common.py @@ -0,0 +1,132 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Report intrastat base module for OpenERP +# Copyright (C) 2010-2011 Akretion (http://www.akretion.com/). All rights reserved. +# @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 . +# +############################################################################## + +from osv import osv, fields +from datetime import datetime +from dateutil.relativedelta import relativedelta +from tools.translate import _ + +class report_intrastat_common(osv.osv_memory): + _name = "report.intrastat.common" + _description = "Common functions for intrastat reports for products and services" + + def _compute_numbers(self, cr, uid, ids, object, context=None): + result = {} + for intrastat in object.browse(cr, uid, ids, context=context): + total_amount = 0.0 + num_lines = 0 + for line in intrastat.intrastat_line_ids: + total_amount += line.amount_company_currency + num_lines += 1 + result[intrastat.id] = {'num_lines': num_lines, 'total_amount': total_amount} + return result + + + def _compute_end_date(self, cr, uid, ids, object, context=None): + result = {} + for intrastat in object.browse(cr, uid, ids, context=context): + start_date_datetime = datetime.strptime(intrastat.start_date, '%Y-%m-%d') + end_date_str = datetime.strftime(start_date_datetime + relativedelta(day=31), '%Y-%m-%d') + result[intrastat.id] = end_date_str + return result + + + def _check_start_date(self, cr, uid, ids, object, context=None): + '''Check that the start date is the first day of the month''' + for date_to_check in object.read(cr, uid, ids, ['start_date'], context=context): + datetime_to_check = datetime.strptime(date_to_check['start_date'], '%Y-%m-%d') + if datetime_to_check.day != 1: + return False + return True + + + def _check_generate_lines(self, cr, uid, intrastat, context=None): + if not intrastat.company_id.country_id: + raise osv.except_osv(_('Error :'), _("The country is not set on the company '%s'.") %intrastat.company_id.name) + if not intrastat.currency_id.name == 'EUR': + raise osv.except_osv(_('Error :'), _("The company currency must be 'EUR', but is currently '%s'.") %intrastat.currency_id.name) + return True + + + def _check_generate_xml(self, cr, uid, intrastat, context=None): + if not intrastat.company_id.partner_id.vat: + raise osv.except_osv(_('Error :'), _("The VAT number is not set for the partner '%s'.") %intrastat.company_id.partner_id.name) + return True + + + def _check_xml_schema(self, cr, uid, xml_root, xml_string, xsd, context=None): + '''Validate the XML file against the XSD''' + from lxml import etree + official_des_xml_schema = etree.XMLSchema(etree.fromstring(xsd)) + try: official_des_xml_schema.assertValid(xml_root) + except Exception, e: # if the validation of the XSD fails, we arrive here + import logging + _logger = logging.getLogger(__name__) + _logger.warning("The XML file is invalid against the XML Schema Definition") + _logger.warning(xml_string) + _logger.warning(e) + raise osv.except_osv(_('Error :'), _('The generated XML file is not valid against the official XML Schema Definition. The generated XML file and the full error have been written in the server logs. Here is the error, which may give you an idea on the cause of the problem : %s.') % str(e)) + return True + + + def _attach_xml_file(self, cr, uid, ids, object, xml_string, start_date_datetime, declaration_name, context=None): + '''Attach the XML file to the report_intrastat_product/service object''' + import base64 + if len(ids) != 1: + raise osv.except_osv(_('Error :'), 'Hara kiri in attach_xml_file') + filename = datetime.strftime(start_date_datetime, '%Y-%m') + '_' + declaration_name + '.xml' + attach_name = declaration_name.upper() + ' ' + datetime.strftime(start_date_datetime, '%Y-%m') + attach_obj = self.pool.get('ir.attachment') + if not context: + context = {} + context.update({'default_res_id' : ids[0], 'default_res_model': object._name}) + attach_id = attach_obj.create(cr, uid, {'name': attach_name, 'datas': base64.encodestring(xml_string), 'datas_fname': filename}, context=context) + return attach_id + + + def _open_attach_view(self, cr, uid, attach_id, title='XML file', context=None): + '''Returns an action which opens the form view of the corresponding attachement''' + # Only works in v6 -> not used in v5 + action = { + 'name': title, + 'view_type': 'form', + 'view_mode': 'form,tree', + 'view_id': False, + 'res_model': 'ir.attachment', + 'type': 'ir.actions.act_window', + 'nodestroy': True, + 'target': 'current', + 'res_id': [attach_id], + } + return action + + + def partner_on_change(self, cr, uid, ids, partner_id=False): + result = {} + result['value'] = {} + if partner_id: + company = self.pool.get('res.partner').read(cr, uid, partner_id, ['vat']) + result['value'].update({'partner_vat': company['vat']}) + return result + +report_intrastat_common() + diff --git a/intrastat_base/intrastat_demo.xml b/intrastat_base/intrastat_demo.xml new file mode 100644 index 0000000..d83640e --- /dev/null +++ b/intrastat_base/intrastat_demo.xml @@ -0,0 +1,57 @@ + + + + + + + + + FR58441019213 + + + + BE0828696437 + True + + + + BE0443167858 + True + + + + BE0884025633 + True + + + + True + + + + True + + + + True + + + + True + + + + Shipping costs + SHIP + service + + 30 + True + + + + diff --git a/intrastat_base/intrastat_menu.xml b/intrastat_base/intrastat_menu.xml new file mode 100644 index 0000000..b078c6a --- /dev/null +++ b/intrastat_base/intrastat_menu.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + diff --git a/intrastat_base/partner_address.py b/intrastat_base/partner_address.py new file mode 100644 index 0000000..f36329b --- /dev/null +++ b/intrastat_base/partner_address.py @@ -0,0 +1,35 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Report intrastat base module for OpenERP +# Copyright (C) 2010-2011 Akretion (http://www.akretion.com/) All Rights Reserved +# @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 . +# +############################################################################## + +from osv import osv, fields + +# We want to have the country field on res_partner_address always set +# because the selection of invoices for intrastat reports is based +# on the country of the invoice partner address ! +class res_partner_address(osv.osv): + _inherit = 'res.partner.address' + _columns = { + 'country_id': fields.many2one('res.country', 'Country', required=True), + } + +res_partner_address() + diff --git a/intrastat_base/product.py b/intrastat_base/product.py new file mode 100644 index 0000000..c535a72 --- /dev/null +++ b/intrastat_base/product.py @@ -0,0 +1,49 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Report intrastat base module for OpenERP +# Copyright (C) 2010-2012 Akretion (http://www.akretion.com/) All Rights Reserved +# @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 . +# +############################################################################## + +from osv import osv, fields +from tools.translate import _ + +class product_template(osv.osv): + _inherit = "product.template" + _columns = { + 'exclude_from_intrastat': fields.boolean('Exclude from Intrastat reports', help="If set to True, the product or service will not be taken into account for Intrastat Product or Service reports. So you should leave this field to False unless you have a very good reason."), + 'is_accessory_cost' : fields.boolean('Is accessory cost', help='Activate this option for shipping costs, packaging costs and all services related to the sale of products. This option is used for Intrastat reports.'), + } + + _defaults = { + 'exclude_from_intrastat': False, + } + + + def _check_accessory_cost(self, cr, uid, ids): + for product in self.browse(cr, uid, ids): + if product.is_accessory_cost and product.type != 'service': + raise osv.except_osv(_('Error :'), _("The option 'Is accessory cost?' should only be activated on 'Service' products. You have activated this option for the product '%s' which is of type '%s'" % (product.name, product.type))) + return True + + _constraints = [ + (_check_accessory_cost, "Error msg is in raise", ['is_accessory_cost', 'type']) + ] + +product_template() + diff --git a/intrastat_base/product_view.xml b/intrastat_base/product_view.xml new file mode 100644 index 0000000..28b026e --- /dev/null +++ b/intrastat_base/product_view.xml @@ -0,0 +1,53 @@ + + + + + + + + + + intrastat.base.product.normal.form + product.product + + + + + + + + + + + + + + + + + + + intrastat.base.product.template.form + product.template + + + + + + + + + + + + + + + + + + diff --git a/intrastat_base/security/ir.model.access.csv b/intrastat_base/security/ir.model.access.csv new file mode 100644 index 0000000..d7a2bf1 --- /dev/null +++ b/intrastat_base/security/ir.model.access.csv @@ -0,0 +1,2 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" +"access_report_intrastat_common","Read access on report.intrastat.common","model_report_intrastat_common","base.group_user",1,0,0,0 diff --git a/intrastat_base/tax.py b/intrastat_base/tax.py new file mode 100644 index 0000000..4d12d32 --- /dev/null +++ b/intrastat_base/tax.py @@ -0,0 +1,33 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Report intrastat base module for OpenERP +# Copyright (C) 2011 Akretion (http://www.akretion.com). All Rights Reserved +# @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 . +# +############################################################################## + +from osv import osv, fields + + +class account_tax(osv.osv): + _inherit = "account.tax" + _columns = { + 'exclude_from_intrastat_if_present': fields.boolean('Exclude invoice line from intrastat if this tax is present', help="If this tax is present on an invoice line, this invoice line will be skipped when generating Intrastat Product or Service lines from invoices."), + } + +account_tax() + diff --git a/intrastat_base/tax_view.xml b/intrastat_base/tax_view.xml new file mode 100644 index 0000000..e60a327 --- /dev/null +++ b/intrastat_base/tax_view.xml @@ -0,0 +1,28 @@ + + + + + + + + + + intrastat.base.tax + account.tax + form + + + + + + + + + + + +