diff --git a/account_move_report_secondary_unit/README.rst b/account_move_report_secondary_unit/README.rst new file mode 100644 index 000000000..fd0f223aa --- /dev/null +++ b/account_move_report_secondary_unit/README.rst @@ -0,0 +1,77 @@ +================================== +Account Move Report Secondary Unit +================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:8cf5eaff8f6fcf63c15ef76d903937fd3d4b61ed5c42ddffb3953b4b85c84919 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--invoice--reporting-lightgray.png?logo=github + :target: https://github.com/OCA/account-invoice-reporting/tree/18.0/account_move_report_secondary_unit + :alt: OCA/account-invoice-reporting +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-invoice-reporting-18-0/account-invoice-reporting-18-0-account_move_report_secondary_unit + :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/account-invoice-reporting&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Show the secondary unit of measure and the secondary quantity in invoice +reports + +**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 +------- + +* Solvos + +Contributors +------------ + +- Iria Alonso + +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. + +This module is part of the `OCA/account-invoice-reporting `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_move_report_secondary_unit/__init__.py b/account_move_report_secondary_unit/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/account_move_report_secondary_unit/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_move_report_secondary_unit/__manifest__.py b/account_move_report_secondary_unit/__manifest__.py new file mode 100644 index 000000000..e97b3630b --- /dev/null +++ b/account_move_report_secondary_unit/__manifest__.py @@ -0,0 +1,16 @@ +# © 2026 Solvos Consultoría Informática () +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +{ + "name": "Account Move Report Secondary Unit", + "summary": """ + Show the secondary unit of measure and the secondary quantity in invoice reports + """, + "author": "Solvos, Odoo Community Association (OCA)", + "license": "AGPL-3", + "version": "18.0.1.0.0", + "category": "Sales/Sales", + "website": "https://github.com/OCA/account-invoice-reporting", + "depends": ["sale_order_secondary_unit"], + "data": ["report/report_invoice_document.xml"], + "installable": True, +} diff --git a/account_move_report_secondary_unit/i18n/account_move_report_secondary_unit.pot b/account_move_report_secondary_unit/i18n/account_move_report_secondary_unit.pot new file mode 100644 index 000000000..b0eae6e49 --- /dev/null +++ b/account_move_report_secondary_unit/i18n/account_move_report_secondary_unit.pot @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_report_secondary_unit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-04-08 13:40+0000\n" +"PO-Revision-Date: 2025-04-08 13:40+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_move_report_secondary_unit +#: model_terms:ir.ui.view,arch_db:account_move_report_secondary_unit.report_invoice_document +msgid "Second. Qty" +msgstr "" + +#. module: account_move_report_secondary_unit +#: model:ir.model,name:account_move_report_secondary_unit.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: account_move_report_secondary_unit +#: model:ir.model.fields,field_description:account_move_report_secondary_unit.field_account_move_line__secondary_uom_id +msgid "Secondary Uom" +msgstr "" + +#. module: account_move_report_secondary_unit +#: model:ir.model.fields,field_description:account_move_report_secondary_unit.field_account_move_line__secondary_uom_qty +msgid "Secondary Uom Qty" +msgstr "" diff --git a/account_move_report_secondary_unit/i18n/es.po b/account_move_report_secondary_unit/i18n/es.po new file mode 100644 index 000000000..ebc29cdef --- /dev/null +++ b/account_move_report_secondary_unit/i18n/es.po @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_report_secondary_unit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-04-08 13:40+0000\n" +"PO-Revision-Date: 2025-04-08 13:40+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_move_report_secondary_unit +#: model_terms:ir.ui.view,arch_db:account_move_report_secondary_unit.report_invoice_document +msgid "Second. Qty" +msgstr "Cant. sec." + +#. module: account_move_report_secondary_unit +#: model:ir.model,name:account_move_report_secondary_unit.model_account_move_line +msgid "Journal Item" +msgstr "Apunte contable" + +#. module: account_move_report_secondary_unit +#: model:ir.model.fields,field_description:account_move_report_secondary_unit.field_account_move_line__secondary_uom_id +msgid "Secondary Uom" +msgstr "" + +#. module: account_move_report_secondary_unit +#: model:ir.model.fields,field_description:account_move_report_secondary_unit.field_account_move_line__secondary_uom_qty +msgid "Secondary Uom Qty" +msgstr "" diff --git a/account_move_report_secondary_unit/models/__init__.py b/account_move_report_secondary_unit/models/__init__.py new file mode 100644 index 000000000..8795b3bea --- /dev/null +++ b/account_move_report_secondary_unit/models/__init__.py @@ -0,0 +1 @@ +from . import account_move_line diff --git a/account_move_report_secondary_unit/models/account_move_line.py b/account_move_report_secondary_unit/models/account_move_line.py new file mode 100644 index 000000000..539b0d703 --- /dev/null +++ b/account_move_report_secondary_unit/models/account_move_line.py @@ -0,0 +1,33 @@ +# © 2026 Solvos Consultoría Informática () +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import api, fields, models + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + secondary_uom_id = fields.Many2one( + comodel_name="product.secondary.unit", + compute="_compute_secondary_uom_id", + ) + + secondary_uom_qty = fields.Float( + compute="_compute_secondary_uom_id", digits="Product Unit of Measure" + ) + + @api.depends( + "product_id.sale_secondary_uom_id", + "product_id.sale_secondary_uom_id.factor", + "sale_line_ids.secondary_uom_id", + ) + def _compute_secondary_uom_id(self): + for record in self: + secondary_unit = ( + record.sale_line_ids[:1].secondary_uom_id + or record.product_id.sale_secondary_uom_id + ) + record.secondary_uom_id = secondary_unit + + if secondary_unit and secondary_unit.factor: + record.secondary_uom_qty = record.quantity / secondary_unit.factor diff --git a/account_move_report_secondary_unit/pyproject.toml b/account_move_report_secondary_unit/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/account_move_report_secondary_unit/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_move_report_secondary_unit/readme/CONTRIBUTORS.md b/account_move_report_secondary_unit/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..1f43251f4 --- /dev/null +++ b/account_move_report_secondary_unit/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +* Iria Alonso \ diff --git a/account_move_report_secondary_unit/readme/DESCRIPTION.md b/account_move_report_secondary_unit/readme/DESCRIPTION.md new file mode 100644 index 000000000..1409a56ab --- /dev/null +++ b/account_move_report_secondary_unit/readme/DESCRIPTION.md @@ -0,0 +1 @@ +Show the secondary unit of measure and the secondary quantity in invoice reports diff --git a/account_move_report_secondary_unit/report/report_invoice_document.xml b/account_move_report_secondary_unit/report/report_invoice_document.xml new file mode 100644 index 000000000..9c97723ad --- /dev/null +++ b/account_move_report_secondary_unit/report/report_invoice_document.xml @@ -0,0 +1,28 @@ + + + diff --git a/account_move_report_secondary_unit/static/description/icon.png b/account_move_report_secondary_unit/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_move_report_secondary_unit/static/description/icon.png differ diff --git a/account_move_report_secondary_unit/static/description/index.html b/account_move_report_secondary_unit/static/description/index.html new file mode 100644 index 000000000..867668e07 --- /dev/null +++ b/account_move_report_secondary_unit/static/description/index.html @@ -0,0 +1,424 @@ + + + + + +Account Move Report Secondary Unit + + + +
+

Account Move Report Secondary Unit

+ + +

Beta License: LGPL-3 OCA/account-invoice-reporting Translate me on Weblate Try me on Runboat

+

Show the secondary unit of measure and the secondary quantity in invoice +reports

+

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

+
    +
  • Solvos
  • +
+
+
+

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.

+

This module is part of the OCA/account-invoice-reporting project on GitHub.

+

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

+
+
+
+ + diff --git a/account_move_report_secondary_unit/tests/__init__.py b/account_move_report_secondary_unit/tests/__init__.py new file mode 100644 index 000000000..3487bb5f1 --- /dev/null +++ b/account_move_report_secondary_unit/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_move_line diff --git a/account_move_report_secondary_unit/tests/test_account_move_line.py b/account_move_report_secondary_unit/tests/test_account_move_line.py new file mode 100644 index 000000000..55cf454ff --- /dev/null +++ b/account_move_report_secondary_unit/tests/test_account_move_line.py @@ -0,0 +1,115 @@ +# © 2026 Solvos Consultoría Informática () +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + + +from odoo.fields import Command +from odoo.tests.common import TransactionCase, tagged + + +@tagged("post_install", "-at_install") +class TestStockMoveWarehouseView(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.product_template = cls.env["product.template"].create( + { + "name": "Producto Test", + "type": "consu", + } + ) + cls.product = cls.product_template.product_variant_id + + cls.secondary_unit_box = cls.env["product.secondary.unit"].create( + { + "name": "Caja 10", + "factor": 10.0, + "product_tmpl_id": cls.product_template.id, + "uom_id": cls.product_template.uom_id.id, + } + ) + + cls.secondary_unit_pallet = cls.env["product.secondary.unit"].create( + { + "name": "Pallet 100", + "factor": 100.0, + "product_tmpl_id": cls.product_template.id, + "uom_id": cls.product_template.uom_id.id, + } + ) + + cls.product_template.sale_secondary_uom_id = cls.secondary_unit_box.id + + cls.partner = cls.env["res.partner"].create({"name": "Cliente Test"}) + + def test_01_fallback_to_product_unit(self): + invoice = self.env["account.move"].create( + { + "move_type": "out_invoice", + "partner_id": self.partner.id, + "invoice_line_ids": [ + Command.create( + { + "product_id": self.product.id, + "quantity": 50.0, + } + ) + ], + } + ) + line = invoice.invoice_line_ids[0] + + self.assertEqual(line.secondary_uom_id, self.secondary_unit_box) + self.assertAlmostEqual(line.secondary_uom_qty, 5.0) + + def test_02_priority_sale_line(self): + sale_order = self.env["sale.order"].create( + { + "partner_id": self.partner.id, + "order_line": [ + Command.create( + { + "product_id": self.product.id, + "product_uom_qty": 200.0, + "secondary_uom_id": self.secondary_unit_pallet.id, + } + ) + ], + } + ) + sale_order.action_confirm() + + invoice = sale_order._create_invoices() + + if isinstance(invoice, dict): + invoice = self.env["account.move"].browse(invoice.get("res_id")) + + line = invoice.invoice_line_ids.filtered(lambda x: x.display_type == "product")[ + :1 + ] + + self.assertEqual(line.secondary_uom_id, self.secondary_unit_pallet) + self.assertAlmostEqual(line.secondary_uom_qty, 2.0) + + def test_03_manual_change(self): + invoice = self.env["account.move"].create( + { + "move_type": "out_invoice", + "partner_id": self.partner.id, + "invoice_line_ids": [ + Command.create( + { + "product_id": self.product.id, + "quantity": 100.0, + } + ) + ], + } + ) + line = invoice.invoice_line_ids[0] + self.assertEqual(line.secondary_uom_qty, 10.0) + + line.quantity = 250.0 + line._compute_secondary_uom_id() + + self.assertEqual(line.secondary_uom_qty, 25.0)