Skip to content

.mapped("allocation_ids.stock_request_id") called on deleted moves #71

@TheMule71

Description

@TheMule71

Module

stock_request

Describe the bug

def _action_done(self, cancel_backorder=False):
"""Apply sudo to prevent requests ACL errors if the user does not have
permissions (example: productions)."""
res = super()._action_done(cancel_backorder=cancel_backorder)
self.mapped("allocation_ids.stock_request_id").sudo().check_done()
return res

the .mapped() there is applied to all moves, but in some cases _action_done() deletes moves (like when it expands Kits in a BOM for a MO).

To Reproduce

Affected versions:
18.0 (I haven't tested other versions)

Steps to reproduce the behavior:

  1. Create a BOM with a Kit inside
  2. Create and confirm a MO using that BOM

Expected behavior
Installing stock_request should not break those productions.

Additional context
The following patch seems to fix the issue:

diff --git a/stock_request/models/stock_move.py b/stock_request/models/stock_move.py
index 6019d26..9a803b2 100644
--- a/stock_request/models/stock_move.py
+++ b/stock_request/models/stock_move.py
@@ -78,5 +78,5 @@ class StockMove(models.Model):
         """Apply sudo to prevent requests ACL errors if the user does not have
         permissions (example: productions)."""
         res = super()._action_done(cancel_backorder=cancel_backorder)
-        self.mapped("allocation_ids.stock_request_id").sudo().check_done()
+        self.filtered(lambda x: x.exists()).mapped("allocation_ids.stock_request_id").sudo().check_done()
         return res

I can't really tell what's the impact on stock_request in general.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions