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
Carlos Vallés Fuster
parent
db07ef7d2b
commit
a42e3ce089
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"name": "RMA Sale",
|
"name": "RMA Sale",
|
||||||
"version": "15.0.1.0.0",
|
"version": "15.0.1.0.1",
|
||||||
"license": "LGPL-3",
|
"license": "LGPL-3",
|
||||||
"category": "RMA",
|
"category": "RMA",
|
||||||
"summary": "Links RMA with Sales Orders",
|
"summary": "Links RMA with Sales Orders",
|
||||||
|
|||||||
@@ -33,31 +33,5 @@ class StockRule(models.Model):
|
|||||||
line = self.env["rma.order.line"].browse([line])
|
line = self.env["rma.order.line"].browse([line])
|
||||||
if line.reference_move_id:
|
if line.reference_move_id:
|
||||||
return res
|
return res
|
||||||
if line.sale_line_id:
|
res["price_unit"] = line._get_price_unit()
|
||||||
moves = line.sale_line_id.move_ids.filtered(
|
|
||||||
lambda x: x.state == "done"
|
|
||||||
and x.location_id.usage in ("internal", "supplier")
|
|
||||||
and x.location_dest_id.usage == "customer"
|
|
||||||
)
|
|
||||||
if moves:
|
|
||||||
layers = moves.mapped("stock_valuation_layer_ids")
|
|
||||||
if layers:
|
|
||||||
price_unit = sum(layers.mapped("value")) / sum(
|
|
||||||
layers.mapped("quantity")
|
|
||||||
)
|
|
||||||
res["price_unit"] = price_unit
|
|
||||||
elif line.account_move_line_id:
|
|
||||||
sale_lines = line.account_move_line_id.sale_line_ids
|
|
||||||
moves = sale_lines.mapped("move_ids").filtered(
|
|
||||||
lambda x: x.state == "done"
|
|
||||||
and x.location_id.usage in ("internal", "supplier")
|
|
||||||
and x.location_dest_id.usage == "customer"
|
|
||||||
)
|
|
||||||
if moves:
|
|
||||||
layers = moves.mapped("stock_valuation_layer_ids")
|
|
||||||
if layers:
|
|
||||||
price_unit = sum(layers.mapped("value")) / sum(
|
|
||||||
layers.mapped("quantity")
|
|
||||||
)
|
|
||||||
res["price_unit"] = price_unit
|
|
||||||
return res
|
return res
|
||||||
|
|||||||
@@ -215,3 +215,33 @@ class RmaOrderLine(models.Model):
|
|||||||
):
|
):
|
||||||
qty += sale_line.product_uom_qty
|
qty += sale_line.product_uom_qty
|
||||||
return qty
|
return qty
|
||||||
|
|
||||||
|
def _get_price_unit(self):
|
||||||
|
self.ensure_one()
|
||||||
|
price_unit = super(RmaOrderLine, self)._get_price_unit()
|
||||||
|
if self.sale_line_id:
|
||||||
|
moves = self.sale_line_id.move_ids.filtered(
|
||||||
|
lambda x: x.state == "done"
|
||||||
|
and x.location_id.usage in ("internal", "supplier")
|
||||||
|
and x.location_dest_id.usage == "customer"
|
||||||
|
)
|
||||||
|
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:
|
||||||
|
sale_lines = self.account_move_line_id.sale_line_ids
|
||||||
|
moves = sale_lines.mapped("move_ids").filtered(
|
||||||
|
lambda x: x.state == "done"
|
||||||
|
and x.location_id.usage in ("internal", "supplier")
|
||||||
|
and x.location_dest_id.usage == "customer"
|
||||||
|
)
|
||||||
|
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