From e91a8606b33ef4667830a6cb008abaa0660d174f Mon Sep 17 00:00:00 2001 From: david Date: Mon, 16 Nov 2020 17:26:06 +0100 Subject: [PATCH] [IMP] rma_sale: prepare kits integration When a sale line has a phantom product (mrp kits) the RMA would not be possible as the wizard couldn't pair the components moves with the product in the line. With this approach, we can at least return the spare components of the original kit line. We also need some hooks to intervine in the main methods, like in invoicing. --- rma/models/account_move.py | 17 +++++++++++------ rma/models/rma.py | 22 +++++++++++++++++++--- rma/views/rma_portal_templates.xml | 4 ++-- rma/views/rma_views.xml | 2 +- 4 files changed, 33 insertions(+), 12 deletions(-) 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 @@ RMA # Date - Product + Product Quantity Status @@ -66,7 +66,7 @@ - + diff --git a/rma/views/rma_views.xml b/rma/views/rma_views.xml index f270b8da..a8efd316 100644 --- a/rma/views/rma_views.xml +++ b/rma/views/rma_views.xml @@ -353,7 +353,7 @@ RMA rma tree,form,pivot,calendar,activity - {"search_default_user_id": uid} + {}

Click to add a new RMA.