diff --git a/stock_cycle_count/models/stock_cycle_count.py b/stock_cycle_count/models/stock_cycle_count.py index d1b4b243ebb2..d947ebb6f6da 100644 --- a/stock_cycle_count/models/stock_cycle_count.py +++ b/stock_cycle_count/models/stock_cycle_count.py @@ -86,13 +86,6 @@ class StockCycleCount(models.Model): 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") diff --git a/stock_cycle_count/models/stock_inventory.py b/stock_cycle_count/models/stock_inventory.py index 74fabd2d0dc3..c7304ed56f10 100644 --- a/stock_cycle_count/models/stock_inventory.py +++ b/stock_cycle_count/models/stock_inventory.py @@ -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: