mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[IMP] centralize the logic to get the correct cost of the RMA.
This commit is contained in:
committed by
AaronHForgeFlow
parent
6a1ed17a69
commit
11cdd4a9e8
@@ -3,7 +3,7 @@
|
||||
|
||||
{
|
||||
"name": "RMA Account",
|
||||
"version": "15.0.1.1.0",
|
||||
"version": "15.0.1.1.1",
|
||||
"license": "LGPL-3",
|
||||
"category": "RMA",
|
||||
"summary": "Integrates RMA with Invoice Processing",
|
||||
|
||||
@@ -234,15 +234,8 @@ class AccountMoveLine(models.Model):
|
||||
and bool(l.move_id.reversed_entry_id) == is_line_reversing
|
||||
)
|
||||
qty_refunded = sum(
|
||||
<<<<<<< HEAD
|
||||
x.product_uom_id._compute_quantity(x.quantity, x.product_id.uom_id)
|
||||
for x in posted_invoice_lines
|
||||
=======
|
||||
[
|
||||
x.product_uom_id._compute_quantity(x.quantity, x.product_id.uom_id)
|
||||
for x in posted_invoice_lines
|
||||
]
|
||||
>>>>>>> 614c98c ([FIX] include anglo-saxon price unit calculation in refunds.)
|
||||
)
|
||||
product = self.product_id.with_company(self.company_id).with_context(
|
||||
is_returned=is_line_reversing
|
||||
|
||||
@@ -4,40 +4,6 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class StockRule(models.Model):
|
||||
_inherit = "stock.rule"
|
||||
|
||||
def _get_stock_move_values(
|
||||
self,
|
||||
product_id,
|
||||
product_qty,
|
||||
product_uom,
|
||||
location_id,
|
||||
name,
|
||||
origin,
|
||||
company_id,
|
||||
values,
|
||||
):
|
||||
res = super(StockRule, self)._get_stock_move_values(
|
||||
product_id,
|
||||
product_qty,
|
||||
product_uom,
|
||||
location_id,
|
||||
name,
|
||||
origin,
|
||||
company_id,
|
||||
values,
|
||||
)
|
||||
if "rma_line_id" in values:
|
||||
line = values.get("rma_line_id")
|
||||
line = self.env["rma.order.line"].browse([line])
|
||||
move = line.reference_move_id
|
||||
if move and move.stock_valuation_layer_ids:
|
||||
cost = move.stock_valuation_layer_ids[-1].unit_cost
|
||||
res["price_unit"] = cost
|
||||
return res
|
||||
|
||||
|
||||
class ProcurementGroup(models.Model):
|
||||
_inherit = "procurement.group"
|
||||
|
||||
|
||||
@@ -333,3 +333,19 @@ class RmaOrderLine(models.Model):
|
||||
)
|
||||
# Reconcile.
|
||||
amls.reconcile()
|
||||
|
||||
def _get_price_unit(self):
|
||||
self.ensure_one()
|
||||
price_unit = super(RmaOrderLine, self)._get_price_unit()
|
||||
if self.reference_move_id:
|
||||
move = self.reference_move_id
|
||||
layers = move.sudo().stock_valuation_layer_ids
|
||||
if layers:
|
||||
price_unit = sum(layers.mapped("value")) / sum(
|
||||
layers.mapped("quantity")
|
||||
)
|
||||
price_unit = price_unit
|
||||
elif self.account_move_line_id and self.type == "supplier":
|
||||
# We get the cost from the original invoice line
|
||||
price_unit = self.account_move_line_id.price_unit
|
||||
return price_unit
|
||||
|
||||
@@ -20,6 +20,7 @@ class StockMove(models.Model):
|
||||
!= self.product_id.categ_id.property_stock_valuation_account_id.id
|
||||
):
|
||||
line[2]["rma_line_id"] = self.rma_line_id.id
|
||||
return res
|
||||
|
||||
def _account_entry_move(self, qty, description, svl_id, cost):
|
||||
res = super(StockMove, self)._account_entry_move(qty, description, svl_id, cost)
|
||||
|
||||
Reference in New Issue
Block a user