[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.
This commit is contained in:
david
2020-11-16 17:26:06 +01:00
committed by Víctor Martínez
parent 1247b23914
commit e91a8606b3
4 changed files with 33 additions and 12 deletions

View File

@@ -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 "

View File

@@ -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"""

View File

@@ -46,7 +46,7 @@
<tr class="active">
<th>RMA #</th>
<th class='d-none d-md-table-cell'>Date</th>
<th>Product</th>
<th name="th_product">Product</th>
<th class='text-right'>Quantity</th>
<th class='d-none d-md-table-cell'>Status</th>
</tr>
@@ -66,7 +66,7 @@
<span t-field="rma.date" />
</td>
<!-- Portal users don't have access to unpublished products -->
<td>
<td name="td_product">
<span t-esc="rma.sudo().product_id.display_name" />
</td>
<td class='text-right'>

View File

@@ -353,7 +353,7 @@
<field name="name">RMA</field>
<field name="res_model">rma</field>
<field name="view_mode">tree,form,pivot,calendar,activity</field>
<field name="context">{"search_default_user_id": uid}</field>
<field name="context">{}</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Click to add a new RMA.