Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4650][ADD] stock_valuation_fifo_lot #156

Open
wants to merge 17 commits into
base: 16.0
Choose a base branch
from
Open
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this to solve the issue of below case.

  • Receive 1 dozen (12 units in SVL)
  • Deliver 1 dozen
    With previous code, it will just deduct 1 unit from remaining qty of receiving SVL.

Copy link
Member

@yostashiro yostashiro Sep 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this the issue you mentioned about the Odoo core? If that is the case, we shouldn't be handling it in this module.

Anyway, I've changed the strategy to use the UoM of the product (not the move UoM) for all the added quantity columns in stock.move.line (for ease of balance comparison between stock valuation layers and stock move lines).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue I mentioned was not decreasing qty_done after product is delivered.
This is for just receive and deliver with same uom that is not default uom of product.

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.
Loading