[FIX] stock_picking_batch_custom: require collected before batch validation
This commit is contained in:
parent
12d434d4c7
commit
d4be0ae23e
4 changed files with 107 additions and 0 deletions
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue