diff --git a/l10n_it_intrastat_delivery_note/README.rst b/l10n_it_intrastat_delivery_note/README.rst new file mode 100644 index 000000000000..ff81f191bf2e --- /dev/null +++ b/l10n_it_intrastat_delivery_note/README.rst @@ -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 `_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* PyTech SRL + +Contributors +------------ + +- `PyTech SRL `__: + + - Sebastiano Picchi + - Alessandro Uffreduzzi + +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 `__: + +|maintainer-aleuffre| |maintainer-renda-dev| |maintainer-PicchiSeba| + +This module is part of the `OCA/l10n-italy `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/l10n_it_intrastat_delivery_note/__init__.py b/l10n_it_intrastat_delivery_note/__init__.py new file mode 100644 index 000000000000..1a9a001cf76a --- /dev/null +++ b/l10n_it_intrastat_delivery_note/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import post_init_hook, uninstall_hook diff --git a/l10n_it_intrastat_delivery_note/__manifest__.py b/l10n_it_intrastat_delivery_note/__manifest__.py new file mode 100644 index 000000000000..74d7f6f9298c --- /dev/null +++ b/l10n_it_intrastat_delivery_note/__manifest__.py @@ -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", +} diff --git a/l10n_it_intrastat_delivery_note/hooks.py b/l10n_it_intrastat_delivery_note/hooks.py new file mode 100644 index 000000000000..cb122a323664 --- /dev/null +++ b/l10n_it_intrastat_delivery_note/hooks.py @@ -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( + [("name", "=", code)] + ) + if not report_intrastat_code_id: + _logger.warning("No Intrastat Code found for HS Code: '%s'", code) + continue + + env["product.product"].browse([i.id for i in products]).write( + { + "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, {}) + if hasattr(env["product.product"], "hs_code"): + product_ids = env["product.product"].search( + [("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( + {"hs_code": code.name} + ) diff --git a/l10n_it_intrastat_delivery_note/models/__init__.py b/l10n_it_intrastat_delivery_note/models/__init__.py new file mode 100644 index 000000000000..6bda2d2428e0 --- /dev/null +++ b/l10n_it_intrastat_delivery_note/models/__init__.py @@ -0,0 +1 @@ +from . import stock_move diff --git a/l10n_it_intrastat_delivery_note/models/stock_move.py b/l10n_it_intrastat_delivery_note/models/stock_move.py new file mode 100644 index 000000000000..f066f380fa61 --- /dev/null +++ b/l10n_it_intrastat_delivery_note/models/stock_move.py @@ -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_id" + ] = intrastat_code + return aggregated_move_lines diff --git a/l10n_it_intrastat_delivery_note/pyproject.toml b/l10n_it_intrastat_delivery_note/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/l10n_it_intrastat_delivery_note/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/l10n_it_intrastat_delivery_note/readme/CONTRIBUTORS.md b/l10n_it_intrastat_delivery_note/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..3ed70787dc0b --- /dev/null +++ b/l10n_it_intrastat_delivery_note/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [PyTech SRL](https://pytech.it): + - Sebastiano Picchi \<\> + - Alessandro Uffreduzzi \<\> diff --git a/l10n_it_intrastat_delivery_note/readme/DESCRIPTION.md b/l10n_it_intrastat_delivery_note/readme/DESCRIPTION.md new file mode 100644 index 000000000000..163a139f6478 --- /dev/null +++ b/l10n_it_intrastat_delivery_note/readme/DESCRIPTION.md @@ -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 diff --git a/l10n_it_intrastat_delivery_note/report/report_delivery_document.xml b/l10n_it_intrastat_delivery_note/report/report_delivery_document.xml new file mode 100644 index 000000000000..2e292b6830aa --- /dev/null +++ b/l10n_it_intrastat_delivery_note/report/report_delivery_document.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + diff --git a/l10n_it_intrastat_delivery_note/report/report_delivery_note.xml b/l10n_it_intrastat_delivery_note/report/report_delivery_note.xml new file mode 100644 index 000000000000..4952dab61ac7 --- /dev/null +++ b/l10n_it_intrastat_delivery_note/report/report_delivery_note.xml @@ -0,0 +1,25 @@ + + + + diff --git a/l10n_it_intrastat_delivery_note/static/description/icon.png b/l10n_it_intrastat_delivery_note/static/description/icon.png new file mode 100644 index 000000000000..3642c5fa1f98 Binary files /dev/null and b/l10n_it_intrastat_delivery_note/static/description/icon.png differ diff --git a/l10n_it_intrastat_delivery_note/static/description/index.html b/l10n_it_intrastat_delivery_note/static/description/index.html new file mode 100644 index 000000000000..5c87ebc9cdfc --- /dev/null +++ b/l10n_it_intrastat_delivery_note/static/description/index.html @@ -0,0 +1,432 @@ + + + + + +ITA - Intrastat Delivery Note + + + +
+

ITA - Intrastat Delivery Note

+ + +

Beta License: AGPL-3 OCA/l10n-italy Translate me on Weblate Try me on Runboat

+

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

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • PyTech SRL
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

Current maintainers:

+

aleuffre renda-dev PicchiSeba

+

This module is part of the OCA/l10n-italy project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/l10n_it_intrastat_delivery_note/tests/__init__.py b/l10n_it_intrastat_delivery_note/tests/__init__.py new file mode 100644 index 000000000000..4b33b6f53cee --- /dev/null +++ b/l10n_it_intrastat_delivery_note/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_move diff --git a/l10n_it_intrastat_delivery_note/tests/test_stock_move.py b/l10n_it_intrastat_delivery_note/tests/test_stock_move.py new file mode 100644 index 000000000000..67089fd33b03 --- /dev/null +++ b/l10n_it_intrastat_delivery_note/tests/test_stock_move.py @@ -0,0 +1,56 @@ +from odoo.tests import Form +from odoo.tests.common import TransactionCase + + +class TestStockMove(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.ProductTemplate = cls.env["product.template"] + + cls.partner = cls.env.ref("base.partner_admin") + cls.stock_location = cls.env.ref("stock.stock_location_stock") + cls.customer_location = cls.env.ref("stock.stock_location_customers") + cls.uom_unit = cls.env.ref("uom.product_uom_unit") + cls.product = cls.ProductTemplate.search( + [("intrastat_code_id", "!=", False)] + ).product_variant_ids[:1] + + def test_move_lines_aggregated(self): + self.assertEqual(len(self.product), 1) + self.env["stock.quant"]._update_available_quantity( + self.product, self.stock_location, 25 + ) + picking = self.env["stock.picking"].create( + { + "location_id": self.stock_location.id, + "location_dest_id": self.customer_location.id, + "picking_type_id": self.env.ref("stock.picking_type_out").id, + } + ) + move1 = self.env["stock.move"].create( + { + "name": "test_transit_1", + "location_id": self.stock_location.id, + "location_dest_id": self.customer_location.id, + "product_id": self.product.id, + "product_uom": self.uom_unit.id, + "product_uom_qty": 15.0, + "picking_id": picking.id, + "picking_type_id": self.env.ref("stock.picking_type_out").id, + } + ) + move1.quantity_done = 5 + picking.action_put_in_pack() + + with Form(picking) as delivery_form: + delivery_form.partner_id = self.partner + delivery_form.save() + + aggregate_values = picking.move_line_ids._get_aggregated_product_quantities() + self.assertTrue(bool(aggregate_values)) + for v in aggregate_values.values(): + self.assertEqual( + v["product"].product_tmpl_id.intrastat_code_id.name, + v["intrastat_code_id"], + ) diff --git a/setup/l10n_it_intrastat_delivery_note/odoo/addons/l10n_it_intrastat_delivery_note b/setup/l10n_it_intrastat_delivery_note/odoo/addons/l10n_it_intrastat_delivery_note new file mode 120000 index 000000000000..be9bd5663ca1 --- /dev/null +++ b/setup/l10n_it_intrastat_delivery_note/odoo/addons/l10n_it_intrastat_delivery_note @@ -0,0 +1 @@ +../../../../l10n_it_intrastat_delivery_note \ No newline at end of file diff --git a/setup/l10n_it_intrastat_delivery_note/setup.py b/setup/l10n_it_intrastat_delivery_note/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/l10n_it_intrastat_delivery_note/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)