[IMP] stock_inventory: improve errors information when inventory is blocked

This commit is contained in:
Joan Sisquella
2024-07-22 10:02:06 +02:00
parent 479a31d613
commit 97251f7ab8
2 changed files with 15 additions and 4 deletions

View File

@@ -273,18 +273,28 @@ class InventoryAdjustmentsGroup(models.Model):
search_filter.append(("product_id", "in", self.product_ids.ids))
error_field = "product_id"
error_message = _(
"There are active adjustments for the requested products: %s"
"There are active adjustments for the requested products: %(names)s. "
"Blocking adjustments: %(blocking_names)s"
)
else:
error_field = "location_id"
error_message = _(
"There's already an Adjustment in Process using one requested Location: %s"
"There's already an Adjustment in Process "
"using one requested Location: %(names)s. "
"Blocking adjustments: %(blocking_names)s"
)
quants = self.env["stock.quant"].search(search_filter)
if quants:
names = self._get_quant_joined_names(quants, error_field)
raise ValidationError(error_message % names)
inventory_ids = self.env["stock.inventory"].search(
[("stock_quant_ids", "in", quants.ids), ("state", "=", "in_progress")]
)
if inventory_ids:
blocking_names = ", ".join(inventory_ids.mapped("name"))
names = self._get_quant_joined_names(quants, error_field)
raise ValidationError(
error_message % {"names": names, "blocking_names": blocking_names}
)
quants = self._get_quants(self.location_ids)
self.write(

View File

@@ -161,6 +161,7 @@
<field name="location_ids" />
<field name="date" />
<field name="state" />
<field name="product_ids" string="Product" />
</search>
</field>
</record>