mirror of
https://github.com/OCA/intrastat-extrastat.git
synced 2025-02-16 17:13:41 +02:00
[10.0] add xls export & generic declaration
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import models
|
||||
from . import report
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2011-2017 Akretion (http://www.akretion.com)
|
||||
# © 2009-2017 Noviat (http://www.noviat.com)
|
||||
# © 2009-2018 Noviat (http://www.noviat.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# @author Luc de Meyer <info@noviat.com>
|
||||
|
||||
{
|
||||
'name': 'Intrastat Product',
|
||||
'version': '10.0.1.2.1',
|
||||
'version': '10.0.1.3.0',
|
||||
'category': 'Intrastat',
|
||||
'license': 'AGPL-3',
|
||||
'summary': 'Base module for Intrastat Product',
|
||||
@@ -16,6 +16,7 @@
|
||||
'product_harmonized_system',
|
||||
'sale_stock',
|
||||
'purchase',
|
||||
'report_xlsx_helper',
|
||||
],
|
||||
'conflicts': ['report_intrastat'],
|
||||
'data': [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2011-2017 Akretion (http://www.akretion.com)
|
||||
# © 2009-2017 Noviat (http://www.noviat.com)
|
||||
# © 2009-2018 Noviat (http://www.noviat.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# @author Luc de Meyer <info@noviat.com>
|
||||
|
||||
@@ -718,6 +718,47 @@ class IntrastatProductDeclaration(models.Model):
|
||||
raise UserError(
|
||||
_("No XML File has been generated."))
|
||||
|
||||
@api.multi
|
||||
def create_xls(self):
|
||||
return {
|
||||
'type': 'ir.actions.report.xml',
|
||||
'report_type': 'xlsx',
|
||||
'report_name': 'intrastat.product.declaration.xlsx',
|
||||
'context': dict(self._context, xlsx_export=True),
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _xls_computation_line_fields(self):
|
||||
"""
|
||||
Update list in custom module to add/drop columns or change order
|
||||
"""
|
||||
return [
|
||||
'product', 'product_origin_country',
|
||||
'hs_code', 'src_dest_country',
|
||||
'amount_company_currency', 'accessory_cost',
|
||||
'transaction', 'weight', 'suppl_unit_qty', 'suppl_unit',
|
||||
'transport', 'invoice',
|
||||
]
|
||||
|
||||
@api.model
|
||||
def _xls_declaration_line_fields(self):
|
||||
"""
|
||||
Update list in custom module to add/drop columns or change order
|
||||
"""
|
||||
return [
|
||||
'hs_code', 'src_dest_country', 'amount_company_currency',
|
||||
'transaction', 'weight', 'suppl_unit_qty', 'suppl_unit',
|
||||
'transport',
|
||||
]
|
||||
|
||||
@api.model
|
||||
def _xls_template(self):
|
||||
"""
|
||||
Placeholder for excel report template updates
|
||||
|
||||
"""
|
||||
return {}
|
||||
|
||||
@api.multi
|
||||
def done(self):
|
||||
self.write({'state': 'done'})
|
||||
|
||||
2
intrastat_product/report/__init__.py
Normal file
2
intrastat_product/report/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import intrastat_product_report_xls
|
||||
295
intrastat_product/report/intrastat_product_report_xls.py
Normal file
295
intrastat_product/report/intrastat_product_report_xls.py
Normal file
@@ -0,0 +1,295 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2009-2018 Noviat
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
import logging
|
||||
|
||||
from odoo.addons.report_xlsx_helper.report.abstract_report_xlsx \
|
||||
import AbstractReportXlsx
|
||||
# from odoo.exceptions import UserError
|
||||
from odoo.report import report_sxw
|
||||
from odoo.tools.translate import translate, _
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
IR_TRANSLATION_NAME = 'intrastat.product.report'
|
||||
|
||||
|
||||
class IntrastatProductDeclarationXlsx(AbstractReportXlsx):
|
||||
|
||||
def _(self, src):
|
||||
lang = self.env.context.get('lang', 'en_US')
|
||||
val = translate(
|
||||
self.env.cr, IR_TRANSLATION_NAME, 'report', lang, src) or src
|
||||
return val
|
||||
|
||||
def _get_template(self):
|
||||
|
||||
template = {
|
||||
'product': {
|
||||
'header': {
|
||||
'type': 'string',
|
||||
'value': self._('Product'),
|
||||
},
|
||||
'line': {
|
||||
'value': self._render(
|
||||
"line.product_id and line.product_id.name"),
|
||||
},
|
||||
'width': 36,
|
||||
},
|
||||
'product_origin_country': {
|
||||
'header': {
|
||||
'type': 'string',
|
||||
'value': self._('Country of Origin of the Product'),
|
||||
},
|
||||
'line': {
|
||||
'type': 'string',
|
||||
'value': self._render(
|
||||
"line.product_origin_country_id.name or ''"),
|
||||
},
|
||||
'width': 28,
|
||||
},
|
||||
'hs_code': {
|
||||
'header': {
|
||||
'type': 'string',
|
||||
'value': self._('Intrastat Code'),
|
||||
},
|
||||
'line': {
|
||||
'type': 'string',
|
||||
'value': self._render(
|
||||
"line.hs_code_id.local_code"),
|
||||
},
|
||||
'width': 14,
|
||||
},
|
||||
'src_dest_country': {
|
||||
'header': {
|
||||
'type': 'string',
|
||||
'value': self._('Country of Origin/Destination'),
|
||||
},
|
||||
'line': {
|
||||
'type': 'string',
|
||||
'value': self._render(
|
||||
"line.src_dest_country_id.name"),
|
||||
},
|
||||
'width': 28,
|
||||
},
|
||||
'amount_company_currency': {
|
||||
'header': {
|
||||
'type': 'string',
|
||||
'value': self._('Fiscal Value'),
|
||||
'format': self.format_theader_yellow_right,
|
||||
},
|
||||
'line': {
|
||||
'type': 'number',
|
||||
'value': self._render("line.amount_company_currency"),
|
||||
'format': self.format_tcell_amount_right,
|
||||
},
|
||||
'width': 18,
|
||||
},
|
||||
'accessory_cost': {
|
||||
'header': {
|
||||
'type': 'string',
|
||||
'value': self._('Accessory Costs'),
|
||||
'format': self.format_theader_yellow_right,
|
||||
},
|
||||
'line': {
|
||||
'type': 'number',
|
||||
'value': self._render(
|
||||
"line.amount_accessory_cost_company_currency"),
|
||||
'format': self.format_tcell_amount_right,
|
||||
},
|
||||
'width': 18,
|
||||
},
|
||||
'transaction': {
|
||||
'header': {
|
||||
'type': 'string',
|
||||
'value': self._('Intrastat Transaction'),
|
||||
},
|
||||
'line': {
|
||||
'value': self._render(
|
||||
"line.transaction_id.display_name"),
|
||||
},
|
||||
'width': 36,
|
||||
},
|
||||
'weight': {
|
||||
'header': {
|
||||
'type': 'string',
|
||||
'value': self._('Weight'),
|
||||
'format': self.format_theader_yellow_right,
|
||||
},
|
||||
'line': {
|
||||
'type': 'number',
|
||||
'value': self._render(
|
||||
"line.weight"),
|
||||
'format': self.format_tcell_amount_right,
|
||||
},
|
||||
'width': 18,
|
||||
},
|
||||
'suppl_unit_qty': {
|
||||
'header': {
|
||||
'type': 'string',
|
||||
'value': self._('Suppl. Unit Qty'),
|
||||
'format': self.format_theader_yellow_right,
|
||||
},
|
||||
'line': {
|
||||
# we don't specify a type here and rely on the
|
||||
# report_xlsx_helper type detection to use
|
||||
# write_string when suppl_unit_qty is zero
|
||||
'value': self._render(
|
||||
"line.suppl_unit_qty or ''"),
|
||||
'format': self.format_tcell_amount_right,
|
||||
},
|
||||
'width': 18,
|
||||
},
|
||||
'suppl_unit': {
|
||||
'header': {
|
||||
'type': 'string',
|
||||
'value': self._('Suppl. Unit'),
|
||||
},
|
||||
'line': {
|
||||
'value': self._render(
|
||||
"line.intrastat_unit_id.name or ''"),
|
||||
},
|
||||
'width': 14,
|
||||
},
|
||||
'incoterm': {
|
||||
'header': {
|
||||
'type': 'string',
|
||||
'value': self._('Incoterm'),
|
||||
},
|
||||
'line': {
|
||||
'value': self._render("line.incoterm_id.name or ''"),
|
||||
},
|
||||
'width': 14,
|
||||
},
|
||||
'transport': {
|
||||
'header': {
|
||||
'type': 'string',
|
||||
'value': self._('Transport Mode'),
|
||||
},
|
||||
'line': {
|
||||
'value': self._render("line.transport_id.name or ''"),
|
||||
},
|
||||
'width': 14,
|
||||
},
|
||||
'region': {
|
||||
'header': {
|
||||
'type': 'string',
|
||||
'value': self._('Intrastat Region'),
|
||||
},
|
||||
'line': {
|
||||
'value': self._render("line.region_id.name or ''"),
|
||||
},
|
||||
'width': 28,
|
||||
},
|
||||
'invoice': {
|
||||
'header': {
|
||||
'type': 'string',
|
||||
'value': self._('Invoice'),
|
||||
},
|
||||
'line': {
|
||||
'value': self._render("line.invoice_id.number"),
|
||||
},
|
||||
'width': 18,
|
||||
},
|
||||
}
|
||||
template.update(
|
||||
self.env['intrastat.product.declaration']._xls_template())
|
||||
|
||||
return template
|
||||
|
||||
def getObjects(self, cr, uid, ids, context):
|
||||
"""
|
||||
Adapt logic since localization modules have other
|
||||
object tables than the object on which this report is defined.
|
||||
"""
|
||||
active_model = self.env.context['active_model']
|
||||
active_id = self.env.context['active_id']
|
||||
declaration = self.env[active_model].browse(active_id)
|
||||
return declaration
|
||||
|
||||
def _get_ws_params(self, wb, data, declaration):
|
||||
template = self._get_template()
|
||||
if self.env.context.get('computation_lines'):
|
||||
wl = declaration._xls_computation_line_fields()
|
||||
report = 'computation'
|
||||
else:
|
||||
wl = declaration._xls_declaration_line_fields()
|
||||
report = 'declaration'
|
||||
|
||||
title = self._get_title(declaration, report, format='normal')
|
||||
title_short = self._get_title(declaration, report, format='short')
|
||||
sheet_name = title_short[:31].replace('/', '-')
|
||||
|
||||
params = {
|
||||
'ws_name': sheet_name,
|
||||
'generate_ws_method': '_intrastat_report',
|
||||
'title': title,
|
||||
'wanted_list': wl,
|
||||
'col_specs': template,
|
||||
}
|
||||
return [params]
|
||||
|
||||
def _get_title(self, declaration, report, format='normal'):
|
||||
title = declaration.year_month
|
||||
if format == 'normal':
|
||||
if report == 'computation':
|
||||
title += ' : ' + _('Computation Lines')
|
||||
else:
|
||||
title += ' : ' + _('Declaration Lines')
|
||||
return title
|
||||
|
||||
def _report_title(self, ws, row_pos, ws_params, data, declaration):
|
||||
return self._write_ws_title(ws, row_pos, ws_params)
|
||||
|
||||
def _empty_report(self, ws, row_pos, ws_params, data, declaration,
|
||||
report):
|
||||
if report == 'computation':
|
||||
lines = _('Computation Lines')
|
||||
else:
|
||||
lines = _('Declaration Lines')
|
||||
no_entries = _("No") + " " + lines + " " + _("for period %s") \
|
||||
% declaration.year_month
|
||||
ws.write_string(row_pos, 0, no_entries, self.format_left_bold)
|
||||
|
||||
def _intrastat_report(self, workbook, ws, ws_params, data, declaration):
|
||||
|
||||
ws.set_portrait()
|
||||
ws.fit_to_pages(1, 0)
|
||||
ws.set_header(self.xls_headers['standard'])
|
||||
ws.set_footer(self.xls_footers['standard'])
|
||||
|
||||
self._set_column_width(ws, ws_params)
|
||||
|
||||
row_pos = 0
|
||||
row_pos = self._report_title(ws, row_pos, ws_params, data, declaration)
|
||||
|
||||
if self.env.context.get('computation_lines'):
|
||||
report = 'computation'
|
||||
lines = declaration.computation_line_ids
|
||||
else:
|
||||
report = 'declaration'
|
||||
lines = declaration.declaration_line_ids
|
||||
|
||||
if not lines:
|
||||
return self._empty_report(
|
||||
ws, row_pos, ws_params, data, declaration, report)
|
||||
|
||||
row_pos = self._write_line(
|
||||
ws, row_pos, ws_params, col_specs_section='header',
|
||||
default_format=self.format_theader_yellow_left)
|
||||
|
||||
ws.freeze_panes(row_pos, 0)
|
||||
|
||||
for line in lines:
|
||||
row_pos = self._write_line(
|
||||
ws, row_pos, ws_params, col_specs_section='line',
|
||||
render_space={'line': line},
|
||||
default_format=self.format_tcell_left)
|
||||
|
||||
|
||||
IntrastatProductDeclarationXlsx(
|
||||
'report.intrastat.product.declaration.xlsx',
|
||||
'intrastat.product.declaration',
|
||||
parser=report_sxw.rml_parse)
|
||||
@@ -17,7 +17,8 @@
|
||||
<button name="generate_xml"
|
||||
string="Generate XML Declaration File"
|
||||
type="object"
|
||||
attrs="{'invisible': [('state', '!=', 'draft')]}"/>
|
||||
attrs="{'invisible': [('state', '!=', 'draft')]}"
|
||||
invisible="context.get('generic_intrastat_product_declaration')"/>
|
||||
<button name="done" string="Done" type="object" class="oe_highlight" states="draft"/>
|
||||
<button name="back2draft" string="Back to Draft" type="object" states="done"/>
|
||||
<field name="state" widget="statusbar"/>
|
||||
@@ -52,11 +53,19 @@
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="Transactions">
|
||||
<header>
|
||||
<button name="create_xls" type="object" string="Excel Export"
|
||||
context="{'computation_lines': 1}"/>
|
||||
</header>
|
||||
<group name="computation_lines">
|
||||
<field name="computation_line_ids" nolabel="1"/>
|
||||
</group>
|
||||
</page>
|
||||
<page string="Declaration Lines">
|
||||
<header>
|
||||
<button name="create_xls" type="object" string="Excel Export"
|
||||
context="{'declaration_lines': 1}"/>
|
||||
</header>
|
||||
<group name="declaration_lines">
|
||||
<field name="declaration_line_ids" nolabel="1"/>
|
||||
</group>
|
||||
|
||||
55
intrastat_product_generic/README.rst
Normal file
55
intrastat_product_generic/README.rst
Normal file
@@ -0,0 +1,55 @@
|
||||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
|
||||
:target: https://www.gnu.org/licenses/agpl
|
||||
:alt: License: AGPL-3
|
||||
|
||||
=====================================
|
||||
Generic Intrastat Product Declaration
|
||||
=====================================
|
||||
|
||||
This module adds a menu entry for a Generic Intrastat Product Declaration.
|
||||
This is usefull to cover countries for which there is no localization module.
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
There is no specific installation procedure for this module.
|
||||
|
||||
Configuration and Usage
|
||||
=======================
|
||||
|
||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||
:alt: Try me on Runbot
|
||||
:target: https://runbot.odoo-community.org/runbot/227/10.0
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues
|
||||
<https://github.com/OCA/account-financial-tools/issues>`_. In case of trouble, please
|
||||
check there if your issue has already been reported. If you spotted it first,
|
||||
help us smash it by providing detailed and welcomed feedback.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Luc De Meyer <luc.demeyer@noviat.com>
|
||||
|
||||
Do not contact contributors directly about support or help with technical issues.
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
.. image:: https://odoo-community.org/logo.png
|
||||
:alt: Odoo Community Association
|
||||
:target: https://odoo-community.org
|
||||
|
||||
This module is maintained by the OCA.
|
||||
|
||||
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.
|
||||
|
||||
To contribute to this module, please visit http://odoo-community.org.
|
||||
0
intrastat_product_generic/__init__.py
Normal file
0
intrastat_product_generic/__init__.py
Normal file
21
intrastat_product_generic/__manifest__.py
Normal file
21
intrastat_product_generic/__manifest__.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2009-2018 Noviat.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Generic Intrastat Product Declaration',
|
||||
'version': '10.0.1.0.0',
|
||||
'category': 'Accounting & Finance',
|
||||
'website': 'https://github.com/OCA/intrastat',
|
||||
'author': 'Noviat,'
|
||||
'Odoo Community Association (OCA)',
|
||||
'license': 'AGPL-3',
|
||||
'installable': True,
|
||||
'depends': [
|
||||
'intrastat_product',
|
||||
],
|
||||
'data': [
|
||||
'security/intrastat_security.xml',
|
||||
'views/intrastat_product.xml'
|
||||
],
|
||||
}
|
||||
12
intrastat_product_generic/security/intrastat_security.xml
Normal file
12
intrastat_product_generic/security/intrastat_security.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo noupdate="1">
|
||||
|
||||
<record id="group_intrastat_product_generic" model="res.groups">
|
||||
<field name="name">Generic Intrastat Product Declaration</field>
|
||||
</record>
|
||||
|
||||
<record id="base.user_root" model="res.users">
|
||||
<field eval="[(4, ref('group_intrastat_product_generic'))]" name="groups_id"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
BIN
intrastat_product_generic/static/description/icon.png
Normal file
BIN
intrastat_product_generic/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
16
intrastat_product_generic/views/intrastat_product.xml
Normal file
16
intrastat_product_generic/views/intrastat_product.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
|
||||
<record id="intrastat_product_declaration_action_generic" model="ir.actions.act_window">
|
||||
<field name="name">Generic Intrastat Product Declaration</field>
|
||||
<field name="res_model">intrastat.product.declaration</field>
|
||||
<field name="view_mode">tree,form,graph</field>
|
||||
<field name="context">{'generic_intrastat_product_declaration': 1}</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="intrastat_product_declaration_menu_generic"
|
||||
parent="intrastat_base.menu_intrastat_base_root"
|
||||
action="intrastat_product_declaration_action_generic"
|
||||
groups="group_intrastat_product_generic"/>
|
||||
|
||||
</odoo>
|
||||
@@ -14,3 +14,4 @@
|
||||
# To provide both the URL and a branch, use:
|
||||
# sale-workflow https://github.com/OCA/sale-workflow branchname
|
||||
stock-logistics-workflow
|
||||
reporting-engine
|
||||
|
||||
Reference in New Issue
Block a user