Skip to content

Commit 957a298

Browse files
committed
[IMP] rma: allow standard refund
1 parent 0880d90 commit 957a298

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

rma/models/rma.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ def _prepare_reception_procurement_vals(self, group=None):
774774
vals = self._prepare_common_procurement_vals(group=group)
775775
vals["route_ids"] = self.warehouse_id.rma_in_route_id
776776
vals["rma_receiver_ids"] = [(6, 0, self.ids)]
777+
vals["to_refund"] = self.operation_id.action_create_refund == "update_quantity"
777778
if self.move_id:
778779
vals["origin_returned_move_id"] = self.move_id.id
779780
return vals

rma/models/rma_operation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class RmaOperation(models.Model):
3636
("automatic_on_confirm", "Automatically on Confirm"),
3737
("manual_after_receipt", "Manually After Receipt"),
3838
("automatic_after_receipt", "Automatically After Receipt"),
39+
("update_quantity", "Update Quantities"),
3940
],
4041
string="Refund Action",
4142
default="manual_after_receipt",

rma/tests/test_rma_operation.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,51 @@ def test_13(self):
233233
rma.reception_move_id.picking_id._action_done()
234234
self.assertEqual(rma.state, "received")
235235
self.assertFalse(rma.delivery_move_ids)
236+
237+
def test_14(self):
238+
"""if the refund action is not ment to update quantity, return picking line
239+
to_refund field should be False"""
240+
self.operation.action_create_refund = "manual_after_receipt"
241+
origin_delivery = self._create_delivery()
242+
stock_return_picking_form = Form(
243+
self.env["stock.return.picking"].with_context(
244+
active_ids=origin_delivery.ids,
245+
active_id=origin_delivery.id,
246+
active_model="stock.picking",
247+
)
248+
)
249+
stock_return_picking_form.create_rma = True
250+
stock_return_picking_form.rma_operation_id = self.operation
251+
return_wizard = stock_return_picking_form.save()
252+
return_line = return_wizard.product_return_moves.filtered(
253+
lambda m, p=self.product: m.product_id == p
254+
)
255+
self.assertEqual(return_line.rma_operation_id, self.operation)
256+
picking_action = return_wizard.create_returns()
257+
reception = self.env["stock.picking"].browse(picking_action["res_id"])
258+
move = reception.move_ids.filtered(lambda m, p=self.product: m.product_id == p)
259+
self.assertFalse(move.to_refund)
260+
261+
def test_15(self):
262+
"""if the refund action is ment to update quantity, return picking line
263+
to_refund field should be True"""
264+
self.operation.action_create_refund = "update_quantity"
265+
origin_delivery = self._create_delivery()
266+
stock_return_picking_form = Form(
267+
self.env["stock.return.picking"].with_context(
268+
active_ids=origin_delivery.ids,
269+
active_id=origin_delivery.id,
270+
active_model="stock.picking",
271+
)
272+
)
273+
stock_return_picking_form.create_rma = True
274+
stock_return_picking_form.rma_operation_id = self.operation
275+
return_wizard = stock_return_picking_form.save()
276+
return_line = return_wizard.product_return_moves.filtered(
277+
lambda m, p=self.product: m.product_id == p
278+
)
279+
self.assertEqual(return_line.rma_operation_id, self.operation)
280+
picking_action = return_wizard.create_returns()
281+
reception = self.env["stock.picking"].browse(picking_action["res_id"])
282+
move = reception.move_ids.filtered(lambda m, p=self.product: m.product_id == p)
283+
self.assertTrue(move.to_refund)

rma_sale/models/rma.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,10 @@ def _prepare_delivery_procurements(self, scheduled_date=None, qty=None, uom=None
175175
return super()._prepare_delivery_procurements(
176176
scheduled_date=scheduled_date, qty=qty, uom=uom
177177
)
178+
179+
def _prepare_reception_procurement_vals(self, group=None):
180+
"""This method is used only for reception and a specific RMA IN route."""
181+
vals = super()._prepare_reception_procurement_vals(group=group)
182+
if self.move_id and self.move_id.sale_line_id:
183+
vals["sale_line_id"] = self.move_id.sale_line_id.id
184+
return vals

rma_sale/tests/test_rma_sale.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,34 @@ def test_report_rma(self):
222222
res = str(res[0])
223223
self.assertRegex(res, self.sale_order.name)
224224
self.assertRegex(res, operation.name)
225+
226+
def test_manual_refund_no_quantity_impact(self):
227+
"""If the operation is meant for a manual refund, the delivered quantity
228+
should not be updated."""
229+
self.operation.action_create_refund = "manual_after_receipt"
230+
order = self.sale_order
231+
order_line = order.order_line
232+
self.assertEqual(order_line.qty_delivered, 5)
233+
wizard = self._rma_sale_wizard(order)
234+
rma = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"])
235+
self.assertEqual(rma.reception_move_id.sale_line_id, order_line)
236+
rma.action_confirm()
237+
rma.reception_move_id.quantity_done = rma.product_uom_qty
238+
rma.reception_move_id.picking_id._action_done()
239+
self.assertEqual(order.order_line.qty_delivered, 5)
240+
241+
def test_no_manual_refund_quantity_impact(self):
242+
"""If the operation is meant for a manual refund, the delivered quantity
243+
should not be updated."""
244+
self.operation.action_create_refund = "update_quantity"
245+
order = self.sale_order
246+
order_line = order.order_line
247+
self.assertEqual(order_line.qty_delivered, 5)
248+
wizard = self._rma_sale_wizard(order)
249+
rma = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"])
250+
self.assertEqual(rma.reception_move_id.sale_line_id, order_line)
251+
rma.action_confirm()
252+
self.assertFalse(rma.can_be_refunded)
253+
rma.reception_move_id.quantity_done = rma.product_uom_qty
254+
rma.reception_move_id.picking_id._action_done()
255+
self.assertEqual(order.order_line.qty_delivered, 0)

0 commit comments

Comments
 (0)