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 000000000..1cd641e79 Binary files /dev/null and b/sale_invoice_partial_lines/static/description/icon.png differ 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, +)