add stock_inventory_category_concurrency: allow several inventory adjustments for diffent categories
This commit is contained in:
parent
1a4c8f0094
commit
e4050a6e31
4 changed files with 84 additions and 0 deletions
1
stock_inventory_category_concurrency/models/__init__.py
Normal file
1
stock_inventory_category_concurrency/models/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from . import stock_inventory
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
from odoo import _, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class InventoryAdjustmentsGroup(models.Model):
|
||||
_inherit = "stock.inventory"
|
||||
|
||||
def action_state_to_in_progress(self):
|
||||
"""
|
||||
Relaja el bloqueo por categoría: si el ajuste actual es por categoría,
|
||||
solo bloquea otros ajustes en progreso que afecten a la MISMA categoría exacta,
|
||||
no a categorías hermanas distintas ni a todas sus hijas.
|
||||
"""
|
||||
self.ensure_one()
|
||||
# Reusar la lógica original, pero parchear el caso de category
|
||||
search_filter = [
|
||||
(
|
||||
"location_id",
|
||||
"child_of" if not self.exclude_sublocation else "in",
|
||||
self.location_ids.ids,
|
||||
),
|
||||
("to_do", "=", True),
|
||||
]
|
||||
|
||||
error_field = "location_id"
|
||||
error_message = _(
|
||||
"There's already an Adjustment in Process "
|
||||
"using one requested Location: %(names)s. "
|
||||
"Blocking adjustments: %(blocking_names)s"
|
||||
)
|
||||
|
||||
if self.product_ids:
|
||||
search_filter.append(("product_id", "in", self.product_ids.ids))
|
||||
error_field = "product_id"
|
||||
error_message = _(
|
||||
"There are active adjustments for the requested products: %(names)s. "
|
||||
"Blocking adjustments: %(blocking_names)s"
|
||||
)
|
||||
elif self.category_id:
|
||||
# Solo misma categoría exacta, sin OR hijos
|
||||
search_filter.append(("product_id.categ_id", "=", self.category_id.id))
|
||||
error_field = "category_id"
|
||||
error_message = _(
|
||||
"There are active adjustments for the requested category: %(names)s. "
|
||||
"Blocking adjustments: %(blocking_names)s"
|
||||
)
|
||||
|
||||
quants = self.env["stock.quant"].search(search_filter)
|
||||
if quants:
|
||||
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({"state": "in_progress", "stock_quant_ids": [(6, 0, quants.ids)]})
|
||||
quants.write(
|
||||
{
|
||||
"to_do": True,
|
||||
"user_id": self.responsible_id,
|
||||
"inventory_date": self.date,
|
||||
"current_inventory_id": self.id,
|
||||
}
|
||||
)
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue