diff --git a/rma/models/rma.py b/rma/models/rma.py
index 78ba3124d..af6fa5646 100644
--- a/rma/models/rma.py
+++ b/rma/models/rma.py
@@ -911,9 +911,15 @@ def action_refund(self):
{
"refund_line_id": line.id,
"refund_id": refund.id,
- "state": "refunded",
}
)
+ line.rma_id._action_refund_after_hook()
+
+ def _action_refund_after_hook(self):
+ """This method sets the status to 'refunded' and allows you to add
+ more actions, such as for rma_sale.
+ """
+ self.state = "refunded"
def action_replace(self):
"""Invoked when 'Replace' button in rma form view is clicked."""
diff --git a/rma_sale/i18n/es.po b/rma_sale/i18n/es.po
index 3ab9401bb..37918f832 100644
--- a/rma_sale/i18n/es.po
+++ b/rma_sale/i18n/es.po
@@ -109,6 +109,11 @@ msgstr "Producto Permitido"
msgid "Allowed Quantity"
msgstr "Cantidad permitida"
+#. module: rma_sale
+#: model:ir.model.fields,field_description:rma_sale.field_rma__can_be_refunded_with_invoice
+msgid "Can Be Refunded With Invoice"
+msgstr ""
+
#. module: rma_sale
#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_rma_wizard_form_view
msgid "Cancel"
@@ -272,6 +277,11 @@ msgstr "Última actualización el"
msgid "Lines"
msgstr "Líneas"
+#. module: rma_sale
+#: model_terms:ir.ui.view,arch_db:rma_sale.rma_view_form
+msgid "Mark To Refund"
+msgstr "Marcar a reembolsar"
+
#. module: rma_sale
#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__move_id
msgid "Move"
diff --git a/rma_sale/i18n/rma_sale.pot b/rma_sale/i18n/rma_sale.pot
index dc52df740..662243b4b 100644
--- a/rma_sale/i18n/rma_sale.pot
+++ b/rma_sale/i18n/rma_sale.pot
@@ -103,6 +103,11 @@ msgstr ""
msgid "Allowed Quantity"
msgstr ""
+#. module: rma_sale
+#: model:ir.model.fields,field_description:rma_sale.field_rma__can_be_refunded_with_invoice
+msgid "Can Be Refunded With Invoice"
+msgstr ""
+
#. module: rma_sale
#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_rma_wizard_form_view
msgid "Cancel"
@@ -256,6 +261,11 @@ msgstr ""
msgid "Lines"
msgstr ""
+#. module: rma_sale
+#: model_terms:ir.ui.view,arch_db:rma_sale.rma_view_form
+msgid "Mark To Refund"
+msgstr ""
+
#. module: rma_sale
#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__move_id
msgid "Move"
diff --git a/rma_sale/models/rma.py b/rma_sale/models/rma.py
index a1c8f46a7..e9a3bab1b 100644
--- a/rma_sale/models/rma.py
+++ b/rma_sale/models/rma.py
@@ -47,6 +47,28 @@ class Rma(models.Model):
)
# Add index to this field, as we perform a search on it
refund_id = fields.Many2one(index=True)
+ can_be_refunded_with_invoice = fields.Boolean(
+ compute="_compute_can_be_refunded_with_invoice"
+ )
+
+ @api.depends(
+ "can_be_refunded",
+ "sale_line_id",
+ "sale_line_id.invoice_lines",
+ "move_id",
+ "move_id.rma_id",
+ "move_id.rma_id.sale_line_id",
+ "move_id.rma_id.sale_line_id.invoice_lines",
+ )
+ def _compute_can_be_refunded_with_invoice(self):
+ for rec in self:
+ rec.can_be_refunded_with_invoice = bool(
+ rec.can_be_refunded
+ and (
+ rec.sale_line_id.invoice_lines
+ or rec.move_id.rma_id.sale_line_id.invoice_lines
+ )
+ )
@api.depends("partner_id", "order_id")
def _compute_allowed_picking_ids(self):
@@ -120,33 +142,24 @@ def _unlink_refund_with_reception_move(self):
self.reception_move_id.sale_line_id = False
self.reception_move_id.to_refund = False
- def action_refund(self):
+ def action_refund_without_invoice(self):
+ for record in self.filtered("can_be_refunded"):
+ record._action_refund_after_hook()
+
+ def _action_refund_after_hook(self):
"""As we have made a refund, the return move + the refund should be linked to
the source sales order line, to decrease both the delivered and invoiced
quantity.
NOTE: The refund line is linked to the SO line in `_prepare_refund_line`.
"""
- _self = self
- # Do not generate a refund invoice if the sales line has not yet been invoiced
- # or if it is an RMA created from another RMA with the same condition
- not_refundable = self.filtered(
- lambda x: (x.sale_line_id and not x.sale_line_id.invoice_lines)
- or (
- x.move_id.rma_id.sale_line_id
- and not x.move_id.rma_id.sale_line_id.invoice_lines
- )
- )
- self -= not_refundable
- res = super().action_refund()
- for rma in _self:
+ res = super()._action_refund_after_hook()
+ for rma in self.filtered(lambda x: x.state == "refunded"):
if rma.sale_line_id:
rma._link_refund_with_reception_move()
elif not rma.sale_line_id and rma.move_id.rma_id.sudo().sale_line_id:
# If there is no sales line, we must apply it to the original RMA
rma.move_id.rma_id._link_refund_with_reception_move()
- # These RMAs should be set to this state anyway
- not_refundable.state = "refunded"
return res
def _prepare_refund_vals(self, origin=False):
diff --git a/rma_sale/tests/test_rma_sale.py b/rma_sale/tests/test_rma_sale.py
index 6a766b33a..5b45ccec7 100644
--- a/rma_sale/tests/test_rma_sale.py
+++ b/rma_sale/tests/test_rma_sale.py
@@ -219,7 +219,7 @@ def test_rma_rma_refund_from_so_without_invoice(self):
rma_extra.reception_move_id.quantity = rma_extra.product_uom_qty
rma_extra.reception_move_id.picking_id.button_validate()
self.assertEqual(rma_extra.state, "received")
- rma_extra.action_refund()
+ rma_extra.action_refund_without_invoice()
self.assertEqual(rma_extra.state, "refunded")
self.assertFalse(rma_extra.refund_line_id)
self.assertFalse(rma_extra.refund_id)
@@ -313,7 +313,7 @@ def test_create_rma_from_so_without_invoice(self):
rma.reception_move_id.quantity = rma.product_uom_qty
rma.reception_move_id.picking_id.button_validate()
# Refund the RMA
- rma.action_refund()
+ rma.action_refund_without_invoice()
self.assertEqual(self.order_line.qty_delivered, 0)
self.assertEqual(self.order_line.qty_invoiced, 0)
self.assertFalse(rma.refund_id)
diff --git a/rma_sale/views/rma_views.xml b/rma_sale/views/rma_views.xml
index 12e7764f9..bc4342123 100644
--- a/rma_sale/views/rma_views.xml
+++ b/rma_sale/views/rma_views.xml
@@ -7,6 +7,18 @@
rma
+
+