mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_cycle_count: Refactor responsible_id sync using compute/inverse fields
This commit is contained in:
@@ -84,17 +84,6 @@ class StockCycleCount(models.Model):
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
def write(self, vals):
|
||||
result = super().write(vals)
|
||||
if "responsible_id" in vals and not self.env.context.get("no_propagate"):
|
||||
stock_inventory_records = self.mapped("stock_adjustment_ids")
|
||||
for record in stock_inventory_records:
|
||||
if record.responsible_id.id != vals["responsible_id"]:
|
||||
record.with_context(no_propagate=True).write(
|
||||
{"responsible_id": vals["responsible_id"]}
|
||||
)
|
||||
return result
|
||||
|
||||
@api.depends("stock_adjustment_ids")
|
||||
def _compute_inventory_adj_count(self):
|
||||
for rec in self:
|
||||
|
||||
@@ -35,10 +35,27 @@ class StockInventory(models.Model):
|
||||
default=False,
|
||||
)
|
||||
responsible_id = fields.Many2one(
|
||||
states={"draft": [("readonly", False)], "in_progress": [("readonly", False)]},
|
||||
tracking=True,
|
||||
compute="_compute_responsible_id",
|
||||
inverse="_inverse_responsible_id",
|
||||
store=True,
|
||||
readonly=False,
|
||||
)
|
||||
|
||||
@api.depends("cycle_count_id.responsible_id")
|
||||
def _compute_responsible_id(self):
|
||||
for inv in self:
|
||||
if inv.cycle_count_id:
|
||||
inv.responsible_id = inv.cycle_count_id.responsible_id
|
||||
inv.stock_quant_ids.write(
|
||||
{"user_id": inv.cycle_count_id.responsible_id}
|
||||
)
|
||||
|
||||
def _inverse_responsible_id(self):
|
||||
for inv in self:
|
||||
if inv.cycle_count_id and inv.responsible_id:
|
||||
inv.cycle_count_id.responsible_id = inv.responsible_id
|
||||
|
||||
def write(self, vals):
|
||||
result = super().write(vals)
|
||||
if "responsible_id" in vals:
|
||||
|
||||
Reference in New Issue
Block a user