[FIX+IMP] rma_sale: Proper dependency + propagate salesman

- Proper dependency is `sale_stock`, not `sale`, as we are using some fields added
  by this module.
- Propagate salesman from sales order when available.

TT25525
This commit is contained in:
Pedro M. Baeza
2020-09-14 19:28:12 +02:00
parent cc673918f2
commit c4372dde3e
3 changed files with 21 additions and 1 deletions

View File

@@ -12,7 +12,7 @@
"license": "AGPL-3",
"depends": [
"rma",
"sale",
"sale_stock",
],
"data": [
"views/assets.xml",

View File

@@ -81,3 +81,10 @@ class Rma(models.Model):
@api.onchange('order_id')
def _onchange_order_id(self):
self.product_id = self.picking_id = False
def _prepare_refund(self, invoice_form, origin):
"""Inject salesman from sales order (if any)"""
res = super()._prepare_refund(invoice_form, origin)
if self.order_id:
invoice_form.user_id = self.order_id.user_id
return res

View File

@@ -70,3 +70,16 @@ class TestRmaSale(SavepointCase):
rma.reception_move_id.picking_id + self.order_out_picking,
order.picking_ids,
)
# Refund the RMA
user = self.env["res.users"].create(
{
"login": "test_refund_with_so",
"name": "Test",
}
)
order.user_id = user.id
rma.action_confirm()
rma.reception_move_id.quantity_done = rma.product_uom_qty
rma.reception_move_id.picking_id.action_done()
rma.action_refund()
self.assertEqual(rma.refund_id.user_id, user)