diff --git a/purchase_order_uninvoiced_amount_line/README.rst b/purchase_order_uninvoiced_amount_line/README.rst new file mode 100644 index 00000000000..c1066f31498 --- /dev/null +++ b/purchase_order_uninvoiced_amount_line/README.rst @@ -0,0 +1,86 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +===================================== +Purchase Order Line Uninvoiced Amount +===================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:138b5d5b42e3809c85e1cdf1ee9c4c5a6301960d702acfeb2bd96922c43ba3aa + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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%2Fpurchase--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/purchase-workflow/tree/19.0/purchase_order_uninvoiced_amount_line + :alt: OCA/purchase-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/purchase-workflow-19-0/purchase-workflow-19-0-purchase_order_uninvoiced_amount_line + :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/purchase-workflow&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Show uninvoiced amount on purchase order line tree. + +**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 +------- + +* ForgeFlow + +Contributors +------------ + +- `ForgeFlow `__: + + - Joan Sisquella + +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia + +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/purchase-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_order_uninvoiced_amount_line/__init__.py b/purchase_order_uninvoiced_amount_line/__init__.py new file mode 100644 index 00000000000..6f937c0c0cd --- /dev/null +++ b/purchase_order_uninvoiced_amount_line/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/purchase_order_uninvoiced_amount_line/__manifest__.py b/purchase_order_uninvoiced_amount_line/__manifest__.py new file mode 100644 index 00000000000..e1e2bc1fb3d --- /dev/null +++ b/purchase_order_uninvoiced_amount_line/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Purchase Order Line Uninvoiced Amount", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "version": "19.0.1.0.0", + "development_status": "Beta", + "website": "https://github.com/OCA/purchase-workflow", + "category": "Purchase", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["purchase", "purchase_order_line_menu"], + "data": ["views/purchase_order_line_views.xml"], +} diff --git a/purchase_order_uninvoiced_amount_line/i18n/it.po b/purchase_order_uninvoiced_amount_line/i18n/it.po new file mode 100644 index 00000000000..a30c824f3b2 --- /dev/null +++ b/purchase_order_uninvoiced_amount_line/i18n/it.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_uninvoiced_amount_line +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-09-16 10:20+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.10.4\n" + +#. module: purchase_order_uninvoiced_amount_line +#: model:ir.model,name:purchase_order_uninvoiced_amount_line.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "Riga ordine di acquisto" + +#. module: purchase_order_uninvoiced_amount_line +#: model:ir.model.fields,field_description:purchase_order_uninvoiced_amount_line.field_purchase_order_line__amount_uninvoiced +#: model_terms:ir.ui.view,arch_db:purchase_order_uninvoiced_amount_line.purchase_order_line_tree_uninvoiced +msgid "Uninvoiced Amount" +msgstr "Importo non fatturato" diff --git a/purchase_order_uninvoiced_amount_line/i18n/purchase_order_uninvoiced_amount_line.pot b/purchase_order_uninvoiced_amount_line/i18n/purchase_order_uninvoiced_amount_line.pot new file mode 100644 index 00000000000..828d9e65f77 --- /dev/null +++ b/purchase_order_uninvoiced_amount_line/i18n/purchase_order_uninvoiced_amount_line.pot @@ -0,0 +1,25 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_uninvoiced_amount_line +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \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: purchase_order_uninvoiced_amount_line +#: model:ir.model,name:purchase_order_uninvoiced_amount_line.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "" + +#. module: purchase_order_uninvoiced_amount_line +#: model:ir.model.fields,field_description:purchase_order_uninvoiced_amount_line.field_purchase_order_line__amount_uninvoiced +#: model_terms:ir.ui.view,arch_db:purchase_order_uninvoiced_amount_line.purchase_order_line_tree_uninvoiced +msgid "Uninvoiced Amount" +msgstr "" diff --git a/purchase_order_uninvoiced_amount_line/models/__init__.py b/purchase_order_uninvoiced_amount_line/models/__init__.py new file mode 100644 index 00000000000..d70b8833432 --- /dev/null +++ b/purchase_order_uninvoiced_amount_line/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import purchase_order_line diff --git a/purchase_order_uninvoiced_amount_line/models/purchase_order_line.py b/purchase_order_uninvoiced_amount_line/models/purchase_order_line.py new file mode 100644 index 00000000000..5ad2c9453a4 --- /dev/null +++ b/purchase_order_uninvoiced_amount_line/models/purchase_order_line.py @@ -0,0 +1,39 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + + @api.depends( + "product_qty", + "qty_invoiced", + "qty_received", + "product_id", + "product_uom_id", + "price_unit", + "price_subtotal", + ) + def _compute_amount_uninvoiced(self): + for line in self: + if line.product_id.purchase_method == "purchase": + qty = line.product_qty - line.qty_invoiced + else: + qty = line.qty_received - line.qty_invoiced + price_unit = ( + line.price_subtotal / line.product_qty + if line.product_qty + else line.price_unit + ) + amount_uninvoiced = max(0, qty * price_unit) + line.amount_uninvoiced = line.currency_id.round(amount_uninvoiced) + + amount_uninvoiced = fields.Monetary( + string="Uninvoiced Amount", + readonly=True, + compute="_compute_amount_uninvoiced", + store=True, + currency_field="currency_id", + ) diff --git a/purchase_order_uninvoiced_amount_line/pyproject.toml b/purchase_order_uninvoiced_amount_line/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/purchase_order_uninvoiced_amount_line/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/purchase_order_uninvoiced_amount_line/readme/CONTRIBUTORS.md b/purchase_order_uninvoiced_amount_line/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..0060b85dbf9 --- /dev/null +++ b/purchase_order_uninvoiced_amount_line/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- [ForgeFlow](https://www.forgeflow.com): + - Joan Sisquella +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/purchase_order_uninvoiced_amount_line/readme/DESCRIPTION.md b/purchase_order_uninvoiced_amount_line/readme/DESCRIPTION.md new file mode 100644 index 00000000000..1c66c995274 --- /dev/null +++ b/purchase_order_uninvoiced_amount_line/readme/DESCRIPTION.md @@ -0,0 +1 @@ +Show uninvoiced amount on purchase order line tree. diff --git a/purchase_order_uninvoiced_amount_line/static/description/icon.png b/purchase_order_uninvoiced_amount_line/static/description/icon.png new file mode 100644 index 00000000000..1dcc49c24f3 Binary files /dev/null and b/purchase_order_uninvoiced_amount_line/static/description/icon.png differ diff --git a/purchase_order_uninvoiced_amount_line/static/description/index.html b/purchase_order_uninvoiced_amount_line/static/description/index.html new file mode 100644 index 00000000000..40a011eea22 --- /dev/null +++ b/purchase_order_uninvoiced_amount_line/static/description/index.html @@ -0,0 +1,436 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Purchase Order Line Uninvoiced Amount

+ +

Beta License: AGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runboat

+

Show uninvoiced amount on purchase order line tree.

+

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

+
    +
  • ForgeFlow
  • +
+
+
+

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/purchase-workflow project on GitHub.

+

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

+
+
+
+
+ + diff --git a/purchase_order_uninvoiced_amount_line/tests/__init__.py b/purchase_order_uninvoiced_amount_line/tests/__init__.py new file mode 100644 index 00000000000..7263c649b3e --- /dev/null +++ b/purchase_order_uninvoiced_amount_line/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_purchase_order_line_uninvoiced_amount diff --git a/purchase_order_uninvoiced_amount_line/tests/test_purchase_order_line_uninvoiced_amount.py b/purchase_order_uninvoiced_amount_line/tests/test_purchase_order_line_uninvoiced_amount.py new file mode 100644 index 00000000000..dd2b831e91b --- /dev/null +++ b/purchase_order_uninvoiced_amount_line/tests/test_purchase_order_line_uninvoiced_amount.py @@ -0,0 +1,234 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import fields +from odoo.tests import Form + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon + + +class TestPurchaseOrderLineUninvoiceAmount(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + if not cls.company_data.get("default_journal_purchase"): + cls.company_data["default_account_payable"] = cls.env[ + "account.account" + ].create( + { + "name": "Payable", + "code": "PAY", + "account_type": "liability_payable", + } + ) + cls.company_data["default_account_expense"] = cls.env[ + "account.account" + ].create( + { + "name": "Expense", + "code": "EXP", + "account_type": "expense", + } + ) + cls.company_data["default_account_receivable"] = cls.env[ + "account.account" + ].create( + { + "name": "Receivable", + "code": "REC", + "account_type": "asset_receivable", + } + ) + cls.company_data["default_journal_purchase"] = cls.env[ + "account.journal" + ].create( + { + "name": "Purchase Journal", + "type": "purchase", + "code": "PJ", + "default_account_id": cls.company_data[ + "default_account_expense" + ].id, + } + ) + cls.purchase_order_model = cls.env["purchase.order"] + cls.purchase_order_line_model = cls.env["purchase.order.line"] + cls.account_move_model = cls.env["account.move"] + cls.res_partner_model = cls.env["res.partner"] + cls.product_product_model = cls.env["product.product"] + cls.product_category_model = cls.env["product.category"] + cls.company = cls.env.ref("base.main_company") + cls.partner = cls.res_partner_model.create( + { + "name": "Partner 1", + "property_account_receivable_id": cls.company_data[ + "default_account_receivable" + ].id, + "property_account_payable_id": cls.company_data[ + "default_account_payable" + ].id, + "supplier_rank": 1, + "is_company": True, + } + ) + cls.product_categ = cls.product_category_model.create({"name": "Test category"}) + cls.uom1 = cls.env["uom.uom"].create( + { + "name": "UOM 1", + "relative_factor": 1, + "active": True, + } + ) + # Products + cls.product_category = cls.env["product.category"].create( + {"name": "Test Product category"} + ) + cls.product_1 = cls.env["product.product"].create( + { + "name": "Test Product 1", + "sale_ok": True, + "type": "consu", + "categ_id": cls.product_category.id, + "description_sale": "Test Description Sale", + "purchase_method": "receive", + } + ) + cls.product_2 = cls.env["product.product"].create( + { + "name": "Test Product 2", + "sale_ok": True, + "type": "consu", + "categ_id": cls.product_category.id, + "description_sale": "Test Description Sale 2", + "purchase_method": "purchase", + } + ) + + def _create_purchase_with_lines(self, lines_data): + purchase = self.purchase_order_model.create( + {"company_id": self.company.id, "partner_id": self.partner.id} + ) + lines = [] + for line_data in lines_data: + line = self.purchase_order_line_model.create( + { + "name": line_data["product"].name, + "product_id": line_data["product"].id, + "product_qty": line_data["qty"], + "product_uom_id": line_data["product"].uom_id.id, + "price_unit": line_data["price"], + "date_planned": fields.Date.today(), + "order_id": purchase.id, + } + ) + lines.append(line) + + purchase.button_confirm() + for i, line in enumerate(lines): + line.qty_received = lines_data[i]["received"] + return purchase, lines + + def _create_invoice_from_purchase(self, purchase): + res = purchase.action_create_invoice() + return self.env["account.move"].browse(res["res_id"]) + + def test_single_line_not_invoiced(self): + purchase, lines = self._create_purchase_with_lines( + [{"product": self.product_1, "qty": 5, "received": 5, "price": 100.0}] + ) + line = lines[0] + self.assertEqual(line.amount_uninvoiced, 500.0) + self.assertEqual(line.invoice_status, "to invoice") + + def test_single_line_no_receive(self): + purchase, lines = self._create_purchase_with_lines( + [{"product": self.product_1, "qty": 5, "received": 0, "price": 100.0}] + ) + line = lines[0] + self.assertEqual(line.amount_uninvoiced, 0.0) + + def test_single_line_partial_invoice(self): + purchase, lines = self._create_purchase_with_lines( + [{"product": self.product_1, "qty": 10, "received": 10, "price": 50.0}] + ) + line = lines[0] + self.assertEqual(line.amount_uninvoiced, 500.0) + invoice = self._create_invoice_from_purchase(purchase) + with Form(invoice) as invoice_form: + with invoice_form.invoice_line_ids.edit(0) as line_form: + line_form.quantity = 6 + self.assertEqual(line.amount_uninvoiced, 200.0) + + def test_single_line_fully_invoiced(self): + purchase, lines = self._create_purchase_with_lines( + [{"product": self.product_1, "qty": 3, "received": 3, "price": 75.0}] + ) + line = lines[0] + self._create_invoice_from_purchase(purchase) + self.assertEqual(line.amount_uninvoiced, 0.0) + + def test_multiple_lines_different_amounts(self): + purchase, lines = self._create_purchase_with_lines( + [ + {"product": self.product_1, "qty": 5, "received": 5, "price": 100.0}, + {"product": self.product_2, "qty": 3, "received": 2, "price": 200.0}, + ] + ) + line1, line2 = lines + # Line 1: receive policy, 5 received - 0 invoiced = 5 * 100 = 500 + self.assertEqual(line1.amount_uninvoiced, 500.0) + # Line 2: purchase policy, 3 ordered - 0 invoiced = 3 * 200 = 600 + self.assertEqual(line2.amount_uninvoiced, 600.0) + + def test_on_ordered_quantities_policy(self): + purchase, lines = self._create_purchase_with_lines( + [{"product": self.product_2, "qty": 10, "received": 0, "price": 60.0}] + ) + line = lines[0] + self.assertEqual(line.amount_uninvoiced, 600.0) + invoice = self._create_invoice_from_purchase(purchase) + with Form(invoice) as invoice_form: + with invoice_form.invoice_line_ids.edit(0) as line_form: + line_form.quantity = 4 + self.assertEqual(line.amount_uninvoiced, 360.0) + + def test_zero_quantity_line(self): + purchase, lines = self._create_purchase_with_lines( + [{"product": self.product_1, "qty": 0, "received": 0, "price": 100.0}] + ) + line = lines[0] + self.assertEqual(line.amount_uninvoiced, 0.0) + + def test_over_invoicing(self): + purchase, lines = self._create_purchase_with_lines( + [{"product": self.product_1, "qty": 5, "received": 5, "price": 80.0}] + ) + line = lines[0] + invoice = self._create_invoice_from_purchase(purchase) + with Form(invoice) as invoice_form: + with invoice_form.invoice_line_ids.edit(0) as line_form: + line_form.quantity = 8 + # Over-invoicing should result in 0, not negative + self.assertEqual(line.amount_uninvoiced, 0.0) + + def test_mixed_policies_multiple_lines(self): + self.product_1.purchase_method = "receive" + self.product_2.purchase_method = "purchase" + purchase, lines = self._create_purchase_with_lines( + [ + {"product": self.product_1, "qty": 10, "received": 8, "price": 25.0}, + {"product": self.product_2, "qty": 6, "received": 3, "price": 150.0}, + ] + ) + + line1, line2 = lines + self.assertEqual(line1.amount_uninvoiced, 200.0) + self.assertEqual(line2.amount_uninvoiced, 900.0) + invoice = self._create_invoice_from_purchase(purchase) + with Form(invoice) as invoice_form: + with invoice_form.invoice_line_ids.edit(0) as line_form: + line_form.quantity = 5 + with invoice_form.invoice_line_ids.edit(1) as line_form: + line_form.quantity = 2 + self.assertEqual(line1.amount_uninvoiced, 75.0) + self.assertEqual(line2.amount_uninvoiced, 600.0) diff --git a/purchase_order_uninvoiced_amount_line/views/purchase_order_line_views.xml b/purchase_order_uninvoiced_amount_line/views/purchase_order_line_views.xml new file mode 100644 index 00000000000..873a1cee68d --- /dev/null +++ b/purchase_order_uninvoiced_amount_line/views/purchase_order_line_views.xml @@ -0,0 +1,23 @@ + + + + + purchase.order.line.tree.uninvoiced + purchase.order.line + + + + + + + + diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 00000000000..a7834895fb8 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-purchase_order_line_menu @ git+https://github.com/OCA/purchase-workflow.git@refs/pull/2846/head#subdirectory=purchase_order_line_menu