diff --git a/intrastat_base/README.rst b/intrastat_base/README.rst new file mode 100644 index 0000000..a941d1d --- /dev/null +++ b/intrastat_base/README.rst @@ -0,0 +1,44 @@ +Intrastat Base Module +===================== + +This module contains common functions for the Intrastat reporting and +should be used in combination with country-specific reporting modules +such as: + +- *l10n_fr_intrastat_service*: + the module for the *Déclaration Européenne des Services* (DES) for France +- *l10n_fr_intrastat_product*: + the module for the *Déclaration d'Echange de Biens* (DEB) for France +- *l10n_be_intrastat_product*: + the module for the Intrastat Declaration for Belgium. + +These country-specific modules can be found in the OCA localization for those countries. + +Installation +============ + +WARNING: +This module conflicts with the module *report_intrastat* from the official addons. +If you have already installed the module *report_intrastat*, +you should uninstall it first before installing this module. + +Credits +======= + +Contributors +------------ + +* Alexis de Lattre, Akretion + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/intrastat_base/__openerp__.py b/intrastat_base/__openerp__.py index e795155..ea5483f 100644 --- a/intrastat_base/__openerp__.py +++ b/intrastat_base/__openerp__.py @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- ############################################################################## # -# Report intrastat base module for Odoo +# Intrastat base module for Odoo # Copyright (C) 2011-2015 Akretion (http://www.akretion.com) # @author Alexis de Lattre # @@ -23,23 +23,13 @@ { 'name': 'Intrastat Reporting Base', 'version': '1.1', - 'category': 'Localisation/Report Intrastat', + 'category': 'Intrastat', 'license': 'AGPL-3', 'summary': 'Base module for Intrastat reporting', - '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 or other country-specific intrastat 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', + 'author': 'Akretion,Odoo Community Association (OCA)', 'website': 'http://www.akretion.com', 'depends': ['base_vat'], + 'conflicts': ['report_intrastat'], 'data': [ 'country_data.xml', 'product_view.xml', @@ -47,7 +37,7 @@ Please contact Alexis de Lattre from Akretion for 'country_view.xml', 'tax_view.xml', 'company_view.xml', - 'intrastat_menu.xml', + 'intrastat_view.xml', ], 'demo': ['intrastat_demo.xml'], 'installable': True, diff --git a/intrastat_base/company_view.xml b/intrastat_base/company_view.xml index 87933f4..1df7aed 100644 --- a/intrastat_base/company_view.xml +++ b/intrastat_base/company_view.xml @@ -16,7 +16,7 @@ - + diff --git a/intrastat_base/country.py b/intrastat_base/country.py index 7f03e5d..7a34e77 100644 --- a/intrastat_base/country.py +++ b/intrastat_base/country.py @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- ############################################################################## # -# Report intrastat base module for Odoo +# Intrastat base module for Odoo # Copyright (C) 2011-2014 Akretion (http://www.akretion.com). # @author Alexis de Lattre # diff --git a/intrastat_base/i18n/fr_FR.po b/intrastat_base/i18n/fr_FR.po index de7e5db..1b3d759 100644 --- a/intrastat_base/i18n/fr_FR.po +++ b/intrastat_base/i18n/fr_FR.po @@ -1,14 +1,14 @@ -# Translation of OpenERP Server. +# Translation of Odoo Server. # This file contains the translation of the following modules: # * intrastat_base # msgid "" msgstr "" -"Project-Id-Version: OpenERP Server 7.0\n" +"Project-Id-Version: Odoo Server 8.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-04-14 14:18+0000\n" -"PO-Revision-Date: 2014-04-14 14:18+0000\n" -"Last-Translator: Alexis de Lattre \n" +"POT-Creation-Date: 2015-05-27 18:43+0000\n" +"PO-Revision-Date: 2015-05-27 18:43+0000\n" +"Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -21,47 +21,43 @@ msgid "Activate this option for shipping costs, packaging costs and all services 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 -#: view:res.company:0 +#: code:addons/intrastat_base/intrastat_common.py:165 +#, python-format +msgid "Cannot delete the declaration %s because it is in Done state" +msgstr "Impossible de supprimer la déclaration %s car elle est à l'état déclaré" + +#. module: intrastat_base +#: view:res.company:intrastat_base.view_company_form msgid "Common Intrastat Settings" msgstr "Paramètres communs DEB et DES" #. module: intrastat_base #: model:ir.model,name:intrastat_base.model_report_intrastat_common -msgid "Common functions for intrastat reports for products and services" -msgstr "Fonctions communes pour la DEB et la DES" +msgid "Common functions for intrastat reports for products " +msgstr "" #. module: intrastat_base #: model:ir.model,name:intrastat_base.model_res_company msgid "Companies" msgstr "Sociétés" +#. module: intrastat_base +#: code:addons/intrastat_base/intrastat_common.py:68 +#, python-format +msgid "Company not yet set on intrastat report." +msgstr "Société non configurée sur le rapport intrastat." + #. module: intrastat_base #: model:ir.model,name:intrastat_base.model_res_country msgid "Country" msgstr "Pays" #. module: intrastat_base -#: view:res.country:0 +#: view:res.country:intrastat_base.view_country_search #: field:res.country,intrastat:0 msgid "EU Country" msgstr "Pays UE" -#. module: intrastat_base -#: code:addons/intrastat_base/company.py:58 -#: code:addons/intrastat_base/intrastat_common.py:77 -#: code:addons/intrastat_base/intrastat_common.py:82 -#: code:addons/intrastat_base/intrastat_common.py:90 -#: code:addons/intrastat_base/intrastat_common.py:110 -#: code:addons/intrastat_base/product.py:51 -#, python-format -msgid "Error :" -msgstr "Erreur :" - -#. module: intrastat_base -#: constraint:product.template:0 -msgid "Error msg is in raise" -msgstr "Error msg is in raise" - #. module: intrastat_base #: field:product.template,exclude_from_intrastat:0 msgid "Exclude from Intrastat reports" @@ -72,6 +68,11 @@ msgstr "Exclure de la DEB et de la DES" 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 +#: field:report.intrastat.common,id:0 +msgid "ID" +msgstr "ID" + #. 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." @@ -83,21 +84,20 @@ msgid "If this tax is present on an invoice line, this invoice line will be skip 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 -#: view:product.product:0 -#: view:product.template:0 +#: view:product.template:intrastat_base.product_template_form_view msgid "Intrastat Properties" msgstr "Propriétés DEB/DES" -#. module: intrastat_base -#: view:res.company:0 -msgid "Intrastat Settings" -msgstr "Configuration DEB/DES" - #. module: intrastat_base #: model:ir.ui.menu,name:intrastat_base.menu_intrastat_base_root msgid "Intrastat Reporting" msgstr "DEB et DES" +#. module: intrastat_base +#: view:res.company:intrastat_base.view_company_form +msgid "Intrastat Settings" +msgstr "Configuration DEB/DES" + #. module: intrastat_base #: field:product.template,is_accessory_cost:0 msgid "Is accessory cost" @@ -109,28 +109,18 @@ msgid "List of OpenERP users who will receive a notification to remind them abou msgstr "Liste d'utilisateurs OpenERP qui recevront le rappel pour la DEB et/ou la DES." #. module: intrastat_base -#: field:res.company,intrastat_email_list:0 -msgid "List of emails of Users Receiving the Intrastat Reminder" -msgstr "Liste des emails d'utilisateurs qui recevront le rappel pour la DEB et/ou la DES" - -#. module: intrastat_base -#: code:addons/intrastat_base/company.py:59 +#: code:addons/intrastat_base/company.py:55 #, python-format msgid "Missing e-mail address on user '%s'." msgstr "Adresse e-mail manquante sur l'utilisateur '%s'." -#. module: intrastat_base -#: model:ir.model,name:intrastat_base.model_res_partner -msgid "Partner" -msgstr "Partenaire" - #. module: intrastat_base #: model:ir.model,name:intrastat_base.model_product_template msgid "Product Template" msgstr "Modèle d'article" #. module: intrastat_base -#: view:res.country:0 +#: view:res.country:intrastat_base.view_country_search msgid "Search Countries" msgstr "Recherche des pays" @@ -150,42 +140,43 @@ msgid "Tax" msgstr "Taxes" #. module: intrastat_base -#: code:addons/intrastat_base/intrastat_common.py:91 +#: code:addons/intrastat_base/intrastat_common.py:84 #, 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 -#: code:addons/intrastat_base/intrastat_common.py:83 +#: code:addons/intrastat_base/intrastat_common.py:76 #, 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:78 +#: code:addons/intrastat_base/intrastat_common.py:72 #, python-format msgid "The country is not set on the company '%s'." msgstr "Le pays n'est pas renseigné sur la société '%s'." #. module: intrastat_base -#: code:addons/intrastat_base/intrastat_common.py:111 +#: code:addons/intrastat_base/intrastat_common.py:105 #, 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 -#: code:addons/intrastat_base/product.py:56 +#: code:addons/intrastat_base/product.py:51 #, python-format msgid "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'" msgstr "L'option 'Frais accessoires' ne doit être activée que sur les produits de type 'Service'. Vous avez activé cette option sur le produit '%s' qui est de type '%s'" +#. module: intrastat_base +#: code:addons/intrastat_base/intrastat_common.py:62 +#, python-format +msgid "The start date must be the first day of the month" +msgstr "La date de début doit être le premier jour du mois" + #. module: intrastat_base #: field:res.company,intrastat_remind_user_ids:0 msgid "Users Receiving the Intrastat Reminder" msgstr "Utilisateurs qui reçoivent le rappel DEB/DES" -#. module: intrastat_base -#: constraint:res.company:0 -msgid "error msg in raise" -msgstr "error msg in raise" - diff --git a/intrastat_base/i18n/intrastat_base.pot b/intrastat_base/i18n/intrastat_base.pot index d184def..fdc6996 100644 --- a/intrastat_base/i18n/intrastat_base.pot +++ b/intrastat_base/i18n/intrastat_base.pot @@ -1,13 +1,13 @@ -# Translation of OpenERP Server. +# Translation of Odoo Server. # This file contains the translation of the following modules: # * intrastat_base # msgid "" msgstr "" -"Project-Id-Version: OpenERP Server 7.0\n" +"Project-Id-Version: Odoo Server 8.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-04-14 14:18+0000\n" -"PO-Revision-Date: 2014-04-14 14:18+0000\n" +"POT-Creation-Date: 2015-05-27 18:43+0000\n" +"PO-Revision-Date: 2015-05-27 18:43+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -21,13 +21,19 @@ msgid "Activate this option for shipping costs, packaging costs and all services msgstr "" #. module: intrastat_base -#: view:res.company:0 +#: code:addons/intrastat_base/intrastat_common.py:165 +#, python-format +msgid "Cannot delete the declaration %s because it is in Done state" +msgstr "" + +#. module: intrastat_base +#: view:res.company:intrastat_base.view_company_form msgid "Common Intrastat Settings" msgstr "" #. module: intrastat_base #: model:ir.model,name:intrastat_base.model_report_intrastat_common -msgid "Common functions for intrastat reports for products and services" +msgid "Common functions for intrastat reports for products " msgstr "" #. module: intrastat_base @@ -35,33 +41,23 @@ msgstr "" msgid "Companies" msgstr "" +#. module: intrastat_base +#: code:addons/intrastat_base/intrastat_common.py:68 +#, python-format +msgid "Company not yet set on intrastat report." +msgstr "" + #. module: intrastat_base #: model:ir.model,name:intrastat_base.model_res_country msgid "Country" msgstr "" #. module: intrastat_base -#: view:res.country:0 +#: view:res.country:intrastat_base.view_country_search #: field:res.country,intrastat:0 msgid "EU Country" msgstr "" -#. module: intrastat_base -#: code:addons/intrastat_base/company.py:58 -#: code:addons/intrastat_base/intrastat_common.py:77 -#: code:addons/intrastat_base/intrastat_common.py:82 -#: code:addons/intrastat_base/intrastat_common.py:90 -#: code:addons/intrastat_base/intrastat_common.py:110 -#: code:addons/intrastat_base/product.py:51 -#, python-format -msgid "Error :" -msgstr "" - -#. module: intrastat_base -#: constraint:product.template:0 -msgid "Error msg is in raise" -msgstr "" - #. module: intrastat_base #: field:product.template,exclude_from_intrastat:0 msgid "Exclude from Intrastat reports" @@ -72,6 +68,11 @@ msgstr "" msgid "Exclude invoice line from intrastat if this tax is present" msgstr "" +#. module: intrastat_base +#: field:report.intrastat.common,id:0 +msgid "ID" +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." @@ -83,21 +84,20 @@ msgid "If this tax is present on an invoice line, this invoice line will be skip msgstr "" #. module: intrastat_base -#: view:product.product:0 -#: view:product.template:0 +#: view:product.template:intrastat_base.product_template_form_view msgid "Intrastat Properties" msgstr "" -#. module: intrastat_base -#: view:res.company:0 -msgid "Intrastat Settings" -msgstr "" - #. module: intrastat_base #: model:ir.ui.menu,name:intrastat_base.menu_intrastat_base_root msgid "Intrastat Reporting" msgstr "" +#. module: intrastat_base +#: view:res.company:intrastat_base.view_company_form +msgid "Intrastat Settings" +msgstr "" + #. module: intrastat_base #: field:product.template,is_accessory_cost:0 msgid "Is accessory cost" @@ -109,28 +109,18 @@ msgid "List of OpenERP users who will receive a notification to remind them abou msgstr "" #. module: intrastat_base -#: field:res.company,intrastat_email_list:0 -msgid "List of emails of Users Receiving the Intrastat Reminder" -msgstr "" - -#. module: intrastat_base -#: code:addons/intrastat_base/company.py:59 +#: code:addons/intrastat_base/company.py:55 #, python-format msgid "Missing e-mail address on user '%s'." msgstr "" -#. module: intrastat_base -#: model:ir.model,name:intrastat_base.model_res_partner -msgid "Partner" -msgstr "" - #. module: intrastat_base #: model:ir.model,name:intrastat_base.model_product_template msgid "Product Template" msgstr "" #. module: intrastat_base -#: view:res.country:0 +#: view:res.country:intrastat_base.view_country_search msgid "Search Countries" msgstr "" @@ -150,42 +140,43 @@ msgid "Tax" msgstr "" #. module: intrastat_base -#: code:addons/intrastat_base/intrastat_common.py:91 +#: code:addons/intrastat_base/intrastat_common.py:84 #, python-format msgid "The VAT number is not set for the partner '%s'." msgstr "" #. module: intrastat_base -#: code:addons/intrastat_base/intrastat_common.py:83 +#: code:addons/intrastat_base/intrastat_common.py:76 #, python-format msgid "The company currency must be 'EUR', but is currently '%s'." msgstr "" #. module: intrastat_base -#: code:addons/intrastat_base/intrastat_common.py:78 +#: code:addons/intrastat_base/intrastat_common.py:72 #, python-format msgid "The country is not set on the company '%s'." msgstr "" #. module: intrastat_base -#: code:addons/intrastat_base/intrastat_common.py:111 +#: code:addons/intrastat_base/intrastat_common.py:105 #, 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 -#: code:addons/intrastat_base/product.py:56 +#: code:addons/intrastat_base/product.py:51 #, python-format msgid "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'" msgstr "" +#. module: intrastat_base +#: code:addons/intrastat_base/intrastat_common.py:62 +#, python-format +msgid "The start date must be the first day of the month" +msgstr "" + #. module: intrastat_base #: field:res.company,intrastat_remind_user_ids:0 msgid "Users Receiving the Intrastat Reminder" msgstr "" -#. module: intrastat_base -#: constraint:res.company:0 -msgid "error msg in raise" -msgstr "" - diff --git a/intrastat_base/intrastat_common.py b/intrastat_base/intrastat_common.py index 3db1764..a18ea07 100644 --- a/intrastat_base/intrastat_common.py +++ b/intrastat_base/intrastat_common.py @@ -1,8 +1,8 @@ # -*- encoding: utf-8 -*- ############################################################################## # -# Report intrastat base module for OpenERP -# Copyright (C) 2010-2013 Akretion (http://www.akretion.com/). +# Intrastat base module for Odoo +# Copyright (C) 2010-2014 Akretion (http://www.akretion.com/). # @author Alexis de Lattre # # This program is free software: you can redistribute it and/or modify @@ -20,91 +20,72 @@ # ############################################################################## -from openerp.osv import orm -from openerp.tools.translate import _ -from openerp import tools -from datetime import datetime +from openerp import models, fields, api, tools, _ +from openerp.exceptions import Warning, ValidationError from dateutil.relativedelta import relativedelta import logging logger = logging.getLogger(__name__) -class report_intrastat_common(orm.TransientModel): - _name = "report.intrastat.common" +class IntrastatCommon(models.AbstractModel): + _name = "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 + @api.one + @api.depends('declaration_line_ids.amount_company_currency') + def _compute_numbers(self): + total_amount = 0.0 + num_lines = 0 + for line in self.declaration_line_ids: + total_amount += line.amount_company_currency + num_lines += 1 + self.num_decl_lines = num_lines + self.total_amount = total_amount - def _compute_dates(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': end_date_str, - 'year_month': start_date_datetime.strftime('%Y-%m'), - } - return result + @api.one + @api.depends('start_date') + def _compute_dates(self): + start_date_dt = fields.Date.from_string(self.start_date) + self.end_date = fields.Date.to_string( + start_date_dt + relativedelta(day=31)) + self.year_month = start_date_dt.strftime('%Y-%m') - def _check_start_date(self, cr, uid, ids, object, context=None): + @api.one + def _check_start_date(self): '''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 + datetime_to_check = fields.Date.from_string(self.start_date) + if datetime_to_check.day != 1: + raise ValidationError( + _('The start date must be the first day of the month')) - def _check_generate_lines(self, cr, uid, intrastat, context=None): + @api.one + def _check_generate_lines(self): """Check wether all requirements are met for generating lines.""" - if not intrastat.company_id: - # Should not be possible, but just in case: - raise orm.except_orm( - _('Error :'), - _("Company not yet set on intrastat report.") - ) - company_obj = intrastat.company_id # Simplify references + if not self.company_id: + raise Warning(_("Company not yet set on intrastat report.")) + company_obj = self.company_id if not company_obj.country_id: - raise orm.except_orm( - _('Error :'), + raise Warning( _("The country is not set on the company '%s'.") - % company_obj.name - ) - if not company_obj.currency_id.name == 'EUR': - raise orm.except_orm( - _('Error :'), + % company_obj.name) + if company_obj.currency_id.name != 'EUR': + raise Warning( _("The company currency must be 'EUR', but is currently '%s'.") - % company_obj.currency_id.name - ) + % company_obj.currency_id.name) return True - def _check_generate_xml(self, cr, uid, intrastat, context=None): - if not intrastat.company_id.partner_id.vat: - raise orm.except_orm( - _('Error :'), + @api.one + def _check_generate_xml(self): + if not self.company_id.partner_id.vat: + raise Warning( _("The VAT number is not set for the partner '%s'.") - % intrastat.company_id.partner_id.name) + % self.company_id.partner_id.name) return True - def _check_xml_schema( - self, cr, uid, xml_root, xml_string, xsd_file, context=None): + @api.model + def _check_xml_schema(self, xml_root, xml_string, xsd_file): '''Validate the XML file against the XSD''' from lxml import etree xsd_etree_obj = etree.parse( @@ -114,13 +95,12 @@ class report_intrastat_common(orm.TransientModel): official_schema.assertValid(xml_root) except Exception, e: # if the validation of the XSD fails, we arrive here - _logger = logging.getLogger(__name__) - _logger.warning( + logger = logging.getLogger(__name__) + logger.warning( "The XML file is invalid against the XML Schema Definition") - _logger.warning(xml_string) - _logger.warning(e) - raise orm.except_orm( - _('Error :'), + logger.warning(xml_string) + logger.warning(e) + raise Warning( _("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. " @@ -129,39 +109,29 @@ class report_intrastat_common(orm.TransientModel): % 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''' + @api.multi + def _attach_xml_file(self, xml_string, declaration_name): + '''Attach the XML file to the report_intrastat_product/service + object''' + self.ensure_one() import base64 - assert len(ids) == 1, "Only one ID accepted" - filename = '%s_%s.xml' % ( - datetime.strftime(start_date_datetime, '%Y-%m'), - declaration_name) - if not context: - context = {} - context.update({ - 'default_res_id': ids[0], - 'default_res_model': object._name - }) - attach_id = self.pool['ir.attachment'].create( - cr, uid, { - 'name': filename, - 'datas': base64.encodestring(xml_string), - 'datas_fname': filename}, - context=context) - return attach_id + filename = '%s_%s.xml' % (self.year_month, declaration_name) + attach = self.env['ir.attachment'].create({ + 'name': filename, + 'res_id': self.id, + 'res_model': self._name, + 'datas': base64.encodestring(xml_string), + 'datas_fname': filename}) + 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''' + @api.model + def _open_attach_view(self, attach_id, title='XML file'): + '''Returns an action which opens the form view of the + corresponding attachement''' action = { 'name': title, 'view_type': 'form', - 'view_mode': 'form,tree', - 'view_id': False, + 'view_mode': 'form', 'res_model': 'ir.attachment', 'type': 'ir.actions.act_window', 'nodestroy': True, @@ -170,30 +140,36 @@ class report_intrastat_common(orm.TransientModel): } return action - def partner_on_change(self, cr, uid, ids, partner_id=False, context=None): - result = {} - result['value'] = {} - if partner_id: - company = self.pool['res.partner'].read( - cr, uid, partner_id, ['vat'], context=context) - result['value']['partner_vat'] = company['vat'] - return result - - def send_reminder_email( - self, cr, uid, company, module_name, template_xmlid, - intrastat_id, context=None): - template_model, template_id =\ - self.pool['ir.model.data'].get_object_reference( - cr, uid, module_name, template_xmlid) - assert template_model == 'email.template', 'Wrong model' - if company.intrastat_remind_user_ids: - self.pool['email.template'].send_mail( - cr, uid, template_id, intrastat_id, context=context) + @api.one + def send_reminder_email(self, mail_template_xmlid): + mail_template = self.env.ref(mail_template_xmlid) + if self.company_id.intrastat_remind_user_ids: + mail_template.send_mail(self.id) logger.info( 'Intrastat Reminder email has been sent (XMLID: %s).' - % template_xmlid) + % mail_template_xmlid) else: logger.warning( 'The list of users receiving the Intrastat Reminder is empty ' - 'on company %s' % company.name) + 'on company %s' % self.company_id.name) return True + + @api.multi + def unlink(self): + for intrastat in self: + if intrastat.state == 'done': + raise Warning( + _('Cannot delete the declaration %s ' + 'because it is in Done state') % self.year_month) + return super(IntrastatCommon, self).unlink() + + +class IntrastatResultView(models.TransientModel): + """ + Transient Model to display Intrastat Report results + """ + _name = 'intrastat.result.view' + + note = fields.Text( + string='Notes', readonly=True, + default=lambda self: self._context.get('note')) diff --git a/intrastat_base/intrastat_menu.xml b/intrastat_base/intrastat_menu.xml deleted file mode 100644 index 85303c1..0000000 --- a/intrastat_base/intrastat_menu.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - diff --git a/intrastat_base/intrastat_view.xml b/intrastat_base/intrastat_view.xml new file mode 100644 index 0000000..4d9c22a --- /dev/null +++ b/intrastat_base/intrastat_view.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + intrastat.result_view_form + intrastat.result.view + +
+ + + +
+
+
+
+
+ +
+
diff --git a/intrastat_base/product.py b/intrastat_base/product.py index ca1652e..5373cb3 100644 --- a/intrastat_base/product.py +++ b/intrastat_base/product.py @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- ############################################################################## # -# Report intrastat base module for OpenERP +# Intrastat base module for Odoo # Copyright (C) 2010-2014 Akretion (http://www.akretion.com/) # @author Alexis de Lattre # diff --git a/intrastat_base/tax.py b/intrastat_base/tax.py index 2b98678..197e51d 100644 --- a/intrastat_base/tax.py +++ b/intrastat_base/tax.py @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- ############################################################################## # -# Report intrastat base module for Odoo +# Intrastat base module for Odoo # Copyright (C) 2011-2014 Akretion (http://www.akretion.com). # @author Alexis de Lattre #