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
JasminSForgeFlow
parent
444da13e86
commit
ad713813c9
@@ -2,7 +2,7 @@
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
{
|
||||
"name": "RMA Purchase",
|
||||
"version": "15.0.1.0.0",
|
||||
"version": "15.0.1.0.1",
|
||||
"category": "RMA",
|
||||
"summary": "RMA from PO",
|
||||
"license": "LGPL-3",
|
||||
|
||||
@@ -4,55 +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])
|
||||
if line.reference_move_id:
|
||||
return res
|
||||
if line.purchase_order_line_id:
|
||||
moves = line.purchase_order_line_id.move_ids
|
||||
if moves:
|
||||
# TODO: Should we be smart in the choice of the move?
|
||||
layers = moves.mapped("stock_valuation_layer_ids")
|
||||
if layers:
|
||||
cost = layers[-1].unit_cost
|
||||
res["price_unit"] = cost
|
||||
elif line.account_move_line_id.purchase_line_id:
|
||||
purchase_lines = line.account_move_line_id.purchase_line_id
|
||||
moves = purchase_lines.mapped("move_ids")
|
||||
if moves:
|
||||
layers = moves.mapped("stock_valuation_layer_ids")
|
||||
if layers:
|
||||
cost = layers[-1].unit_cost
|
||||
# TODO: Should we be smart in the choice of the move?
|
||||
res["price_unit"] = cost
|
||||
return res
|
||||
|
||||
|
||||
class ProcurementGroup(models.Model):
|
||||
_inherit = "procurement.group"
|
||||
|
||||
|
||||
@@ -223,3 +223,25 @@ class RmaOrderLine(models.Model):
|
||||
):
|
||||
qty += self.uom_id._compute_quantity(line.product_qty, line.product_uom)
|
||||
return qty
|
||||
|
||||
def _get_price_unit(self):
|
||||
self.ensure_one()
|
||||
price_unit = super(RmaOrderLine, self)._get_price_unit()
|
||||
if self.purchase_order_line_id:
|
||||
moves = self.purchase_order_line_id.move_ids
|
||||
if moves:
|
||||
layers = moves.sudo().mapped("stock_valuation_layer_ids")
|
||||
if layers:
|
||||
price_unit = sum(layers.mapped("value")) / sum(
|
||||
layers.mapped("quantity")
|
||||
)
|
||||
elif self.account_move_line_id.purchase_line_id:
|
||||
purchase_lines = self.account_move_line_id.purchase_line_id
|
||||
moves = purchase_lines.mapped("move_ids")
|
||||
if moves:
|
||||
layers = moves.sudo().mapped("stock_valuation_layer_ids")
|
||||
if layers:
|
||||
price_unit = sum(layers.mapped("value")) / sum(
|
||||
layers.mapped("quantity")
|
||||
)
|
||||
return price_unit
|
||||
|
||||
Reference in New Issue
Block a user