diff --git a/stock_picking_batch_custom/i18n/es.po b/stock_picking_batch_custom/i18n/es.po new file mode 100644 index 0000000..c38c173 --- /dev/null +++ b/stock_picking_batch_custom/i18n/es.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_picking_batch_custom +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"POT-Creation-Date: 2026-03-30 00:00+0000\n" +"PO-Revision-Date: 2026-03-30 00: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: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: stock_picking_batch_custom +#. odoo-python +#: code:addons/stock_picking_batch_custom/models/stock_picking_batch.py:0 +msgid "You must mark all product lines as collected before validating the batch." +msgstr "Debes marcar todas las lĂ­neas de producto como recogidas antes de validar el lote." + +#. module: stock_picking_batch_custom +#. odoo-python +#: code:addons/stock_picking_batch_custom/models/stock_picking_batch.py:0 +msgid "Pending products: %(products)s" +msgstr "Productos pendientes: %(products)s" diff --git a/stock_picking_batch_custom/i18n/eu.po b/stock_picking_batch_custom/i18n/eu.po new file mode 100644 index 0000000..7fe2682 --- /dev/null +++ b/stock_picking_batch_custom/i18n/eu.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_picking_batch_custom +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"POT-Creation-Date: 2026-03-30 00:00+0000\n" +"PO-Revision-Date: 2026-03-30 00:00+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: eu\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: stock_picking_batch_custom +#. odoo-python +#: code:addons/stock_picking_batch_custom/models/stock_picking_batch.py:0 +msgid "You must mark all product lines as collected before validating the batch." +msgstr "Produktu-lerro guztiak jasota gisa markatu behar dituzu lotea balioztatu aurretik." + +#. module: stock_picking_batch_custom +#. odoo-python +#: code:addons/stock_picking_batch_custom/models/stock_picking_batch.py:0 +msgid "Pending products: %(products)s" +msgstr "Zain dauden produktuak: %(products)s" diff --git a/stock_picking_batch_custom/models/stock_picking_batch.py b/stock_picking_batch_custom/models/stock_picking_batch.py index c2c77fc..798678c 100644 --- a/stock_picking_batch_custom/models/stock_picking_batch.py +++ b/stock_picking_batch_custom/models/stock_picking_batch.py @@ -4,6 +4,7 @@ from odoo import api from odoo import fields from odoo import models +from odoo.exceptions import UserError class StockPickingBatch(models.Model): @@ -139,6 +140,31 @@ class StockPickingBatch(models.Model): else: batch.summary_line_ids = [fields.Command.clear()] + def _check_all_products_collected(self): + """Ensure all product summary lines are marked as collected before done.""" + for batch in self: + not_collected_lines = batch.summary_line_ids.filtered( + lambda line: not line.is_collected + ) + if not not_collected_lines: + continue + + product_names = ", ".join( + not_collected_lines.mapped("product_id.display_name") + ) + message = batch.env._( + "You must mark all product lines as collected before validating the batch." + ) + if product_names: + message += "\n" + batch.env._( + "Pending products: %(products)s", products=product_names + ) + raise UserError(message) + + def action_done(self): + self._check_all_products_collected() + return super().action_done() + class StockPickingBatchSummaryLine(models.Model): _name = "stock.picking.batch.summary.line" diff --git a/stock_picking_batch_custom/tests/test_batch_summary.py b/stock_picking_batch_custom/tests/test_batch_summary.py index e8139e9..07f2518 100644 --- a/stock_picking_batch_custom/tests/test_batch_summary.py +++ b/stock_picking_batch_custom/tests/test_batch_summary.py @@ -1,6 +1,7 @@ # Copyright 2026 Criptomart # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo.exceptions import UserError from odoo.tests import tagged from odoo.tests.common import TransactionCase @@ -287,3 +288,27 @@ class TestBatchSummary(TransactionCase): lambda line: line.product_id == product2 ) self.assertAlmostEqual(line_product2.qty_demanded, 10.0) + + def test_done_requires_all_summary_lines_collected(self): + """Batch validation must fail if there are unchecked collected lines.""" + + batch = self._create_batch_with_pickings() + batch.action_confirm() + batch._compute_summary_line_ids() + + self.assertTrue(batch.summary_line_ids) + self.assertFalse(batch.summary_line_ids.mapped("is_collected")[0]) + + with self.assertRaises(UserError): + batch.action_done() + + def test_check_all_products_collected_passes_when_all_checked(self): + """Collected validation helper must pass when all lines are checked.""" + + batch = self._create_batch_with_pickings() + batch.action_confirm() + batch._compute_summary_line_ids() + batch.summary_line_ids.write({"is_collected": True}) + + # Should not raise + batch._check_all_products_collected()