mirror of
https://github.com/OCA/rma.git
synced 2025-02-16 17:11:47 +02:00
[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:
@@ -9,14 +9,13 @@ from odoo.tools import float_compare
|
|||||||
class AccountMove(models.Model):
|
class AccountMove(models.Model):
|
||||||
_inherit = "account.move"
|
_inherit = "account.move"
|
||||||
|
|
||||||
def post(self):
|
def _check_rma_invoice_lines_qty(self):
|
||||||
""" Avoids to validate a refund with less quantity of product than
|
"""We can't refund a different qty than the stated in the RMA.
|
||||||
quantity in the linked RMA.
|
Extend to change criteria """
|
||||||
"""
|
|
||||||
precision = self.env["decimal.precision"].precision_get(
|
precision = self.env["decimal.precision"].precision_get(
|
||||||
"Product Unit of Measure"
|
"Product Unit of Measure"
|
||||||
)
|
)
|
||||||
if (
|
return (
|
||||||
self.sudo()
|
self.sudo()
|
||||||
.mapped("invoice_line_ids")
|
.mapped("invoice_line_ids")
|
||||||
.filtered(
|
.filtered(
|
||||||
@@ -26,7 +25,13 @@ class AccountMove(models.Model):
|
|||||||
< 0
|
< 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(
|
raise ValidationError(
|
||||||
_(
|
_(
|
||||||
"There is at least one invoice lines whose quantity is "
|
"There is at least one invoice lines whose quantity is "
|
||||||
|
|||||||
@@ -925,16 +925,32 @@ class Rma(models.Model):
|
|||||||
rma.action_refund
|
rma.action_refund
|
||||||
"""
|
"""
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
line_form.product_id = self.product_id
|
product = self._get_refund_line_product()
|
||||||
line_form.quantity = self.product_uom_qty
|
qty, uom = self._get_refund_line_quantity()
|
||||||
line_form.product_uom_id = self.product_uom
|
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()
|
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):
|
def _get_refund_line_price_unit(self):
|
||||||
"""To be overriden in a third module with the proper origin values
|
"""To be overriden in a third module with the proper origin values
|
||||||
in case a sale order is linked to the original move"""
|
in case a sale order is linked to the original move"""
|
||||||
return self.product_id.lst_price
|
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
|
# Returning business methods
|
||||||
def create_return(self, scheduled_date, qty=None, uom=None):
|
def create_return(self, scheduled_date, qty=None, uom=None):
|
||||||
"""Intended to be invoked by the delivery wizard"""
|
"""Intended to be invoked by the delivery wizard"""
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
<tr class="active">
|
<tr class="active">
|
||||||
<th>RMA #</th>
|
<th>RMA #</th>
|
||||||
<th class='d-none d-md-table-cell'>Date</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='text-right'>Quantity</th>
|
||||||
<th class='d-none d-md-table-cell'>Status</th>
|
<th class='d-none d-md-table-cell'>Status</th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -66,7 +66,7 @@
|
|||||||
<span t-field="rma.date" />
|
<span t-field="rma.date" />
|
||||||
</td>
|
</td>
|
||||||
<!-- Portal users don't have access to unpublished products -->
|
<!-- Portal users don't have access to unpublished products -->
|
||||||
<td>
|
<td name="td_product">
|
||||||
<span t-esc="rma.sudo().product_id.display_name" />
|
<span t-esc="rma.sudo().product_id.display_name" />
|
||||||
</td>
|
</td>
|
||||||
<td class='text-right'>
|
<td class='text-right'>
|
||||||
|
|||||||
@@ -353,7 +353,7 @@
|
|||||||
<field name="name">RMA</field>
|
<field name="name">RMA</field>
|
||||||
<field name="res_model">rma</field>
|
<field name="res_model">rma</field>
|
||||||
<field name="view_mode">tree,form,pivot,calendar,activity</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">
|
<field name="help" type="html">
|
||||||
<p class="o_view_nocontent_smiling_face">
|
<p class="o_view_nocontent_smiling_face">
|
||||||
Click to add a new RMA.
|
Click to add a new RMA.
|
||||||
|
|||||||
Reference in New Issue
Block a user