Skip to content

Commit

Permalink
adj, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Sep 20, 2024
1 parent fa44d0d commit 647c3c0
Show file tree
Hide file tree
Showing 3 changed files with 364 additions and 77 deletions.
7 changes: 6 additions & 1 deletion stock_valuation_fifo_lot/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,17 @@ def _get_price_unit(self):
[
("product_id", "=", self.product_id.id),
("lot_id", "=", self.lot_ids.id),
"|",
("qty_consumed", ">", 0),
("qty_remaining", ">", 0),
("company_id", "=", self.company_id.id),
],
order="id desc",
limit=1,
)
if move_line:
return move_line.value_consumed / move_line.qty_consumed
if move_line.qty_consumed:
return move_line.value_consumed / move_line.qty_consumed
else:
return move_line.value_remaining / move_line.qty_remaining
return super()._get_price_unit()
15 changes: 15 additions & 0 deletions stock_valuation_fifo_lot/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ def _compute_remaining_value(self):
"internal",
"transit",
) or rec.location_dest_usage not in ("internal", "transit"):
layers = rec.move_id.stock_valuation_layer_ids
remaining_qty_layers = layers.filtered(lambda l: l.remaining_qty > 0)
if not remaining_qty_layers:
rec.qty_remaining = 0
rec.value_remaining = 0
continue
rec.qty_remaining = rec.product_uom_id._compute_quantity(
sum(remaining_qty_layers.mapped("remaining_qty")),
rec.product_id.uom_id,
)
rec.value_remaining = (
sum(remaining_qty_layers.mapped("remaining_value"))
* sum(remaining_qty_layers.mapped("remaining_qty"))
/ rec.qty_remaining
)
continue
rec.qty_remaining = rec.qty_done - rec.qty_consumed
layers = rec.move_id.stock_valuation_layer_ids
Expand Down
Loading

0 comments on commit 647c3c0

Please sign in to comment.