From f11e02cd1c1bd462ba15f5f80f7811213b1f84e0 Mon Sep 17 00:00:00 2001 From: Eric Antones Date: Mon, 27 Apr 2026 15:03:12 +0200 Subject: [PATCH] [ADD] sale_invoice_partial_lines Mark sale order lines and invoice only the marked ones. Adds a generic boolean ``selected`` on ``sale.order.line`` and an "Only selected lines" checkbox on the standard ``sale.advance.payment.inv`` wizard. When the wizard runs with that flag, ``_get_invoiceable_lines`` narrows core's regular invoiceable result to the selected lines (sections and down-payments handled like core), and ``selected`` is reset on the just-invoiced lines. Useful for long quotations where the customer wants to invoice subsets instead of the full order. --- sale_invoice_partial_lines/README.rst | 72 +++ sale_invoice_partial_lines/__init__.py | 2 + sale_invoice_partial_lines/__manifest__.py | 19 + sale_invoice_partial_lines/i18n/ca.po | 77 ++++ sale_invoice_partial_lines/i18n/es.po | 76 +++ sale_invoice_partial_lines/models/__init__.py | 2 + .../models/sale_order.py | 73 +++ .../models/sale_order_line.py | 15 + .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 7 + .../static/description/icon.png | Bin 0 -> 6342 bytes .../static/description/index.html | 433 ++++++++++++++++++ sale_invoice_partial_lines/tests/__init__.py | 1 + .../tests/test_sale_invoice_partial_lines.py | 223 +++++++++ .../views/sale_order_views.xml | 40 ++ .../wizards/__init__.py | 1 + .../wizards/sale_advance_payment_inv.py | 46 ++ .../sale_advance_payment_inv_views.xml | 20 + .../odoo/addons/sale_invoice_partial_lines | 1 + setup/sale_invoice_partial_lines/setup.py | 6 + 20 files changed, 1117 insertions(+) create mode 100644 sale_invoice_partial_lines/README.rst create mode 100644 sale_invoice_partial_lines/__init__.py create mode 100644 sale_invoice_partial_lines/__manifest__.py create mode 100644 sale_invoice_partial_lines/i18n/ca.po create mode 100644 sale_invoice_partial_lines/i18n/es.po create mode 100644 sale_invoice_partial_lines/models/__init__.py create mode 100644 sale_invoice_partial_lines/models/sale_order.py create mode 100644 sale_invoice_partial_lines/models/sale_order_line.py create mode 100644 sale_invoice_partial_lines/readme/CONTRIBUTORS.rst create mode 100644 sale_invoice_partial_lines/readme/DESCRIPTION.rst create mode 100644 sale_invoice_partial_lines/static/description/icon.png create mode 100644 sale_invoice_partial_lines/static/description/index.html create mode 100644 sale_invoice_partial_lines/tests/__init__.py create mode 100644 sale_invoice_partial_lines/tests/test_sale_invoice_partial_lines.py create mode 100644 sale_invoice_partial_lines/views/sale_order_views.xml create mode 100644 sale_invoice_partial_lines/wizards/__init__.py create mode 100644 sale_invoice_partial_lines/wizards/sale_advance_payment_inv.py create mode 100644 sale_invoice_partial_lines/wizards/sale_advance_payment_inv_views.xml create mode 120000 setup/sale_invoice_partial_lines/odoo/addons/sale_invoice_partial_lines create mode 100644 setup/sale_invoice_partial_lines/setup.py diff --git a/sale_invoice_partial_lines/README.rst b/sale_invoice_partial_lines/README.rst new file mode 100644 index 000000000..cb3072769 --- /dev/null +++ b/sale_invoice_partial_lines/README.rst @@ -0,0 +1,72 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +========================== +Sale Invoice Partial Lines +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:845f09508565b18e27ed0f7fb04ba3e072aa6f830076626db730f48fa2848d7c + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-nuobit%2Fodoo--addons-lightgray.png?logo=github + :target: https://github.com/nuobit/odoo-addons/tree/16.0/sale_invoice_partial_lines + :alt: nuobit/odoo-addons + +|badge1| |badge2| |badge3| + +* Add a per-line ``Selected`` checkbox on sale orders so users can pick + which lines go into the next regular invoice. +* Persist the selection in the database, so it survives pagination, + refreshes, and closing the browser. +* Extend the standard *Create Invoice* wizard with an ``Only selected lines`` + option that includes only those flagged lines and resets the flag once + the invoice is created. + +**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 +~~~~~~~ + +* NuoBiT Solutions SL + +Contributors +~~~~~~~~~~~~ + +* `NuoBiT `__: + + * Eric Antones + +Maintainers +~~~~~~~~~~~ + +This module is part of the `nuobit/odoo-addons `_ project on GitHub. + +You are welcome to contribute. diff --git a/sale_invoice_partial_lines/__init__.py b/sale_invoice_partial_lines/__init__.py new file mode 100644 index 000000000..aee8895e7 --- /dev/null +++ b/sale_invoice_partial_lines/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizards diff --git a/sale_invoice_partial_lines/__manifest__.py b/sale_invoice_partial_lines/__manifest__.py new file mode 100644 index 000000000..2a5982265 --- /dev/null +++ b/sale_invoice_partial_lines/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2026 NuoBiT Solutions SL - Eric Antones +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Sale Invoice Partial Lines", + "summary": "Mark sale order lines and invoice only the marked ones", + "author": "NuoBiT Solutions SL", + "category": "Sales", + "version": "16.0.1.2.1", + "license": "AGPL-3", + "website": "https://github.com/nuobit/odoo-addons", + "depends": [ + "sale", + ], + "data": [ + "views/sale_order_views.xml", + "wizards/sale_advance_payment_inv_views.xml", + ], +} diff --git a/sale_invoice_partial_lines/i18n/ca.po b/sale_invoice_partial_lines/i18n/ca.po new file mode 100644 index 000000000..4f855d19b --- /dev/null +++ b/sale_invoice_partial_lines/i18n/ca.po @@ -0,0 +1,77 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_invoice_partial_lines +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2026-04-27 14:00+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: ca\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: sale_invoice_partial_lines +#: model:ir.model.fields,help:sale_invoice_partial_lines.field_sale_order_line__selected +msgid "" +"Mark this line for batch operations (invoicing, grouping, exporting, etc.)." +msgstr "" +"Marca aquesta línia per a operacions per lots (facturació, agrupació, " +"exportació, etc.)." + +#. module: sale_invoice_partial_lines +#. odoo-python +#: code:addons/sale_invoice_partial_lines/wizards/sale_advance_payment_inv.py:0 +#, python-format +msgid "" +"No selected order lines are ready to invoice. Tick the 'Selected' checkbox on " +"invoiceable lines before creating the invoice." +msgstr "" +"No hi ha cap línia seleccionada a punt per facturar. Marca la casella " +"'Seleccionada' a les línies facturables abans de crear la factura." + +#. module: sale_invoice_partial_lines +#: model:ir.model.fields,help:sale_invoice_partial_lines.field_sale_order__selected_lines_count +msgid "Number of selected order lines (sections and notes excluded)." +msgstr "Nombre de línies de comanda seleccionades (sense seccions ni notes)." + +#. module: sale_invoice_partial_lines +#: model:ir.model.fields,field_description:sale_invoice_partial_lines.field_sale_advance_payment_inv__only_selected_lines +msgid "Only selected lines" +msgstr "Només línies seleccionades" + +#. module: sale_invoice_partial_lines +#: model:ir.model.fields,field_description:sale_invoice_partial_lines.field_sale_order_line__selected +msgid "Selected" +msgstr "Seleccionada" + +#. module: sale_invoice_partial_lines +#: model:ir.model.fields,field_description:sale_invoice_partial_lines.field_sale_order__selected_lines_count +msgid "Selected lines" +msgstr "Línies seleccionades" + +#. module: sale_invoice_partial_lines +#: model:ir.model.fields,field_description:sale_invoice_partial_lines.field_sale_order__selected_lines_amount +msgid "Subtotal of selected lines" +msgstr "Subtotal de les línies seleccionades" + +#. module: sale_invoice_partial_lines +#: model:ir.model.fields,help:sale_invoice_partial_lines.field_sale_order__selected_lines_amount +msgid "Sum of the untaxed subtotal of the selected order lines." +msgstr "" +"Suma del subtotal sense impostos de les línies de comanda seleccionades." + +#. module: sale_invoice_partial_lines +#: model:ir.model.fields,help:sale_invoice_partial_lines.field_sale_advance_payment_inv__only_selected_lines +msgid "" +"When set, the invoice will include only the order lines flagged as " +"'Selected'. After the invoice is created, the flag is reset on every line " +"that was just invoiced." +msgstr "" +"Quan està activat, la factura inclourà només les línies marcades com a " +"'Seleccionada'. Després de crear la factura, l'indicador es restableix a " +"cada línia facturada." diff --git a/sale_invoice_partial_lines/i18n/es.po b/sale_invoice_partial_lines/i18n/es.po new file mode 100644 index 000000000..759c276a7 --- /dev/null +++ b/sale_invoice_partial_lines/i18n/es.po @@ -0,0 +1,76 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_invoice_partial_lines +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2026-04-27 14:00+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: sale_invoice_partial_lines +#: model:ir.model.fields,help:sale_invoice_partial_lines.field_sale_order_line__selected +msgid "" +"Mark this line for batch operations (invoicing, grouping, exporting, etc.)." +msgstr "" +"Marca esta línea para operaciones por lotes (facturación, agrupación, " +"exportación, etc.)." + +#. module: sale_invoice_partial_lines +#. odoo-python +#: code:addons/sale_invoice_partial_lines/wizards/sale_advance_payment_inv.py:0 +#, python-format +msgid "" +"No selected order lines are ready to invoice. Tick the 'Selected' checkbox on " +"invoiceable lines before creating the invoice." +msgstr "" +"No hay líneas seleccionadas listas para facturar. Marca la casilla " +"'Seleccionada' en las líneas facturables antes de crear la factura." + +#. module: sale_invoice_partial_lines +#: model:ir.model.fields,help:sale_invoice_partial_lines.field_sale_order__selected_lines_count +msgid "Number of selected order lines (sections and notes excluded)." +msgstr "Número de líneas de pedido seleccionadas (sin secciones ni notas)." + +#. module: sale_invoice_partial_lines +#: model:ir.model.fields,field_description:sale_invoice_partial_lines.field_sale_advance_payment_inv__only_selected_lines +msgid "Only selected lines" +msgstr "Sólo líneas seleccionadas" + +#. module: sale_invoice_partial_lines +#: model:ir.model.fields,field_description:sale_invoice_partial_lines.field_sale_order_line__selected +msgid "Selected" +msgstr "Seleccionada" + +#. module: sale_invoice_partial_lines +#: model:ir.model.fields,field_description:sale_invoice_partial_lines.field_sale_order__selected_lines_count +msgid "Selected lines" +msgstr "Líneas seleccionadas" + +#. module: sale_invoice_partial_lines +#: model:ir.model.fields,field_description:sale_invoice_partial_lines.field_sale_order__selected_lines_amount +msgid "Subtotal of selected lines" +msgstr "Subtotal de las líneas seleccionadas" + +#. module: sale_invoice_partial_lines +#: model:ir.model.fields,help:sale_invoice_partial_lines.field_sale_order__selected_lines_amount +msgid "Sum of the untaxed subtotal of the selected order lines." +msgstr "Suma del subtotal sin impuestos de las líneas de pedido seleccionadas." + +#. module: sale_invoice_partial_lines +#: model:ir.model.fields,help:sale_invoice_partial_lines.field_sale_advance_payment_inv__only_selected_lines +msgid "" +"When set, the invoice will include only the order lines flagged as " +"'Selected'. After the invoice is created, the flag is reset on every line " +"that was just invoiced." +msgstr "" +"Cuando está activo, la factura incluirá sólo las líneas marcadas como " +"'Seleccionada'. Después de crear la factura, el indicador se restablece en " +"cada línea facturada." diff --git a/sale_invoice_partial_lines/models/__init__.py b/sale_invoice_partial_lines/models/__init__.py new file mode 100644 index 000000000..e7e9273fc --- /dev/null +++ b/sale_invoice_partial_lines/models/__init__.py @@ -0,0 +1,2 @@ +from . import sale_order_line +from . import sale_order diff --git a/sale_invoice_partial_lines/models/sale_order.py b/sale_invoice_partial_lines/models/sale_order.py new file mode 100644 index 000000000..ff3cff1f8 --- /dev/null +++ b/sale_invoice_partial_lines/models/sale_order.py @@ -0,0 +1,73 @@ +# Copyright 2026 NuoBiT Solutions SL - Eric Antones +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + selected_lines_count = fields.Integer( + string="Selected lines", + compute="_compute_selected_lines", + help="Number of selected order lines (sections and notes excluded).", + ) + selected_lines_amount = fields.Monetary( + string="Subtotal of selected lines", + compute="_compute_selected_lines", + currency_field="currency_id", + help="Sum of the untaxed subtotal of the selected order lines.", + ) + + @api.depends( + "order_line.selected", + "order_line.price_subtotal", + "order_line.display_type", + ) + def _compute_selected_lines(self): + for order in self: + selected = order.order_line.filtered( + lambda line: line.selected and not line.display_type + ) + order.selected_lines_count = len(selected) + order.selected_lines_amount = sum(selected.mapped("price_subtotal")) + + def _get_invoiceable_lines(self, final=False): + invoiceable_lines = super()._get_invoiceable_lines(final=final) + if not self.env.context.get("only_selected_lines"): + return invoiceable_lines + + # Keep the result from super() as the source of truth for what is + # invoiceable, then only narrow regular lines to the selected ones. + invoiceable_line_ids = [] + down_payment_line_ids = [] + group_lines = [] + group_has_selected_line = False + + def flush_group(): + nonlocal group_lines, group_has_selected_line + if group_has_selected_line: + invoiceable_line_ids.extend( + line.id + for line in group_lines + if line.display_type or line.selected + ) + group_lines = [] + group_has_selected_line = False + + for line in invoiceable_lines: + if line.is_downpayment and not line.display_type: + down_payment_line_ids.append(line.id) + continue + if line.display_type == "line_section": + flush_group() + group_lines = [line] + continue + group_lines.append(line) + if not line.display_type and line.selected: + group_has_selected_line = True + flush_group() + + return self.env["sale.order.line"].browse( + invoiceable_line_ids + down_payment_line_ids + ) diff --git a/sale_invoice_partial_lines/models/sale_order_line.py b/sale_invoice_partial_lines/models/sale_order_line.py new file mode 100644 index 000000000..e5d2f88e3 --- /dev/null +++ b/sale_invoice_partial_lines/models/sale_order_line.py @@ -0,0 +1,15 @@ +# Copyright 2026 NuoBiT Solutions SL - Eric Antones +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + selected = fields.Boolean( + default=False, + copy=False, + help="Mark this line for batch operations (invoicing, grouping, " + "exporting, etc.).", + ) diff --git a/sale_invoice_partial_lines/readme/CONTRIBUTORS.rst b/sale_invoice_partial_lines/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..866096fcb --- /dev/null +++ b/sale_invoice_partial_lines/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `NuoBiT `__: + + * Eric Antones diff --git a/sale_invoice_partial_lines/readme/DESCRIPTION.rst b/sale_invoice_partial_lines/readme/DESCRIPTION.rst new file mode 100644 index 000000000..02b85eb05 --- /dev/null +++ b/sale_invoice_partial_lines/readme/DESCRIPTION.rst @@ -0,0 +1,7 @@ +* Add a per-line ``Selected`` checkbox on sale orders so users can pick + which lines go into the next regular invoice. +* Persist the selection in the database, so it survives pagination, + refreshes, and closing the browser. +* Extend the standard *Create Invoice* wizard with an ``Only selected lines`` + option that includes only those flagged lines and resets the flag once + the invoice is created. diff --git a/sale_invoice_partial_lines/static/description/icon.png b/sale_invoice_partial_lines/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..1cd641e792c30455187ca30940bc0f329ce8bbb0 GIT binary patch literal 6342 zcmd^^hf`C}*TzHWpfm-MZa|7OjYtjE(4`3pP0Eid3J8V{0s)mKJ<q zp^9|rp$mb~2}po9-@oIXJG(oxcjoS%d!O@s&d!Z9HP*e##KQyt0IurmK_64bp8pyH z9i^|ds>-JfbWVo4P{8GX*QeIfbjl2)kDfIG0ALvZuTgp2ZfK=U();NfY11z-vM>r= zo6RyI007+P`cO@apy}VqnaiVCLL`CEUGVGYE&5WpdhhbZv%|*-Y|2t(4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^5hnC6CLZUU`;nO2NF2)FaAkYhQL$Z58+`p75dj7RKse#Z!uacCm z0@|m~U!QZOdb|V~`ktFK4;lg_ZOCjFXeV4`jGj&bh7Q6BEyN8~yGd*JyzwFbIRaAf z#KG$rvQxWFvqwn`i6jBQ?6o+k+oOC)Gj9ChlgabiScr};b5|opxUYjCZOwmhjTj6W zFzJt_htTuopW4IRiQ}r0L}`w=pE{HN<@(9Hl11P5cHmN6A1F^sg2OWXcw<+q2x>I5 zq9Bu>PBob6#^vrr<|IC)m+zJpFRRcCVsqbspNybriu&!R=H^@RcG#aBGz9RH}ZI=>4 zi(m?IA?Vr$Q7?wN6ZW7H`S?3}K8=$7J5MjWKri=_igw1%J?0~*6e_Ii*1&23dGcF} z&=vaMgF!^veGQ1f$3k?WK5Jaw%==+Bb!tI6zQ68&-dQ3Orl+Tqh#Nt?dBEV_w^wkjY+qJ+X*NCMs%J-Lc4%}pKryM#O)O&9 un*HHVB-AlUN`suyDkKONktc!@Ievk;6wT20MOSqhE{1gM*SZGeqiYU literal 0 HcmV?d00001 diff --git a/sale_invoice_partial_lines/static/description/index.html b/sale_invoice_partial_lines/static/description/index.html new file mode 100644 index 000000000..b63cbfe96 --- /dev/null +++ b/sale_invoice_partial_lines/static/description/index.html @@ -0,0 +1,433 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Sale Invoice Partial Lines

+ +

Beta License: AGPL-3 nuobit/odoo-addons

+
    +
  • Add a per-line Selected checkbox on sale orders so users can pick +which lines go into the next regular invoice.
  • +
  • Persist the selection in the database, so it survives pagination, +refreshes, and closing the browser.
  • +
  • Extend the standard Create Invoice wizard with an Only selected lines +option that includes only those flagged lines and resets the flag once +the invoice is created.
  • +
+

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

+
    +
  • NuoBiT Solutions SL
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is part of the nuobit/odoo-addons project on GitHub.

+

You are welcome to contribute.

+
+
+
+
+ + diff --git a/sale_invoice_partial_lines/tests/__init__.py b/sale_invoice_partial_lines/tests/__init__.py new file mode 100644 index 000000000..9d3d4c0de --- /dev/null +++ b/sale_invoice_partial_lines/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_invoice_partial_lines diff --git a/sale_invoice_partial_lines/tests/test_sale_invoice_partial_lines.py b/sale_invoice_partial_lines/tests/test_sale_invoice_partial_lines.py new file mode 100644 index 000000000..7011373c3 --- /dev/null +++ b/sale_invoice_partial_lines/tests/test_sale_invoice_partial_lines.py @@ -0,0 +1,223 @@ +# Copyright 2026 NuoBiT Solutions SL - Eric Antones +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.exceptions import UserError +from odoo.fields import Command +from odoo.tests import tagged + +from odoo.addons.sale.tests.common import TestSaleCommon + + +@tagged("-at_install", "post_install") +class TestSaleInvoicePartialLines(TestSaleCommon): + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass(chart_template_ref=chart_template_ref) + cls.sale_order = ( + cls.env["sale.order"] + .with_context(tracking_disable=True) + .create( + { + "partner_id": cls.partner_a.id, + "partner_invoice_id": cls.partner_a.id, + "partner_shipping_id": cls.partner_a.id, + "pricelist_id": cls.company_data["default_pricelist"].id, + "order_line": [ + Command.create( + { + "display_type": "line_section", + "name": "Section A", + } + ), + Command.create( + { + "product_id": cls.company_data["product_order_no"].id, + "product_uom_qty": 5, + "tax_id": False, + } + ), + Command.create( + { + "product_id": cls.company_data[ + "product_service_order" + ].id, + "product_uom_qty": 3, + "tax_id": False, + } + ), + Command.create( + { + "display_type": "line_section", + "name": "Section B", + } + ), + Command.create( + { + "product_id": cls.company_data[ + "product_delivery_no" + ].id, + "product_uom_qty": 2, + "tax_id": False, + } + ), + ], + } + ) + ) + cls.sale_order.action_confirm() + cls.product_lines = cls.sale_order.order_line.filtered( + lambda line: not line.display_type + ) + cls.section_a, cls.section_b = cls.sale_order.order_line.filtered( + lambda line: line.display_type == "line_section" + ) + # Force quantities so every product line is invoiceable + for line in cls.product_lines: + line.qty_delivered = line.product_uom_qty + cls.context = { + "active_model": "sale.order", + "active_ids": [cls.sale_order.id], + "active_id": cls.sale_order.id, + } + + def _create_wizard(self, only_selected_lines): + return ( + self.env["sale.advance.payment.inv"] + .with_context(**self.context) + .create( + { + "advance_payment_method": "delivered", + "only_selected_lines": only_selected_lines, + } + ) + ) + + def test_count_and_amount_compute(self): + line_1, line_2, _line_3 = self.product_lines + line_1.selected = True + line_2.selected = True + self.assertEqual(self.sale_order.selected_lines_count, 2) + self.assertEqual( + self.sale_order.selected_lines_amount, + line_1.price_subtotal + line_2.price_subtotal, + ) + + def test_no_marked_lines_raises(self): + wizard = self._create_wizard(only_selected_lines=True) + with self.assertRaises(UserError): + wizard.create_invoices() + + def test_no_selected_invoiceable_lines_keeps_marks(self): + _line_1, _line_2, line_3 = self.product_lines + line_3.qty_delivered = 0 + line_3.selected = True + wizard = self._create_wizard(only_selected_lines=True) + with self.assertRaises(UserError): + wizard.create_invoices() + self.assertTrue(line_3.selected) + + def test_invoice_only_marked_lines(self): + line_1, line_2, _line_3 = self.product_lines + line_1.selected = True + line_2.selected = True + wizard = self._create_wizard(only_selected_lines=True) + wizard.create_invoices() + invoice = self.sale_order.invoice_ids + self.assertEqual(len(invoice), 1) + invoiced_so_product_lines = invoice.invoice_line_ids.filtered( + lambda l: l.display_type == "product" + ).sale_line_ids + self.assertEqual(invoiced_so_product_lines, line_1 + line_2) + + def test_marks_reset_after_invoice(self): + line_1, line_2, _line_3 = self.product_lines + line_1.selected = True + line_2.selected = True + self._create_wizard(only_selected_lines=True).create_invoices() + self.assertFalse(line_1.selected) + self.assertFalse(line_2.selected) + self.assertEqual(self.sale_order.selected_lines_count, 0) + + def test_only_invoiceable_marks_reset_after_invoice(self): + line_1, _line_2, line_3 = self.product_lines + line_1.selected = True + line_3.qty_delivered = 0 + line_3.selected = True + self._create_wizard(only_selected_lines=True).create_invoices() + invoice = self.sale_order.invoice_ids + invoiced_so_product_lines = invoice.invoice_line_ids.filtered( + lambda l: l.display_type == "product" + ).sale_line_ids + self.assertEqual(invoiced_so_product_lines, line_1) + self.assertFalse(line_1.selected) + self.assertTrue(line_3.selected) + + def test_only_marked_section_kept(self): + # Mark only the line under Section B; Section A must be dropped. + _line_1, _line_2, line_3 = self.product_lines + line_3.selected = True + self._create_wizard(only_selected_lines=True).create_invoices() + invoice = self.sale_order.invoice_ids + self.assertEqual(len(invoice), 1) + invoiced_so_product_lines = invoice.invoice_line_ids.filtered( + lambda l: l.display_type == "product" + ).sale_line_ids + self.assertEqual(invoiced_so_product_lines, line_3) + sections_in_invoice = invoice.invoice_line_ids.filtered( + lambda l: l.display_type == "line_section" + ) + self.assertEqual(sections_in_invoice.mapped("name"), ["Section B"]) + + def test_unselected_section_note_dropped(self): + line_1, line_2, line_3 = self.product_lines + self.section_a.sequence = 10 + line_1.sequence = 20 + line_2.sequence = 30 + note = self.env["sale.order.line"].create( + { + "order_id": self.sale_order.id, + "display_type": "line_note", + "name": "Unselected section note", + "sequence": 40, + } + ) + self.section_b.sequence = 50 + line_3.sequence = 60 + line_3.selected = True + self._create_wizard(only_selected_lines=True).create_invoices() + invoice = self.sale_order.invoice_ids + sections_in_invoice = invoice.invoice_line_ids.filtered( + lambda l: l.display_type == "line_section" + ) + self.assertEqual(sections_in_invoice.mapped("name"), ["Section B"]) + self.assertNotIn(note.name, invoice.invoice_line_ids.mapped("name")) + + def test_orphan_note_kept_with_selected_product(self): + # Note before any section, followed by a selected product line: the + # note must be carried into the invoice with the selected line. + line_1, _line_2, _line_3 = self.product_lines + self.section_a.unlink() + self.section_b.unlink() + note = self.env["sale.order.line"].create( + { + "order_id": self.sale_order.id, + "display_type": "line_note", + "name": "Orphan note before product", + "sequence": 5, + } + ) + line_1.sequence = 10 + line_1.selected = True + self._create_wizard(only_selected_lines=True).create_invoices() + invoice = self.sale_order.invoice_ids + self.assertIn(note.name, invoice.invoice_line_ids.mapped("name")) + + def test_default_path_invoices_all(self): + # Without only_selected_lines the wizard behaves exactly like core sale. + self._create_wizard(only_selected_lines=False).create_invoices() + invoice = self.sale_order.invoice_ids + self.assertEqual(len(invoice), 1) + invoiced_so_product_lines = invoice.invoice_line_ids.filtered( + lambda l: l.display_type == "product" + ).sale_line_ids + self.assertEqual(invoiced_so_product_lines, self.product_lines) diff --git a/sale_invoice_partial_lines/views/sale_order_views.xml b/sale_invoice_partial_lines/views/sale_order_views.xml new file mode 100644 index 000000000..fbc6d2695 --- /dev/null +++ b/sale_invoice_partial_lines/views/sale_order_views.xml @@ -0,0 +1,40 @@ + + + + + + sale.order.form.invoice.partial.lines + sale.order + + + + + + + + + + + + + + + diff --git a/sale_invoice_partial_lines/wizards/__init__.py b/sale_invoice_partial_lines/wizards/__init__.py new file mode 100644 index 000000000..b53fbfe41 --- /dev/null +++ b/sale_invoice_partial_lines/wizards/__init__.py @@ -0,0 +1 @@ +from . import sale_advance_payment_inv diff --git a/sale_invoice_partial_lines/wizards/sale_advance_payment_inv.py b/sale_invoice_partial_lines/wizards/sale_advance_payment_inv.py new file mode 100644 index 000000000..7cdff10cf --- /dev/null +++ b/sale_invoice_partial_lines/wizards/sale_advance_payment_inv.py @@ -0,0 +1,46 @@ +# Copyright 2026 NuoBiT Solutions SL - Eric Antones +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, fields, models +from odoo.exceptions import UserError + + +class SaleAdvancePaymentInv(models.TransientModel): + _inherit = "sale.advance.payment.inv" + + only_selected_lines = fields.Boolean( + string="Only selected lines", + default=False, + help="When set, the invoice will include only the order lines flagged " + "as 'Selected'. After the invoice is created, the flag is reset on " + "every line that was just invoiced.", + ) + + def _create_invoices(self, sale_orders): + self.ensure_one() + if not self.only_selected_lines or self.advance_payment_method != "delivered": + return super()._create_invoices(sale_orders) + selected_invoiceable_lines = self.env["sale.order.line"] + selective_sale_orders = sale_orders.with_context(only_selected_lines=True) + for order in selective_sale_orders: + selected_invoiceable_lines |= order._get_invoiceable_lines( + final=self.deduct_down_payments + ).filtered( + lambda line: line.selected + and not line.display_type + and not line.is_downpayment + ) + if not selected_invoiceable_lines: + raise UserError( + _( + "No selected order lines are ready to invoice. Tick the " + "'Selected' checkbox on invoiceable lines before creating " + "the invoice." + ) + ) + res = super( + SaleAdvancePaymentInv, + self.with_context(only_selected_lines=True), + )._create_invoices(selective_sale_orders) + selected_invoiceable_lines.write({"selected": False}) + return res diff --git a/sale_invoice_partial_lines/wizards/sale_advance_payment_inv_views.xml b/sale_invoice_partial_lines/wizards/sale_advance_payment_inv_views.xml new file mode 100644 index 000000000..32f97db8f --- /dev/null +++ b/sale_invoice_partial_lines/wizards/sale_advance_payment_inv_views.xml @@ -0,0 +1,20 @@ + + + + + + sale.advance.payment.inv.form.invoice.partial.lines + sale.advance.payment.inv + + + + + + + + + diff --git a/setup/sale_invoice_partial_lines/odoo/addons/sale_invoice_partial_lines b/setup/sale_invoice_partial_lines/odoo/addons/sale_invoice_partial_lines new file mode 120000 index 000000000..b36051b61 --- /dev/null +++ b/setup/sale_invoice_partial_lines/odoo/addons/sale_invoice_partial_lines @@ -0,0 +1 @@ +../../../../sale_invoice_partial_lines \ No newline at end of file diff --git a/setup/sale_invoice_partial_lines/setup.py b/setup/sale_invoice_partial_lines/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/sale_invoice_partial_lines/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)