Files
rma/rma/models/account_invoice.py
david 9614c93f88 [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.
2021-02-19 15:08:49 +01:00

44 lines
1.5 KiB
Python

# Copyright 2020 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, fields, models
from odoo.exceptions import ValidationError
from odoo.tools import float_compare
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
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")
return self.sudo().mapped("invoice_line_ids").filtered(
lambda r: (r.rma_id and float_compare(
r.quantity, r.rma_id.product_uom_qty, precision) < 0))
def action_invoice_open(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 "
"less than the quantity specified in its linked RMA."))
return super().action_invoice_open()
def unlink(self):
rma = self.mapped('invoice_line_ids.rma_id')
rma.write({'state': 'received'})
return super().unlink()
class AccountInvoiceLine(models.Model):
_inherit = 'account.invoice.line'
rma_id = fields.Many2one(
comodel_name='rma',
string='RMA',
)