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 @@
-
-
+
+
+
+
+
+
diff --git a/intrastat_product/models/account_invoice.py b/intrastat_product/models/account_invoice.py
index 4fcc0fe..fcd38fe 100644
--- a/intrastat_product/models/account_invoice.py
+++ b/intrastat_product/models/account_invoice.py
@@ -53,7 +53,7 @@ class AccountInvoice(models.Model):
@api.model
def _default_intrastat_transaction_id(self):
rco = self.env['res.company']
- company = rco._company_default_get('account.invoice')
+ company = rco._company_default_get()
inv_type = self._context.get('type')
if inv_type == 'out_invoice':
return company.intrastat_transaction_out_invoice
@@ -69,7 +69,7 @@ class AccountInvoice(models.Model):
@api.model
def _default_src_dest_region_id(self):
rco = self.env['res.company']
- company = rco._company_default_get('account.invoice')
+ company = rco._company_default_get()
return company.intrastat_region_id
diff --git a/intrastat_product/models/intrastat_product_declaration.py b/intrastat_product/models/intrastat_product_declaration.py
index d700233..3eec980 100644
--- a/intrastat_product/models/intrastat_product_declaration.py
+++ b/intrastat_product/models/intrastat_product_declaration.py
@@ -80,8 +80,7 @@ class IntrastatProductDeclaration(models.Model):
company_id = fields.Many2one(
'res.company', string='Company', readonly=True,
- default=lambda self: self.env['res.company']._company_default_get(
- 'intrastat.product.declaration'))
+ default=lambda self: self.env['res.company']._company_default_get())
company_country_code = fields.Char(
compute='_compute_company_country_code',
string='Company Country Code', readonly=True, store=True,
@@ -924,29 +923,6 @@ class IntrastatProductDeclarationLine(models.Model):
'res.country', string='Country of Origin of the Product',
help="Country of origin of the product i.e. product 'made in ____'")
- @api.model
- def _prepare_grouped_fields(self, computation_line, fields_to_sum):
- """
- This method is DEPRECATED.
- You should use the _prepare_grouped_fields method on the
- IntrastatProductDeclaration class.
- """
- vals = {
- 'src_dest_country_id': computation_line.src_dest_country_id.id,
- 'intrastat_unit_id': computation_line.intrastat_unit_id.id,
- 'hs_code_id': computation_line.hs_code_id.id,
- 'transaction_id': computation_line.transaction_id.id,
- 'transport_id': computation_line.transport_id.id,
- 'region_id': computation_line.region_id.id,
- 'parent_id': computation_line.parent_id.id,
- 'product_origin_country_id':
- computation_line.product_origin_country_id.id,
- 'amount_company_currency': 0.0,
- }
- for field in fields_to_sum:
- vals[field] = 0.0
- return vals
-
def _fields_to_sum(self):
"""
This method is DEPRECATED.
diff --git a/intrastat_product/models/intrastat_region.py b/intrastat_product/models/intrastat_region.py
index b385255..84f9537 100644
--- a/intrastat_product/models/intrastat_region.py
+++ b/intrastat_product/models/intrastat_region.py
@@ -16,8 +16,7 @@ class IntrastatRegion(models.Model):
description = fields.Char(string='Description')
company_id = fields.Many2one(
'res.company', string='Company',
- default=lambda self: self.env['res.company']._company_default_get(
- 'intrastat.region'))
+ default=lambda self: self.env['res.company']._company_default_get())
_sql_constraints = [
('intrastat_region_code_unique',
diff --git a/intrastat_product/models/intrastat_transaction.py b/intrastat_product/models/intrastat_transaction.py
index 49fb34a..8d66fe1 100644
--- a/intrastat_product/models/intrastat_transaction.py
+++ b/intrastat_product/models/intrastat_transaction.py
@@ -20,8 +20,7 @@ class IntrastatTransaction(models.Model):
readonly=True, store=True)
company_id = fields.Many2one(
'res.company', string='Company',
- default=lambda self: self.env['res.company']._company_default_get(
- 'intrastat.transaction'))
+ default=lambda self: self.env['res.company']._company_default_get())
@api.multi
@api.depends('code', 'description')
diff --git a/intrastat_product/views/res_config_settings.xml b/intrastat_product/views/res_config_settings.xml
index 9c6bdbb..cc9c212 100644
--- a/intrastat_product/views/res_config_settings.xml
+++ b/intrastat_product/views/res_config_settings.xml
@@ -12,48 +12,48 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
-
+
+
-
+
+
-
+
+
-
+
+
-
+
+
-
-
-
+
+
+
+
+
diff --git a/product_harmonized_system/models/hs_code.py b/product_harmonized_system/models/hs_code.py
index 1b0d158..7312a91 100644
--- a/product_harmonized_system/models/hs_code.py
+++ b/product_harmonized_system/models/hs_code.py
@@ -31,9 +31,8 @@ class HSCode(models.Model):
"has a few additional digits to extend the H.S. code.")
active = fields.Boolean(default=True)
company_id = fields.Many2one(
- 'res.company', string='Company', readonly=True, required=True,
- default=lambda self: self.env['res.company']._company_default_get(
- 'hs.code'))
+ 'res.company', string='Company',
+ default=lambda self: self.env['res.company']._company_default_get())
product_categ_ids = fields.One2many(
'product.category', 'hs_code_id', string='Product Categories')
product_tmpl_ids = fields.One2many(
diff --git a/product_harmonized_system_delivery/__init__.py b/product_harmonized_system_delivery/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/product_harmonized_system_delivery/__manifest__.py b/product_harmonized_system_delivery/__manifest__.py
new file mode 100644
index 0000000..725f53c
--- /dev/null
+++ b/product_harmonized_system_delivery/__manifest__.py
@@ -0,0 +1,16 @@
+# Copyright 2018 Akretion France (http://www.akretion.com)
+# @author Alexis de Lattre
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+{
+ 'name': 'Product Harmonized System Codes - Delivery',
+ 'version': '11.0.1.0.0',
+ 'category': 'Reporting',
+ 'license': 'AGPL-3',
+ 'summary': 'Hide native hs_code field provided by the delivery module',
+ 'author': 'Akretion, Odoo Community Association (OCA)',
+ 'depends': ['delivery', 'product_harmonized_system'],
+ 'data': ['views/product_template.xml'],
+ 'installable': True,
+ 'auto_install': True,
+}
diff --git a/product_harmonized_system_delivery/readme/CONTRIBUTORS.rst b/product_harmonized_system_delivery/readme/CONTRIBUTORS.rst
new file mode 100644
index 0000000..ff65d68
--- /dev/null
+++ b/product_harmonized_system_delivery/readme/CONTRIBUTORS.rst
@@ -0,0 +1 @@
+* Alexis de Lattre
diff --git a/product_harmonized_system_delivery/readme/DESCRIPTION.rst b/product_harmonized_system_delivery/readme/DESCRIPTION.rst
new file mode 100644
index 0000000..ecd76ab
--- /dev/null
+++ b/product_harmonized_system_delivery/readme/DESCRIPTION.rst
@@ -0,0 +1 @@
+The OCA module *product_harmonized_system* adds a many2one field *hs_code_id* on product templates that points to an *H.S. Code* object. But the *delivery* module from the official addons adds a char field *hs_code* on product templates, which has the same purpose, but we can't use it because we need structured data for H.S. codes. This module hides the *hs_code* field added by the *delivery* module, to avoid confusion.
diff --git a/product_harmonized_system_delivery/views/product_template.xml b/product_harmonized_system_delivery/views/product_template.xml
new file mode 100644
index 0000000..d9a6695
--- /dev/null
+++ b/product_harmonized_system_delivery/views/product_template.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+ hide_native_hs_code_field.product.template.form
+ product.template
+
+
+
+ 1
+
+
+
+
+