mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[FIX] rma_account: get correct account when a bill refund is created
and reference to a supplier rma is made
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Copyright 2017 ForgeFlow S.L.
|
||||
# Copyright 2017-22 ForgeFlow S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from odoo import api, fields, models
|
||||
@@ -14,29 +14,36 @@ class AccountMove(models.Model):
|
||||
rmas = self.mapped("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:
|
||||
def _prepare_invoice_line_from_rma_line(self, rma_line):
|
||||
sequence = max(self.line_ids.mapped("sequence")) + 1 if self.line_ids else 10
|
||||
qty = rma_line.qty_to_refund
|
||||
if float_compare(qty, 0.0, precision_rounding=rma_line.uom_id.rounding) <= 0:
|
||||
qty = 0.0
|
||||
# Todo fill taxes from somewhere
|
||||
invoice_line = self.env["account.move.line"]
|
||||
data = {
|
||||
"purchase_line_id": line.id,
|
||||
"name": line.name + ": " + line.name,
|
||||
"product_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(
|
||||
"move_id": self.id,
|
||||
"product_uom_id": rma_line.uom_id.id,
|
||||
"product_id": rma_line.product_id.id,
|
||||
"price_unit": rma_line.company_id.currency_id.with_context(
|
||||
date=self.date
|
||||
).compute(line.price_unit, self.currency_id, round=False),
|
||||
).compute(rma_line.price_unit, self.currency_id, round=False),
|
||||
"quantity": qty,
|
||||
"discount": 0.0,
|
||||
"rma_line_ids": [(4, line.id)],
|
||||
"rma_line_ids": [(4, rma_line.id)],
|
||||
"sequence": sequence + 1,
|
||||
}
|
||||
return data
|
||||
|
||||
def _post_process_invoice_line_from_rma_line(self, new_line, rma_line):
|
||||
new_line.name = "%s: %s" % (
|
||||
self.add_rma_line_id.name,
|
||||
new_line._get_computed_name(),
|
||||
)
|
||||
new_line.account_id = new_line._get_computed_account()
|
||||
new_line._onchange_price_subtotal()
|
||||
new_line._onchange_mark_recompute_taxes()
|
||||
return True
|
||||
|
||||
@api.onchange("add_rma_line_id")
|
||||
def on_change_add_rma_line_id(self):
|
||||
if not self.add_rma_line_id:
|
||||
@@ -48,9 +55,14 @@ class AccountMove(models.Model):
|
||||
if self.add_rma_line_id not in (self.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.line_ids += new_line
|
||||
self._post_process_invoice_line_from_rma_line(
|
||||
new_line, self.add_rma_line_id
|
||||
)
|
||||
# Compute invoice_origin.
|
||||
origins = set(self.line_ids.mapped("rma_line_id.name"))
|
||||
self.invoice_origin = ",".join(list(origins))
|
||||
self.add_rma_line_id = False
|
||||
self._onchange_currency()
|
||||
return {}
|
||||
|
||||
rma_count = fields.Integer(compute="_compute_rma_count", string="# of RMA")
|
||||
@@ -62,32 +74,24 @@ class AccountMove(models.Model):
|
||||
help="Create a refund in based on an existing rma_line",
|
||||
)
|
||||
|
||||
def action_view_rma_supplier(self):
|
||||
action = self.env.ref("rma.action_rma_supplier_lines")
|
||||
def action_view_rma(self):
|
||||
if self.move_type in ["in_invoice", "in_refund"]:
|
||||
action = self.env.ref("rma.action_rma_supplier_lines")
|
||||
form_view = self.env.ref("rma.view_rma_line_supplier_form", False)
|
||||
else:
|
||||
action = self.env.ref("rma.action_rma_customer_lines")
|
||||
form_view = self.env.ref("rma.view_rma_line_form", False)
|
||||
result = action.sudo().read()[0]
|
||||
rma_ids = self.mapped("line_ids.rma_line_ids").ids
|
||||
if rma_ids:
|
||||
# choose the view_mode accordingly
|
||||
if len(rma_ids) > 1:
|
||||
result["domain"] = [("id", "in", rma_ids)]
|
||||
else:
|
||||
res = self.env.ref("rma.view_rma_line_supplier_form", False)
|
||||
result["views"] = [(res and res.id or False, "form")]
|
||||
result["res_id"] = rma_ids[0]
|
||||
return result
|
||||
|
||||
def action_view_rma_customer(self):
|
||||
action = self.env.ref("rma.action_rma_customer_lines")
|
||||
result = action.sudo().read()[0]
|
||||
rma_ids = self.mapped("line_ids.rma_line_ids").ids
|
||||
if rma_ids:
|
||||
# choose the view_mode accordingly
|
||||
if len(rma_ids) > 1:
|
||||
result["domain"] = [("id", "in", rma_ids)]
|
||||
else:
|
||||
res = self.env.ref("rma.view_rma_line_form", False)
|
||||
result["views"] = [(res and res.id or False, "form")]
|
||||
result["res_id"] = rma_ids[0]
|
||||
# choose the view_mode accordingly
|
||||
if not rma_ids:
|
||||
result["domain"] = [("id", "in", [])]
|
||||
elif len(rma_ids) > 1:
|
||||
result["domain"] = [("id", "in", rma_ids)]
|
||||
else:
|
||||
res = form_view
|
||||
result["views"] = [(res and res.id or False, "form")]
|
||||
result["res_id"] = rma_ids and rma_ids[0] or False
|
||||
return result
|
||||
|
||||
|
||||
|
||||
@@ -5,22 +5,17 @@
|
||||
<field name="model">account.move</field>
|
||||
<field name="inherit_id" ref="account.view_move_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="before">
|
||||
<div
|
||||
class="oe_button_box"
|
||||
attrs="{'invisible': [('rma_count', '=', 0)]}"
|
||||
<div name="button_box" position="inside">
|
||||
<button
|
||||
type="object"
|
||||
name="action_view_rma"
|
||||
class="oe_stat_button"
|
||||
icon="fa-eject"
|
||||
groups="rma.group_rma_customer_user,rma.group_rma_supplier_user"
|
||||
>
|
||||
<button
|
||||
type="object"
|
||||
name="action_view_rma_customer"
|
||||
class="oe_stat_button"
|
||||
icon="fa-eject"
|
||||
groups="rma.group_rma_customer_user,rma.group_rma_supplier_user"
|
||||
>
|
||||
<field name="rma_count" widget="statinfo" string="RMA" />
|
||||
</button>
|
||||
</div>
|
||||
</field>
|
||||
<field name="rma_count" widget="statinfo" string="RMA" />
|
||||
</button>
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -55,10 +50,10 @@
|
||||
<field
|
||||
name="add_rma_line_id"
|
||||
context="{'rma': True}"
|
||||
domain="[('type', '=', 'customer'),('partner_id', '=', partner_id)]"
|
||||
domain="[('type', '=', 'supplier'),('partner_id', '=', partner_id)]"
|
||||
attrs="{'readonly': [('state','not in',['draft'])],
|
||||
'invisible': ['|', ('state', '=', 'paid'),
|
||||
('move_type', '=', 'in_invoice')]}"
|
||||
('move_type', '!=', 'in_refund')]}"
|
||||
class="oe_edit_only"
|
||||
options="{'no_create': True}"
|
||||
/>
|
||||
|
||||
@@ -4,3 +4,4 @@ from . import purchase_order
|
||||
from . import purchase_order_line
|
||||
from . import rma_operation
|
||||
from . import procurement
|
||||
from . import account_move
|
||||
|
||||
13
rma_purchase/models/account_move.py
Normal file
13
rma_purchase/models/account_move.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# Copyright 2017-22 ForgeFlow S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
def _prepare_invoice_line_from_rma_line(self, line):
|
||||
data = super(AccountMove, self)._prepare_invoice_line_from_rma_line(line)
|
||||
data["purchase_line_id"]: line.id
|
||||
return data
|
||||
Reference in New Issue
Block a user