Skip to content

Commit

Permalink
intrastat - add 2019 fields to xls export
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-demeyer committed Feb 11, 2019
1 parent 705ab18 commit 006b5ae
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 4 deletions.
2 changes: 1 addition & 1 deletion l10n_be_intrastat_product/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
'name': 'Intrastat Product Declaration for Belgium',
'version': '11.0.1.1.0',
'version': '11.0.1.1.1',
'category': 'Intrastat',
'license': 'AGPL-3',
'summary': 'Intrastat Product Declaration for Belgium',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

from odoo import api, fields, models, _
from odoo.exceptions import UserError, RedirectWarning
from odoo.addons.report_xlsx_helper.report.report_xlsx_abstract \
import ReportXlsxAbstract

from lxml import etree
import logging
_render = ReportXlsxAbstract._render
_logger = logging.getLogger(__name__)

_INTRASTAT_XMLNS = 'http://www.onegate.eu/2010-01-01'
Expand Down Expand Up @@ -335,6 +338,38 @@ def _generate_xml(self):
)
return xml_string

def _xls_computation_line_fields(self):
res = super()._xls_computation_line_fields()
i = res.index('product_origin_country')
if self.type == 'dispatches':
res.insert(i + 1, 'vat_number')
else:
res.pop(i)
return res

def _xls_declaration_line_fields(self):
res = super()._xls_declaration_line_fields()
if self.type == 'dispatches':
i = res.index('hs_code')
res.insert(i + 1, 'vat_number')
res.insert(i + 1, 'product_origin_country')
return res

def _xls_template(self):
res = super()._xls_template()
res['vat_number'] = {
'header': {
'type': 'string',
'value': _('VAT Number'),
},
'line': {
'value': _render(
"line.vat_number or ''"),
},
'width': 18,
}
return res


class L10nBeIntrastatProductComputationLine(models.Model):
_name = 'l10n.be.intrastat.product.computation.line'
Expand Down
57 changes: 54 additions & 3 deletions l10n_be_intrastat_product/views/l10n_be_intrastat_product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
<attribute name="invisible"/>
</field>
<field name="amount_accessory_cost_company_currency" position="attributes">
<attribute name="invisible">1</attribute>/>
<attribute name="invisible">1</attribute>
</field>
<field name="product_origin_country_id" position="attributes">
<attribute name="invisible"/>
<attribute name="attrs">{'invisible': [('type', '=', 'arrivals')]}</attribute>
</field>
<field name="incoterm_id" position="attributes">
<attribute name="invisible"/>
Expand All @@ -32,8 +36,31 @@
<field name="region_id" position="attributes">
<attribute name="invisible"/>
</field>
<!--
In Odoo 10.0 the lines below result in a conditional hide of the tree view columns:
<field name="product_origin_country_id" position="attributes">
<attribute name="invisible">context.get('type') == 'arrivals'</attribute>
</field>
<field name="product_origin_country_id" position="after">
<field name="vat_number" invisible="context.get('type') == 'arrivals'"/>
</field>
This is broken in Odoo 11.0.
As an alternative we now use the 'column_invisible' modifier but this one only works
when the tree view is embedded directly into the form view.
We have created a PR (cf. https://github.com/odoo/odoo/pull/30982) which fixes this limitation.
Until this PR is merged by Odoo we recommend to install the web_column_invisible_fix module.
-->
<field name="product_origin_country_id" position="attributes">
<attribute name="invisible"/>
<attribute name="attrs">{'column_invisible': [('parent.type', '=', 'arrivals')]}</attribute>
</field>
<field name="product_origin_country_id" position="after">
<field name="vat_number" attrs="{'column_invisible': [('parent.type', '=', 'arrivals')]}"/>
</field>
<field name="amount_accessory_cost_company_currency" position="attributes">
<attribute name="invisible">1</attribute>/>
<attribute name="invisible">1</attribute>
</field>
</field>
</record>
Expand All @@ -44,6 +71,10 @@
<field name="mode">primary</field>
<field name="inherit_id" ref="intrastat_product.intrastat_product_declaration_line_view_form"/>
<field name="arch" type="xml">
<field name="product_origin_country_id" position="attributes">
<attribute name="invisible"/>
<attribute name="attrs">{'invisible': [('type', '=', 'arrivals')]}</attribute>
</field>
<field name="product_origin_country_id" position="after">
<field name="vat_number" attrs="{'invisible': [('type', '=', 'arrivals')]}"/>
</field>
Expand All @@ -63,8 +94,28 @@
<field name="mode">primary</field>
<field name="inherit_id" ref="intrastat_product.intrastat_product_declaration_line_view_tree"/>
<field name="arch" type="xml">
<!--
In Odoo 10.0 the lines below result in a conditional hide of the tree view columns:
<field name="product_origin_country_id" position="attributes">
<attribute name="invisible">context.get('type') == 'arrivals'</attribute>
</field>
<field name="product_origin_country_id" position="after">
<field name="vat_number" attrs="{'invisible': [('type', '=', 'arrivals')]}"/>
<field name="vat_number" invisible="context.get('type') == 'arrivals'"/>
</field>
This is broken in Odoo 11.0.
As an alternative we now use the 'column_invisible' modifier but this one only works
when the tree view is embedded directly into the form view.
We have created a PR (cf. https://github.com/odoo/odoo/pull/30982) which fixes this limitation.
Until this PR is merged by Odoo we recommend to install the web_column_invisible_fix module.
-->
<field name="product_origin_country_id" position="attributes">
<attribute name="invisible"/>
<attribute name="attrs">{'column_invisible': [('parent.type', '=', 'arrivals')]}</attribute>
</field>
<field name="product_origin_country_id" position="after">
<field name="vat_number" attrs="{'column_invisible': [('parent.type', '=', 'arrivals')]}"/>
</field>
<field name="region_id" position="attributes">
<attribute name="invisible"/>
Expand Down
13 changes: 13 additions & 0 deletions web_column_invisible_fix/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

==========================
Web 'column_invisible' fix
==========================

The 'column_invisible' modifier doesn't work for O2M fields
where the tree view is not embedded in the form view.

We have created a PR (cf. https://github.com/odoo/odoo/pull/30982) which fixes this limitation.
Until this PR is merged by Odoo we recommend to install the web_column_invisible_fix module.
Empty file.
16 changes: 16 additions & 0 deletions web_column_invisible_fix/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2019 Noviat.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': "Web 'column_invisible' fix",
'version': '11.0.1.0.0',
'license': 'AGPL-3',
'author': 'Noviat',
'website': 'http://www.noviat.com',
'category': 'Web',
'depends': ['web'],
'data': [
'views/assets_backend.xml',
],
'installable': True,
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions web_column_invisible_fix/static/src/js/relational_fields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright 2019 Noviat (www.noviat.com) */

odoo.define("web_column_invisible_fix.relational_fields", function (require) {
"use strict";

var relational_fields = require('web.relational_fields');

relational_fields.FieldOne2Many.include({

init: function () {
var self = this;
this._super.apply(this, arguments);
var todo = false;
var arch = this.view && this.view.arch;
if (arch) {
/*
Set columnInvisibleFields which have not been set before.
This is the case for O2M fields where the tree view is not embedded in the form view.
*/
if (typeof this.attrs.columnInvisibleFields === "undefined") {
this.attrs.columnInvisibleFields = {};
_.each(arch.children, function (child) {
if (child.attrs && child.attrs.modifiers && child.attrs.modifiers.column_invisible) {
self.attrs.columnInvisibleFields[child.attrs.name] = child.attrs.modifiers.column_invisible;
todo = true;
};
});
};
};
if (todo) {
this._processColumnInvisibleFields();
};
},
});

});
10 changes: 10 additions & 0 deletions web_column_invisible_fix/views/assets_backend.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<template id="assets_backend" name="column_invisible_fix assets_backend" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/web_column_invisible_fix/static/src/js/relational_fields.js"></script>
</xpath>
</template>

</odoo>

0 comments on commit 006b5ae

Please sign in to comment.