diff --git a/rma/models/account_move.py b/rma/models/account_move.py index 3bd81e6c..7c8d0af8 100644 --- a/rma/models/account_move.py +++ b/rma/models/account_move.py @@ -9,14 +9,13 @@ from odoo.tools import float_compare class AccountMove(models.Model): _inherit = "account.move" - def post(self): - """ Avoids to validate a refund with less quantity of product than - quantity in the linked RMA. - """ + def _check_rma_invoice_lines_qty(self): + """We can't refund a different qty than the stated in the RMA. + Extend to change criteria """ precision = self.env["decimal.precision"].precision_get( "Product Unit of Measure" ) - if ( + return ( self.sudo() .mapped("invoice_line_ids") .filtered( @@ -26,7 +25,13 @@ class AccountMove(models.Model): < 0 ) ) - ): + ) + + def post(self): + """ Avoids to validate a refund with less quantity of product than + quantity in the linked RMA. + """ + if self._check_rma_invoice_lines_qty(): raise ValidationError( _( "There is at least one invoice lines whose quantity is " diff --git a/rma/models/rma.py b/rma/models/rma.py index 3ce4cb3b..554c8a90 100644 --- a/rma/models/rma.py +++ b/rma/models/rma.py @@ -925,16 +925,32 @@ class Rma(models.Model): rma.action_refund """ self.ensure_one() - line_form.product_id = self.product_id - line_form.quantity = self.product_uom_qty - line_form.product_uom_id = self.product_uom + product = self._get_refund_line_product() + qty, uom = self._get_refund_line_quantity() + line_form.product_id = product + line_form.quantity = qty + line_form.product_uom_id = uom line_form.price_unit = self._get_refund_line_price_unit() + def _get_refund_line_product(self): + """To be overriden in a third module with the proper origin values + in case a kit is linked with the rma""" + return self.product_id + + def _get_refund_line_quantity(self): + """To be overriden in a third module with the proper origin values + in case a kit is linked with the rma """ + return (self.product_uom_qty, self.product_uom) + def _get_refund_line_price_unit(self): """To be overriden in a third module with the proper origin values in case a sale order is linked to the original move""" return self.product_id.lst_price + def _get_extra_refund_line_vals(self): + """Override to write aditional stuff into the refund line""" + return {} + # Returning business methods def create_return(self, scheduled_date, qty=None, uom=None): """Intended to be invoked by the delivery wizard""" diff --git a/rma/views/rma_portal_templates.xml b/rma/views/rma_portal_templates.xml index ef0ea47d..002a5c80 100644 --- a/rma/views/rma_portal_templates.xml +++ b/rma/views/rma_portal_templates.xml @@ -46,7 +46,7 @@
Click to add a new RMA.