Skip to content

Commit

Permalink
[ADD]l10n_it_intrastat_delivery_note: new module that adds missing fi…
Browse files Browse the repository at this point in the history
…elds to the delivery note report
  • Loading branch information
PicchiSeba committed Dec 10, 2024
1 parent 8dbb73f commit 96ce878
Show file tree
Hide file tree
Showing 17 changed files with 803 additions and 0 deletions.
99 changes: 99 additions & 0 deletions l10n_it_intrastat_delivery_note/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
=============================
ITA - Intrastat Delivery Note
=============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:3e3510f1efa020fc96deafc7148bb0330fc1d930017577bf2a09390cd5c5b06c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-italy/tree/16.0/l10n_it_intrastat_delivery_note
:alt: OCA/l10n-italy
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-italy-16-0/l10n-italy-16-0-l10n_it_intrastat_delivery_note
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-italy&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

**Italiano**

Questo modulo aggiunge campi mancanti alla stampa del resoconto DDT

**English**

This module adds missing fields to the DDT report print

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-italy/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_intrastat_delivery_note%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* PyTech SRL

Contributors
------------

- `PyTech SRL <https://pytech.it>`__:

- Sebastiano Picchi <[email protected]>
- Alessandro Uffreduzzi <[email protected]>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

.. |maintainer-aleuffre| image:: https://github.com/aleuffre.png?size=40px
:target: https://github.com/aleuffre
:alt: aleuffre
.. |maintainer-renda-dev| image:: https://github.com/renda-dev.png?size=40px
:target: https://github.com/renda-dev
:alt: renda-dev
.. |maintainer-PicchiSeba| image:: https://github.com/PicchiSeba.png?size=40px
:target: https://github.com/PicchiSeba
:alt: PicchiSeba

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-aleuffre| |maintainer-renda-dev| |maintainer-PicchiSeba|

This module is part of the `OCA/l10n-italy <https://github.com/OCA/l10n-italy/tree/16.0/l10n_it_intrastat_delivery_note>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions l10n_it_intrastat_delivery_note/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import post_init_hook, uninstall_hook
22 changes: 22 additions & 0 deletions l10n_it_intrastat_delivery_note/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "ITA - Intrastat Delivery Note",
"version": "16.0.1.0.0",
"category": "Hidden",
"summary": "Aggiunta campi mancanti a stampa DDT",
"author": "PyTech SRL, Odoo Community Association (OCA)",
"maintainers": ["aleuffre", "renda-dev", "PicchiSeba"],
"website": "https://github.com/OCA/l10n-italy",
"license": "AGPL-3",
"installable": True,
"depends": [
"l10n_it_delivery_note",
"l10n_it_intrastat",
],
"data": [
"report/report_delivery_document.xml",
"report/report_delivery_note.xml",
],
"demo": [],
"post_init_hook": "post_init_hook",
"uninstall_hook": "uninstall_hook",
}
43 changes: 43 additions & 0 deletions l10n_it_intrastat_delivery_note/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import logging

from odoo import SUPERUSER_ID, api, tools

_logger = logging.getLogger(__name__)


def post_init_hook(cr, registry):
# Convert 'HS Code' to an 'Intrastat code'
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
product_ids = env["product.product"].search([("hs_code", "!=", False)])
for code, products in tools.groupby(product_ids, lambda x: x.hs_code):
report_intrastat_code_id = env["report.intrastat.code"].search(

Check warning on line 14 in l10n_it_intrastat_delivery_note/hooks.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_intrastat_delivery_note/hooks.py#L14

Added line #L14 was not covered by tests
[("name", "=", code)]
)
if not report_intrastat_code_id:
_logger.warning("No Intrastat Code found for HS Code: '%s'", code)
continue

Check warning on line 19 in l10n_it_intrastat_delivery_note/hooks.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_intrastat_delivery_note/hooks.py#L18-L19

Added lines #L18 - L19 were not covered by tests

env["product.product"].browse([i.id for i in products]).write(

Check warning on line 21 in l10n_it_intrastat_delivery_note/hooks.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_intrastat_delivery_note/hooks.py#L21

Added line #L21 was not covered by tests
{
"intrastat_code_id": report_intrastat_code_id.id,
"intrastat_type": report_intrastat_code_id.type,
}
)


def uninstall_hook(cr, registry):
# Move every 'Intrastat code' to 'HS Code'
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})

Check warning on line 32 in l10n_it_intrastat_delivery_note/hooks.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_intrastat_delivery_note/hooks.py#L31-L32

Added lines #L31 - L32 were not covered by tests
if hasattr(env["product.product"], "hs_code"):
product_ids = env["product.product"].search(

Check warning on line 34 in l10n_it_intrastat_delivery_note/hooks.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_intrastat_delivery_note/hooks.py#L34

Added line #L34 was not covered by tests
[("intrastat_code_id", "!=", False), ("hs_code", "=", False)]
)

for code, products in tools.groupby(
product_ids, lambda x: x.intrastat_code_id
):
env["product.product"].browse([i.id for i in products]).write(

Check warning on line 41 in l10n_it_intrastat_delivery_note/hooks.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_intrastat_delivery_note/hooks.py#L41

Added line #L41 was not covered by tests
{"hs_code": code.name}
)
1 change: 1 addition & 0 deletions l10n_it_intrastat_delivery_note/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_move
16 changes: 16 additions & 0 deletions l10n_it_intrastat_delivery_note/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from odoo import models


class StockMoveLine(models.Model):
_inherit = "stock.move.line"

def _get_aggregated_product_quantities(self, **kwargs):
aggregated_move_lines = super()._get_aggregated_product_quantities(**kwargs)
for aggregated_move_line in aggregated_move_lines:
intrastat_code = aggregated_move_lines[aggregated_move_line][
"product"
].product_tmpl_id.intrastat_code_id.name
aggregated_move_lines[aggregated_move_line][
"intrastat_code"
] = intrastat_code
return aggregated_move_lines
3 changes: 3 additions & 0 deletions l10n_it_intrastat_delivery_note/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions l10n_it_intrastat_delivery_note/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [PyTech SRL](https://pytech.it):
- Sebastiano Picchi \<<[email protected]>\>
- Alessandro Uffreduzzi \<<[email protected]>\>
7 changes: 7 additions & 0 deletions l10n_it_intrastat_delivery_note/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**Italiano**

Questo modulo aggiunge campi mancanti alla stampa del resoconto DDT

**English**

This module adds missing fields to the DDT report print
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="report_delivery_document" inherit_id="stock.report_delivery_document">
<xpath expr="//div[hasclass('page')]" position="before">
<t
t-set="has_intrastat_code"
t-value="o.move_lines.filtered(lambda l: l.product_id.intrastat_code_id)"
/>
</xpath>
<xpath
expr="//table[@name='stock_move_table']/thead/tr/th[@name='th_sm_product']"
position="before"
>
<th name="th_sm_hs_code" t-if="has_intrastat_code">
<strong>HS Code</strong>
</th>
</xpath>
<xpath
expr="//table[@name='stock_move_line_table']/thead/tr/th[@name='th_sml_product']"
position="before"
>
<th name="th_sml_hs_code" t-if="has_intrastat_code">
<strong>HS Code</strong>
</th>
</xpath>
<xpath
expr="//table[@name='stock_backorder_table']/thead/tr/th[@name='th_sb_product']"
position="before"
>
<th name="th_sb_hs_code" t-if="has_intrastat_code">
<strong>HS Code</strong>
</th>
</xpath>

<!-- old HS Code invisible -->
<xpath
expr="//table[@name='stock_move_table']/thead/tr/th[@t-if='has_hs_code']"
position="attributes"
>
<attribute name="t-if">0</attribute>
</xpath>

<xpath
expr="//table[@name='stock_move_line_table']/thead/tr/th[@t-if='has_hs_code']"
position="attributes"
>
<attribute name="t-if">0</attribute>
</xpath>
</template>


<!-- Intrastat Code to table rows-->
<template
id="stock_report_delivery_has_serial_move_line_inherit_delivery"
inherit_id="stock.stock_report_delivery_has_serial_move_line"
>
<xpath expr="//td" position="before">
<td t-if="has_intrastat_code">
<span t-field="move_line.product_id.intrastat_code_id.name" />
</td>
</xpath>

<!-- old HS Code invisible -->
<xpath expr="//td[@t-if='has_hs_code']" position="attributes">
<attribute name="t-if">0</attribute>
</xpath>
</template>

<template
id="stock_report_delivery_aggregated_move_lines_inherit_delivery"
inherit_id="stock.stock_report_delivery_aggregated_move_lines"
>
<xpath expr="//td" position="before">
<td t-if="has_intrastat_code">
<span t-esc="aggregated_lines[line]['intrastat_code']" />
</td>
</xpath>

<!-- old HS Code invisible -->
<xpath expr="//td[@t-if='has_hs_code']" position="attributes">
<attribute name="t-if">0</attribute>
</xpath>
</template>


</odoo>
25 changes: 25 additions & 0 deletions l10n_it_intrastat_delivery_note/report/report_delivery_note.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template
id="delivery_note_report_template"
inherit_id="l10n_it_delivery_note.delivery_note_report_template"
>
<xpath expr="//table[@id='product_data']//th" position="before">
<t
t-set="has_intrastat_code"
t-value="doc.line_ids.filtered(lambda l: l.product_id.intrastat_code_id)"
/>
<th class="text-left" t-if="has_intrastat_code">
HS Code
</th>
</xpath>
<xpath
expr="//tbody[hasclass('sale_tbody')]//td[span[@t-field='line.product_id.default_code']]"
position="before"
>
<td t-if="has_intrastat_code">
<span t-field="line.product_id.intrastat_code_id.name" />
</td>
</xpath>
</template>
</odoo>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 96ce878

Please sign in to comment.