From d33c78f1fbb5cb06f5d74e4e5d0248d216ea81cb Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 6 Dec 2018 19:34:56 +0100 Subject: [PATCH] Add new module product_harmonized_system_delivery (hide native hs_code field) Finalize port to v11 --- intrastat_base/models/account_tax.py | 10 ++++++++ intrastat_base/models/intrastat_common.py | 27 ++++++++++---------- intrastat_base/views/account_tax.xml | 4 +-- intrastat_base/views/res_config_settings.xml | 8 ++++-- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/intrastat_base/models/account_tax.py b/intrastat_base/models/account_tax.py index 2235255..df81523 100644 --- a/intrastat_base/models/account_tax.py +++ b/intrastat_base/models/account_tax.py @@ -12,3 +12,13 @@ class AccountTax(models.Model): 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.") + + +class AccountTaxTemplate(models.Model): + _inherit = "account.tax.template" + + exclude_from_intrastat_if_present = fields.Boolean( + string='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.") diff --git a/intrastat_base/models/intrastat_common.py b/intrastat_base/models/intrastat_common.py index 45b9399..bc13e5f 100644 --- a/intrastat_base/models/intrastat_common.py +++ b/intrastat_base/models/intrastat_common.py @@ -3,6 +3,8 @@ from odoo import models, fields, api, tools, _ from odoo.exceptions import UserError +import base64 +from lxml import etree import logging logger = logging.getLogger(__name__) @@ -48,29 +50,29 @@ class IntrastatCommon(models.AbstractModel): return True @api.model - def _check_xml_schema(self, xml_string, xsd_file): + def _check_xml_schema(self, xml_etree, xsd_file): '''Validate the XML file against the XSD''' - from lxml import etree - from io import StringIO xsd_etree_obj = etree.parse( tools.file_open(xsd_file)) official_schema = etree.XMLSchema(xsd_etree_obj) try: - t = etree.parse(StringIO(xml_string)) - official_schema.assertValid(t) + official_schema.assertValid(xml_etree) except Exception as e: # if the validation of the XSD fails, we arrive here logger = logging.getLogger(__name__) 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.") + 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 @@ -79,13 +81,12 @@ class IntrastatCommon(models.AbstractModel): '''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.encodestring(xml_string), + 'datas': base64.b64encode(xml_string), 'datas_fname': filename}) return attach.id diff --git a/intrastat_base/views/account_tax.xml b/intrastat_base/views/account_tax.xml index a1e72cd..7f77213 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 cb9fd76..de45030 100644 --- a/intrastat_base/views/res_config_settings.xml +++ b/intrastat_base/views/res_config_settings.xml @@ -17,8 +17,12 @@
-