diff --git a/intrastat_base/__manifest__.py b/intrastat_base/__manifest__.py index d584ab2..b92710b 100644 --- a/intrastat_base/__manifest__.py +++ b/intrastat_base/__manifest__.py @@ -1,5 +1,6 @@ -# © 2011-2016 Akretion (http://www.akretion.com) -# © 2018 brain-tec AG (Kumar Aberer ) +# Copyright 2011-2016 Akretion (http://www.akretion.com) +# Copyright 2018 brain-tec AG (Kumar Aberer ) +# Copyright 2009-2019 Noviat (http://www.noviat.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { @@ -8,7 +9,7 @@ 'category': 'Intrastat', 'license': 'AGPL-3', 'summary': 'Base module for Intrastat reporting', - 'author': 'Akretion,Odoo Community Association (OCA)', + 'author': 'Akretion,Noviat,Odoo Community Association (OCA)', 'website': 'https://github.com/OCA/intrastat', 'depends': ['base_vat', 'account'], 'conflicts': ['report_intrastat'], diff --git a/intrastat_base/i18n/intrastat_base.pot b/intrastat_base/i18n/intrastat_base.pot index e9e9889..315e3f2 100644 --- a/intrastat_base/i18n/intrastat_base.pot +++ b/intrastat_base/i18n/intrastat_base.pot @@ -20,7 +20,7 @@ msgid "Activate this option for shipping costs, packaging costs and all services msgstr "" #. module: intrastat_base -#: code:addons/intrastat_base/models/intrastat_common.py:154 +#: code:addons/intrastat_base/models/intrastat_common.py:151 #, python-format msgid "Cannot delete the declaration %s because it is in Done state" msgstr "" @@ -36,7 +36,7 @@ msgid "Companies" msgstr "" #. module: intrastat_base -#: code:addons/intrastat_base/models/intrastat_common.py:33 +#: code:addons/intrastat_base/models/intrastat_common.py:39 #, python-format msgid "Company not yet set on intrastat report." msgstr "" @@ -70,6 +70,7 @@ msgstr "" #. module: intrastat_base #: model:ir.model.fields,field_description:intrastat_base.field_account_tax_exclude_from_intrastat_if_present +#: model:ir.model.fields,field_description:intrastat_base.field_account_tax_template_exclude_from_intrastat_if_present msgid "Exclude invoice line from intrastat if this tax is present" msgstr "" @@ -81,6 +82,7 @@ msgstr "" #. module: intrastat_base #: model:ir.model.fields,help:intrastat_base.field_account_tax_exclude_from_intrastat_if_present +#: model:ir.model.fields,help:intrastat_base.field_account_tax_template_exclude_from_intrastat_if_present 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 "" @@ -177,35 +179,34 @@ msgid "Tax" msgstr "" #. module: intrastat_base -#: code:addons/intrastat_base/models/intrastat_common.py:51 +#: model:ir.model,name:intrastat_base.model_account_tax_template +msgid "Templates for Taxes" +msgstr "" + +#. module: intrastat_base +#: code:addons/intrastat_base/models/intrastat_common.py:52 #, python-format msgid "The VAT number is not set for the partner '%s'." msgstr "" #. module: intrastat_base -#: code:addons/intrastat_base/models/intrastat_common.py:41 -#, python-format -msgid "The company currency must be 'EUR', but is currently '%s'." -msgstr "" - -#. module: intrastat_base -#: code:addons/intrastat_base/models/intrastat_common.py:37 +#: code:addons/intrastat_base/models/intrastat_common.py:43 #, python-format msgid "The country is not set on the company '%s'." msgstr "" -#. module: intrastat_base -#: code:addons/intrastat_base/models/intrastat_common.py:74 -#, 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/models/product_template.py:23 #, 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/models/intrastat_common.py:73 +#, python-format +msgid "Unknown Error" +msgstr "" + #. module: intrastat_base #: model:ir.model.fields,field_description:intrastat_base.field_res_company_intrastat_remind_user_ids #: model:ir.model.fields,field_description:intrastat_base.field_res_config_settings_intrastat_remind_user_ids diff --git a/intrastat_base/models/intrastat_common.py b/intrastat_base/models/intrastat_common.py index bc13e5f..048d5c5 100644 --- a/intrastat_base/models/intrastat_common.py +++ b/intrastat_base/models/intrastat_common.py @@ -1,12 +1,16 @@ -# © 2010-2016 Akretion (Alexis de Lattre ) +# Copyright 2010-2016 Akretion () +# Copyright 2009-2019 Noviat (http://www.noviat.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api, tools, _ -from odoo.exceptions import UserError -import base64 +from io import BytesIO from lxml import etree +from sys import exc_info +from traceback import format_exception import logging +from odoo import api, fields, models, tools, _ +from odoo.exceptions import UserError + logger = logging.getLogger(__name__) @@ -50,43 +54,40 @@ class IntrastatCommon(models.AbstractModel): return True @api.model - def _check_xml_schema(self, xml_etree, xsd_file): + def _check_xml_schema(self, xml_string, xsd_file): '''Validate the XML file against the XSD''' xsd_etree_obj = etree.parse( - tools.file_open(xsd_file)) + tools.file_open(xsd_file, mode='rb')) official_schema = etree.XMLSchema(xsd_etree_obj) try: - official_schema.assertValid(xml_etree) - except Exception as e: - # if the validation of the XSD fails, we arrive here - logger = logging.getLogger(__name__) + t = etree.parse(BytesIO(xml_string)) + official_schema.assertValid(t) + except (etree.XMLSchemaParseError, etree.DocumentInvalid) as e: logger.warning( "The XML file is invalid against the XML Schema Definition") - xml_string = etree.tostring( - xml_etree, pretty_print=True, encoding='UTF-8', - xml_declaration=True).decode() logger.warning(xml_string) logger.warning(e) - raise UserError(_( - "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 + usererror = '%s\n\n%s' % (e.__class__.__name__, str(e)) + raise UserError(usererror) + except Exception: + error = _("Unknown Error") + tb = ''.join(format_exception(*exc_info())) + error += '\n%s' % tb + logger.warning(error) + raise UserError(error) @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 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.b64encode(xml_string), + 'datas': base64.encodestring(xml_string), 'datas_fname': filename}) return attach.id diff --git a/intrastat_base/models/product_template.py b/intrastat_base/models/product_template.py index 0f714f0..bc3f6ca 100644 --- a/intrastat_base/models/product_template.py +++ b/intrastat_base/models/product_template.py @@ -1,7 +1,7 @@ -# © 2010-2016 Akretion (Alexis de Lattre ) +# Copyright 2010-2016 Akretion () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api, _ +from odoo import api, fields, models, _ from odoo.exceptions import ValidationError @@ -19,8 +19,9 @@ class ProductTemplate(models.Model): def _check_accessory_cost(self): for this in self: if this.is_accessory_cost and this.type != 'service': - raise ValidationError(_( - "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'") % (this.name, this.type)) + raise ValidationError( + _("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'") % + (this.name, this.type)) diff --git a/intrastat_base/models/res_company.py b/intrastat_base/models/res_company.py index 4b110f0..f67bcf5 100644 --- a/intrastat_base/models/res_company.py +++ b/intrastat_base/models/res_company.py @@ -1,7 +1,7 @@ -# © 2013-2017 Akretion (Alexis de Lattre ) +# Copyright 2013-2017 Akretion () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api, _ +from odoo import api, fields, models, _ from odoo.exceptions import ValidationError diff --git a/intrastat_base/models/res_config_settings.py b/intrastat_base/models/res_config_settings.py index 4191666..14c62ec 100644 --- a/intrastat_base/models/res_config_settings.py +++ b/intrastat_base/models/res_config_settings.py @@ -1,8 +1,8 @@ -# © 2017 Akretion (Alexis de Lattre ) -# © 2018 brain-tec AG (Kumar Aberer ) +# Copyright 2017 Akretion (Alexis de Lattre ) +# Copyright 2018 brain-tec AG (Kumar Aberer ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import models, fields +from odoo import fields, models class ResConfigSettings(models.TransientModel): diff --git a/intrastat_base/models/res_country.py b/intrastat_base/models/res_country.py index 9b4868c..3af71f0 100644 --- a/intrastat_base/models/res_country.py +++ b/intrastat_base/models/res_country.py @@ -1,7 +1,7 @@ -# © 2011-2014 Akretion (Alexis de Lattre ) +# Copyright 2011-2014 Akretion () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields +from odoo import fields, models class ResCountry(models.Model): diff --git a/intrastat_base/static/description/icon.png b/intrastat_base/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/intrastat_base/static/description/icon.png differ diff --git a/intrastat_base/views/account_tax.xml b/intrastat_base/views/account_tax.xml index 7f77213..a1e72cd 100644 --- a/intrastat_base/views/account_tax.xml +++ b/intrastat_base/views/account_tax.xml @@ -12,9 +12,9 @@ account.tax - + - + diff --git a/intrastat_base/views/res_config_settings.xml b/intrastat_base/views/res_config_settings.xml index de45030..f472061 100644 --- a/intrastat_base/views/res_config_settings.xml +++ b/intrastat_base/views/res_config_settings.xml @@ -15,14 +15,13 @@

Intrastat

-
+
+
-
-
-
-
+
+