mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[IMP]add rma lines to invoices as it is done with PO
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||||
|
|
||||||
from odoo import api, fields, models
|
from odoo import api, fields, models
|
||||||
|
from odoo.tools.float_utils import float_compare
|
||||||
|
|
||||||
|
|
||||||
class AccountInvoice(models.Model):
|
class AccountInvoice(models.Model):
|
||||||
@@ -14,9 +15,59 @@ class AccountInvoice(models.Model):
|
|||||||
rmas = self.mapped('invoice_line_ids.rma_line_ids')
|
rmas = self.mapped('invoice_line_ids.rma_line_ids')
|
||||||
inv.rma_count = len(rmas)
|
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(
|
rma_count = fields.Integer(
|
||||||
compute=_compute_rma_count, string='# of RMA')
|
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
|
@api.multi
|
||||||
def action_view_rma_supplier(self):
|
def action_view_rma_supplier(self):
|
||||||
action = self.env.ref('rma.action_rma_supplier_lines')
|
action = self.env.ref('rma.action_rma_supplier_lines')
|
||||||
|
|||||||
@@ -218,3 +218,16 @@ class RmaOrderLine(models.Model):
|
|||||||
result['views'] = [(res and res.id or False, 'form')]
|
result['views'] = [(res and res.id or False, 'form')]
|
||||||
result['res_id'] = invoice_ids[0]
|
result['res_id'] = invoice_ids[0]
|
||||||
return result
|
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()
|
||||||
|
|||||||
@@ -62,6 +62,42 @@
|
|||||||
</record>
|
</record>
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
|
<record id="view_invoice_supplier_rma_form" model="ir.ui.view">
|
||||||
|
<field name="name">account.invoice.supplier.rma</field>
|
||||||
|
<field name="model">account.invoice</field>
|
||||||
|
<field name="inherit_id" ref="account.invoice_supplier_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="reference" position="after">
|
||||||
|
<field name="add_rma_line_id"
|
||||||
|
context="{'rma': True}"
|
||||||
|
domain="[('type', '=', 'supplier'),
|
||||||
|
('partner_id', '=', partner_id)]"
|
||||||
|
attrs="{'readonly': [('state','not in',['draft'])],
|
||||||
|
'invisible': ['|', ('state', '=', 'done'),
|
||||||
|
('type', '=', 'in_invoice')]}" class="oe_edit_only"
|
||||||
|
options="{'no_create': True}"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="view_invoice_customer_rma_form" model="ir.ui.view">
|
||||||
|
<field name="name">account.invoice.customer.rma</field>
|
||||||
|
<field name="model">account.invoice</field>
|
||||||
|
<field name="inherit_id" ref="account.invoice_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="payment_term_id" position="after">
|
||||||
|
<field name="add_rma_line_id"
|
||||||
|
context="{'rma': True}"
|
||||||
|
domain="[('type', '=', 'customer'),
|
||||||
|
('partner_id', '=', partner_id)]"
|
||||||
|
attrs="{'readonly': [('state','not in',['draft'])],
|
||||||
|
'invisible': ['|', ('state', '=', 'done'),
|
||||||
|
('type', '=', 'out_invoice')]}" class="oe_edit_only"
|
||||||
|
options="{'no_create': True}"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
<record id="action_invoice_line" model="ir.actions.act_window">
|
<record id="action_invoice_line" model="ir.actions.act_window">
|
||||||
<field name="name">Invoice Line</field>
|
<field name="name">Invoice Line</field>
|
||||||
<field name="res_model">account.invoice.line</field>
|
<field name="res_model">account.invoice.line</field>
|
||||||
|
|||||||
Reference in New Issue
Block a user