[IMP] stock_picking_batch_custom: configuraciones de bloqueo por pestaña
This commit is contained in:
parent
05a8908007
commit
18fd73ed1b
7 changed files with 211 additions and 25 deletions
|
|
@ -140,15 +140,47 @@ class StockPickingBatch(models.Model):
|
|||
else:
|
||||
batch.summary_line_ids = [fields.Command.clear()]
|
||||
|
||||
def _check_all_products_collected(self, pickings=None):
|
||||
"""Validate only Detailed Operations collected flags.
|
||||
def _raise_collected_restriction(self, base_message, product_names):
|
||||
message = self.env._(base_message)
|
||||
if product_names:
|
||||
message += "\n" + self.env._(
|
||||
"Pending products: %(products)s", products=product_names
|
||||
)
|
||||
raise UserError(message)
|
||||
|
||||
Product Summary checkboxes are informative and must not block the flow.
|
||||
The blocking validation applies to stock.move.line.is_collected in the
|
||||
detailed operations tab for lines with processed quantity.
|
||||
"""
|
||||
def _get_not_collected_summary_lines(self, batch_pickings, scope):
|
||||
summary_lines = self.summary_line_ids
|
||||
if scope == "processed":
|
||||
processed_product_ids = set(
|
||||
batch_pickings.move_line_ids.filtered(
|
||||
lambda line: (
|
||||
line.move_id.state not in ("cancel", "done")
|
||||
and line.product_id
|
||||
and line.move_id.quantity > 0
|
||||
)
|
||||
).mapped("product_id.id")
|
||||
)
|
||||
summary_lines = summary_lines.filtered(
|
||||
lambda line: line.product_id.id in processed_product_ids
|
||||
)
|
||||
return summary_lines.filtered(lambda line: not line.is_collected)
|
||||
|
||||
def _get_not_collected_detailed_lines(self, batch_pickings, scope):
|
||||
detailed_lines = batch_pickings.move_line_ids.filtered(
|
||||
lambda line: line.move_id.state not in ("cancel", "done")
|
||||
and line.product_id
|
||||
)
|
||||
if scope == "processed":
|
||||
detailed_lines = detailed_lines.filtered(
|
||||
lambda line: line.move_id.quantity > 0
|
||||
)
|
||||
return detailed_lines.filtered(lambda line: not line.is_collected)
|
||||
|
||||
def _check_all_products_collected(self, pickings=None):
|
||||
"""Validate collected restrictions based on tab configuration."""
|
||||
|
||||
for batch in self:
|
||||
company = batch.company_id or self.env.company
|
||||
batch_pickings = (
|
||||
pickings.filtered(lambda p, batch=batch: p.batch_id == batch)
|
||||
if pickings
|
||||
|
|
@ -157,28 +189,37 @@ class StockPickingBatch(models.Model):
|
|||
if not batch_pickings:
|
||||
continue
|
||||
|
||||
not_collected_move_lines = batch_pickings.move_line_ids.filtered(
|
||||
lambda line: (
|
||||
line.move_id.state not in ("cancel", "done")
|
||||
and line.product_id
|
||||
and line.move_id.quantity > 0
|
||||
and not line.is_collected
|
||||
if company.batch_detailed_restriction_enabled:
|
||||
not_collected_detailed = batch._get_not_collected_detailed_lines(
|
||||
batch_pickings, company.batch_detailed_restriction_scope
|
||||
)
|
||||
)
|
||||
if not not_collected_move_lines:
|
||||
continue
|
||||
if not_collected_detailed:
|
||||
product_names = ", ".join(
|
||||
sorted(
|
||||
set(
|
||||
not_collected_detailed.mapped("product_id.display_name")
|
||||
)
|
||||
)
|
||||
)
|
||||
batch._raise_collected_restriction(
|
||||
"You must mark detailed operation lines as collected before validating the batch.",
|
||||
product_names,
|
||||
)
|
||||
|
||||
product_names = ", ".join(
|
||||
sorted(set(not_collected_move_lines.mapped("product_id.display_name")))
|
||||
)
|
||||
message = batch.env._(
|
||||
"You must mark detailed operation lines as collected before validating the batch."
|
||||
)
|
||||
if product_names:
|
||||
message += "\n" + batch.env._(
|
||||
"Pending products: %(products)s", products=product_names
|
||||
if company.batch_summary_restriction_enabled:
|
||||
not_collected_summary = batch._get_not_collected_summary_lines(
|
||||
batch_pickings, company.batch_summary_restriction_scope
|
||||
)
|
||||
raise UserError(message)
|
||||
if not_collected_summary:
|
||||
product_names = ", ".join(
|
||||
sorted(
|
||||
set(not_collected_summary.mapped("product_id.display_name"))
|
||||
)
|
||||
)
|
||||
batch._raise_collected_restriction(
|
||||
"You must mark product summary lines as collected before validating the batch.",
|
||||
product_names,
|
||||
)
|
||||
|
||||
|
||||
class StockPickingBatchSummaryLine(models.Model):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue