diff --git a/rma_account/models/invoice.py b/rma_account/models/invoice.py
index 233ec0d7..06d74042 100644
--- a/rma_account/models/invoice.py
+++ b/rma_account/models/invoice.py
@@ -3,6 +3,7 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import api, fields, models
+from odoo.tools.float_utils import float_compare
class AccountInvoice(models.Model):
@@ -14,9 +15,59 @@ class AccountInvoice(models.Model):
rmas = self.mapped('invoice_line_ids.rma_line_ids')
inv.rma_count = len(rmas)
+ def _prepare_invoice_line_from_rma_line(self, line):
+ qty = line.qty_to_refund
+ if float_compare(
+ qty, 0.0, precision_rounding=line.uom_id.rounding) <= 0:
+ qty = 0.0
+ # Todo fill taxes from somewhere
+ invoice_line = self.env['account.invoice.line']
+ data = {
+ 'purchase_line_id': line.id,
+ 'name': line.name + ': '+line.name,
+ 'origin': line.origin,
+ 'uom_id': line.uom_id.id,
+ 'product_id': line.product_id.id,
+ 'account_id': invoice_line.with_context(
+ {'journal_id': self.journal_id.id,
+ 'type': 'in_invoice'})._default_account(),
+ 'price_unit': line.company_id.currency_id.with_context(
+ date=self.date_invoice).compute(
+ line.price_unit, self.currency_id, round=False),
+ 'quantity': qty,
+ 'discount': 0.0,
+ 'account_analytic_id': line.analytic_account_id.id,
+ 'rma_line_ids': [(4, line.id)],
+ }
+ return data
+
+ @api.onchange('add_rma_line_id')
+ def on_change_add_rma_line_id(self):
+ if not self.add_rma_line_id:
+ return {}
+ if not self.partner_id:
+ self.partner_id = self.add_rma_line_id.partner_id.id
+
+ new_line = self.env['account.invoice.line']
+ if self.add_rma_line_id not in (
+ self.invoice_line_ids.mapped('rma_line_id')):
+ data = self._prepare_invoice_line_from_rma_line(
+ self.add_rma_line_id)
+ new_line = new_line.new(data)
+ new_line._set_additional_fields(self)
+ self.invoice_line_ids += new_line
+ self.add_rma_line_id = False
+ return {}
+
rma_count = fields.Integer(
compute=_compute_rma_count, string='# of RMA')
+ add_rma_line_id = fields.Many2one(
+ comodel_name='rma.order.line',
+ string="Add from RMA line",
+ ondelete="set null",
+ help="Create a refund in based on an existing rma_line")
+
@api.multi
def action_view_rma_supplier(self):
action = self.env.ref('rma.action_rma_supplier_lines')
diff --git a/rma_account/models/rma_order_line.py b/rma_account/models/rma_order_line.py
index 81789c18..2d49f855 100644
--- a/rma_account/models/rma_order_line.py
+++ b/rma_account/models/rma_order_line.py
@@ -218,3 +218,16 @@ class RmaOrderLine(models.Model):
result['views'] = [(res and res.id or False, 'form')]
result['res_id'] = invoice_ids[0]
return result
+
+ @api.multi
+ def name_get(self):
+ res = []
+ if self.env.context.get('rma'):
+ for rma in self:
+ res.append((rma.id, "%s %s qty:%s" % (
+ rma.name,
+ rma.product_id.name,
+ rma.product_qty)))
+ return res
+ else:
+ return super(RmaOrderLine, self).name_get()
diff --git a/rma_account/views/invoice_view.xml b/rma_account/views/invoice_view.xml
index c1097905..8b24a07d 100644
--- a/rma_account/views/invoice_view.xml
+++ b/rma_account/views/invoice_view.xml
@@ -62,6 +62,42 @@
+
+ account.invoice.supplier.rma
+ account.invoice
+
+
+
+
+
+
+
+
+
+ account.invoice.customer.rma
+ account.invoice
+
+
+
+
+
+
+
+
Invoice Line
account.invoice.line