mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
Merge pull request #301 from ForgeFlow/14.0-fix-get_valuation_from_all_layers
[14.0][FIX] rma_account: get price unit with all related layers on sale moves
This commit is contained in:
@@ -33,8 +33,12 @@ class StockRule(models.Model):
|
||||
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
|
||||
layers = move.stock_valuation_layer_ids
|
||||
price_unit = sum(layers.mapped("value")) / sum(
|
||||
layers.mapped("quantity")
|
||||
)
|
||||
|
||||
res["price_unit"] = price_unit
|
||||
return res
|
||||
|
||||
|
||||
|
||||
@@ -34,20 +34,30 @@ class StockRule(models.Model):
|
||||
if line.reference_move_id:
|
||||
return res
|
||||
if line.sale_line_id:
|
||||
moves = line.sale_line_id.move_ids
|
||||
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:
|
||||
# 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
|
||||
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")
|
||||
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:
|
||||
cost = layers[-1].unit_cost
|
||||
# TODO: Should we be smart in the choice of the move?
|
||||
res["price_unit"] = cost
|
||||
price_unit = sum(layers.mapped("value")) / sum(
|
||||
layers.mapped("quantity")
|
||||
)
|
||||
res["price_unit"] = price_unit
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user