Skip to content

Commit 5b18457

Browse files
committed
[IMP] rma_batch: Propagate location change from batch to RMAs
The _compute_location_id dependency was on "batch_id" instead of "batch_id.location_id", so changing the location on a draft batch did not trigger recomputation on the associated RMAs.
1 parent 0bf1f19 commit 5b18457

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

rma_batch/models/rma.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ def _compute_team_id(self):
6262
rec.team_id = rec.batch_id.team_id
6363
return res
6464

65-
@api.depends("picking_id", "product_id", "company_id", "batch_id")
65+
@api.depends("picking_id", "product_id", "company_id", "batch_id.location_id")
6666
def _compute_location_id(self):
6767
"""Override to consider RMA Batch location"""
6868
super()._compute_location_id()
6969
# Apply RMA Batch location if set
7070
for record in self:
71-
if record.batch_id and record.batch_id.location_id:
71+
if record.state != "draft":
72+
continue
73+
if record.batch_id.location_id:
7274
record.location_id = record.batch_id.location_id
7375

7476
return

rma_batch/tests/test_rma_batch.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ def test_onchange_sync_rmas_only(self):
113113
self.assertEqual(rma.team_id, self.team)
114114
self.assertEqual(rma.tag_ids, self.tag1)
115115

116+
def test_change_location_on_batch_propagates_to_rmas(self):
117+
"""check that changing the location on a draft batch updates
118+
the location on the associated RMAs"""
119+
warehouse = self.env["stock.warehouse"].search(
120+
[("company_id", "=", self.env.company.id)], limit=1
121+
)
122+
rma_location = warehouse.rma_loc_id
123+
batch = self._create_batch([(self.product, 5), (self.product2, 3)])
124+
self.assertEqual(batch.state, "draft")
125+
self.assertEqual(batch.rma_ids[0].location_id, batch.location_id)
126+
batch.location_id = rma_location
127+
for rma in batch.rma_ids:
128+
self.assertEqual(rma.location_id, rma_location)
129+
116130
def test_unlink_forbidden_when_non_draft_rma(self):
117131
"""ensure that a batch can't be deleted if it contains any RMA
118132
not in draft state"""

0 commit comments

Comments
 (0)