diff --git a/stock_ux/models/stock_move.py b/stock_ux/models/stock_move.py index aa006c359..a93235121 100644 --- a/stock_ux/models/stock_move.py +++ b/stock_ux/models/stock_move.py @@ -140,3 +140,8 @@ def _trigger_assign(self): if not self.env.context.get("trigger_assign"): return super().with_context(trigger_assign=True)._trigger_assign() return super()._trigger_assign() + + @api.ondelete(at_uninstall=False) + def _unlink_if_draft_or_cancel(self): + if any(move.state not in ("draft", "cancel") for move in self): + raise UserError(_("You can only delete draft or cancelled moves."))