Skip to content

Commit

Permalink
adj
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Sep 21, 2024
1 parent 647c3c0 commit 88e3356
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion stock_valuation_fifo_lot/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _run_fifo(self, quantity, company):
move_lines = correction_move_line or fifo_move._get_out_move_lines()
for ml in move_lines:
fifo_lot = ml.force_fifo_lot_id or ml.lot_id
ml_qty = fifo_move.product_uom._compute_quantity(ml.qty_done, self.uom_id)
ml_qty = ml.product_uom_id._compute_quantity(ml.qty_done, self.uom_id)
fifo_qty = min(remaining_qty, ml_qty)
self = self.with_context(fifo_lot=fifo_lot, fifo_qty=fifo_qty)
ml_fifo_vals = super()._run_fifo(fifo_qty, company)
Expand Down
5 changes: 2 additions & 3 deletions stock_valuation_fifo_lot/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _get_price_unit(self):
if hasattr(self, "purchase_line_id") and self.purchase_line_id:
return super()._get_price_unit()
if self.product_id.cost_method == "fifo" and len(self.lot_ids) == 1:
# Get the last consumed incoming move line.
# Get the most recent incoming move line for the lot.
move_line = self.env["stock.move.line"].search(
[
("product_id", "=", self.product_id.id),
Expand All @@ -71,6 +71,5 @@ def _get_price_unit(self):
if move_line:
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 move_line.value_remaining / move_line.qty_remaining
return super()._get_price_unit()
27 changes: 15 additions & 12 deletions stock_valuation_fifo_lot/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,29 @@ 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
# Specifically for the case where qty_done of the outgoing
# stock move line with done state is reduced, which creates
# a positive stock valuation layer for the outgoing move.
layers = rec.move_id.stock_valuation_layer_ids.filtered(
lambda l: l.remaining_qty > 0
)
if not layers:
rec.qty_remaining = 0.0
rec.value_remaining = 0.0
continue
rec.qty_remaining = rec.product_uom_id._compute_quantity(
sum(remaining_qty_layers.mapped("remaining_qty")),
rec.product_id.uom_id,
rec.qty_remaining = rec.product_id.uom_id._compute_quantity(
sum(layers.mapped("remaining_qty")), rec.product_uom_id
)
rec.value_remaining = (
sum(remaining_qty_layers.mapped("remaining_value"))
* sum(remaining_qty_layers.mapped("remaining_qty"))
sum(layers.mapped("remaining_value"))
* sum(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
remaining_qty = rec.product_uom_id._compute_quantity(
sum(layers.mapped("remaining_qty")), rec.product_id.uom_id
remaining_qty = rec.product_id.uom_id._compute_quantity(
sum(layers.mapped("remaining_qty")), rec.product_uom_id
)
if not remaining_qty:
rec.qty_remaining = 0
Expand Down
7 changes: 5 additions & 2 deletions stock_valuation_fifo_lot/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ Main UI Changes
- 'Force FIFO Lot/Serial': Used when you are stuck by not being able to find a FIFO
balance for the lot in an outgoing move line.

.. [*] Updated only for valued incoming moves of the products with FIFO costing method.
.. [*] Updated only for valued incoming moves and outgoing moves where the qty_done has been
reduced in the completed state for products with FIFO costing method. For these outgoing moves,
the system generates positive stock valuation layers with remaining_qty and remaining_value,
which need to be reflected in the related move line.
The values here represent the theoretical figures in terms of FIFO costing,
meaning that they may differ from the actual stock situation especially for
those updated at the installation of this module.
those updated at the installation of this module.

0 comments on commit 88e3356

Please sign in to comment.