mirror of
https://github.com/OCA/intrastat-extrastat.git
synced 2025-02-16 17:13:41 +02:00
Add new module product_harmonized_system_delivery (hide native hs_code field)
Finalize port to v11
This commit is contained in:
committed by
Pedro M. Baeza
parent
919a7944ae
commit
d68468cb77
@@ -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.")
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
<field name="model">account.tax</field>
|
||||
<field name="inherit_id" ref="account.view_tax_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="active" position="before">
|
||||
<group name="advanced_booleans" position="inside">
|
||||
<field name="exclude_from_intrastat_if_present"/>
|
||||
</field>
|
||||
</group>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -17,8 +17,12 @@
|
||||
<div class="row mt16 o_settings_container" id="intrastat">
|
||||
<div class="col-xs-12 col-md-6 o_setting_box">
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="intrastat_remind_user_ids"/>
|
||||
<field name="intrastat_remind_user_ids" widget="many2many_tags"/>
|
||||
<div class="content-group" id="intrastat_content_grp">
|
||||
<div class="row mt16">
|
||||
<label for="intrastat_remind_user_ids" class="col-md-5 o_light_label"/>
|
||||
<field name="intrastat_remind_user_ids" widget="many2many_tags"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -12,48 +12,48 @@
|
||||
<field name="arch" type="xml">
|
||||
|
||||
|
||||
<xpath expr="//div[@id='intrastat']" position="inside">
|
||||
<div class="col-xs-12 col-md-6 o_setting_box">
|
||||
<div class="o_setting_right_pane">
|
||||
<div class="content-group">
|
||||
<div class="row mt16">
|
||||
<label for="intrastat_arrivals" class="col-md-5 o_light_label"/>
|
||||
<field name="intrastat_arrivals"/>
|
||||
|
||||
<label for="intrastat_dispatches" class="col-md-5 o_light_label"/>
|
||||
<field name="intrastat_dispatches"/>
|
||||
|
||||
<label for="intrastat_transport_id" class="col-md-5 o_light_label"/>
|
||||
<field name="intrastat_transport_id"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="intrastat_content_grp" position="inside">
|
||||
<div class="row mt16">
|
||||
<label for="intrastat_arrivals" class="col-md-5 o_light_label"/>
|
||||
<field name="intrastat_arrivals"/>
|
||||
</div>
|
||||
|
||||
</xpath>
|
||||
<xpath expr="//div[@id='intrastat']" position="after">
|
||||
<div class="row mt16 o_settings_container" id="intrastat_ext">
|
||||
<div class="row mt16">
|
||||
<label for="intrastat_dispatches" class="col-md-5 o_light_label"/>
|
||||
<field name="intrastat_dispatches"/>
|
||||
</div>
|
||||
<div class="row mt16">
|
||||
<label for="intrastat_transport_id" class="col-md-5 o_light_label"/>
|
||||
<field name="intrastat_transport_id"/>
|
||||
</div>
|
||||
<div class="row mt16">
|
||||
<label for="intrastat_incoterm_id" class="col-md-5 o_light_label"/>
|
||||
<field name="intrastat_incoterm_id"/>
|
||||
|
||||
</div>
|
||||
<div class="row mt16">
|
||||
<label for="intrastat_transaction_out_invoice" class="col-md-5 o_light_label"/>
|
||||
<field name="intrastat_transaction_out_invoice"/>
|
||||
|
||||
</div>
|
||||
<div class="row mt16">
|
||||
<label for="intrastat_transaction_out_refund" class="col-md-5 o_light_label"/>
|
||||
<field name="intrastat_transaction_out_refund"/>
|
||||
|
||||
</div>
|
||||
<div class="row mt16">
|
||||
<label for="intrastat_transaction_in_invoice" class="col-md-5 o_light_label"/>
|
||||
<field name="intrastat_transaction_in_invoice"/>
|
||||
|
||||
</div>
|
||||
<div class="row mt16">
|
||||
<label for="intrastat_transaction_in_refund" class="col-md-5 o_light_label"/>
|
||||
<field name="intrastat_transaction_in_refund"/>
|
||||
|
||||
</div>
|
||||
<div id="intrastat_accessory_costs" class="row mt16" invisible="1">
|
||||
<label for="intrastat_accessory_costs" class="col-md-5 o_light_label"/>
|
||||
<field name="intrastat_accessory_costs"/>
|
||||
|
||||
<field name="intrastat_region_id" invisible="1"/>
|
||||
</div>
|
||||
</xpath>
|
||||
<div class="row mt16" id="intrastat_region" invisible="1">
|
||||
<label for="intrastat_region_id" class="col-md-5 o_light_label"/>
|
||||
<field name="intrastat_region_id"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</field>
|
||||
|
||||
@@ -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(
|
||||
|
||||
0
product_harmonized_system_delivery/__init__.py
Normal file
0
product_harmonized_system_delivery/__init__.py
Normal file
16
product_harmonized_system_delivery/__manifest__.py
Normal file
16
product_harmonized_system_delivery/__manifest__.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# Copyright 2018 Akretion France (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# 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,
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
* Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
@@ -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.
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2018 Akretion France (http://www.akretion.com/)
|
||||
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
<!-- product.template form view -->
|
||||
<record id="product_template_hs_code" model="ir.ui.view">
|
||||
<field name="name">hide_native_hs_code_field.product.template.form</field>
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id" ref="delivery.product_template_hs_code" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="hs_code" position="attributes">
|
||||
<attribute name="invisible">1</attribute>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user