Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions setup/stock_valuation_fifo_lot/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
6 changes: 6 additions & 0 deletions setup/stock_valuation_fifo_lot_mrp_landed_cost/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
192 changes: 192 additions & 0 deletions stock_valuation_fifo_lot/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
========================
Stock Valuation Fifo Lot
========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b737cb3e86aa1875b5331bbace25e4ed86b38353f8ab87359a5e27e69769960d
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_valuation_fifo_lot
:alt: OCA/stock-logistics-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-16-0/stock-logistics-workflow-16-0-stock_valuation_fifo_lot
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module changes the scope of FIFO cost calculation to specific lots/serials (as
opposed to products), effectively achieving Specific Identification costing method.

Example: Lot-Level Costing
~~~~~~~~~~~~~~~~~~~~~~~~~~

- Purchase:

- Lot A: 100 units at $10 each.
- Lot B: 100 units at $12 each.

- Sale:

- 50 units from Lot B.

- COGS Calculation:

- 50 units * $12 = $600 assigned to COGS.

- Ending Inventory:

- Lot A: 100 units at $10 each.
- Lot B: 50 units at $12 each.

Main UI Changes
~~~~~~~~~~~~~~~

- Stock Valuation Layer

- Adds the following field:

- 'Lots/Serials': Taken from related stock moves.

- Stock Move Line

- Adds the following fields:

- 'Qty Base' [*]: Base quantity for FIFO allocation; represents the total quantity
of the moves with incoming valuation for the move line. In product UoM.
- 'Qty Consumed' [*]: Consumed quantity by outgoing valuation. In product UoM.
- 'Value Consumed' [*]: Consumed value by outgoing valuation.
- 'Qty Remaining' [*]: Remaining quantity (the total by product should match that
of the inventory valuation). In product UoM.
- 'Value Remaining' [*]: Remaining value (the total by product should match that
of the inventory valuation).
- '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 products with FIFO costing method, for valued incoming
moves, and for outgoing moves where the qty_done has been reduced in the completed
state.
For these outgoing moves, the system generates positive stock valuation layers
with a remaining balance, 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.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Configuration
=============

Disable the 'Use Last Lot/Serial Cost for New Stock' setting under *Inventory >
Configuration > Settings*, which is enabled by default, to use the standard
`_get_price()` behavior instead of the lot cost, for receipts of specific lots/serials
with no link to a purchase order (i.e. customer returns and positive inventory
adjustments).

Usage
=====

Process an outgoing move with a lot/serial for a product of FIFO costing method, and the
costs are calculated based on the lot/serial.

You will get a user error in case the lot/serial of your choice (in an outgoing move)
does not have a FIFO balance (i.e. there is no remaining quantity for the incoming move
lines linked to the candidate SVL; this is expected to happen for lots/serials created
before the installation of this module, unless your actual inventory operations have
been strictly FIFO). In such situations, you should select a "rogue" lot/serial (one
that still exists in terms of FIFO costing, but not in reality, due to the inconsistency
carried over from the past) in the 'Force FIFO Lot/Serial' field so that this lot/serial
is used for FIFO costing instead.

To revalue a product with lot_ids displayed in the Stock Valuation Layer list view,
use the standard revaluation wizard. Set a lot_id in the wizard to revalue a specific
lot only. Only lots with a remaining quantity will appear in the dropdown list.

Known issues / Roadmap
======================

Updating the "Done" quantity of completed stock move lines for valued and tracked FIFO
products is not supported, in order to avoid overcomplicating the logic. Attempting to
perform such an operation will result in a user error.

Creating a landed cost for a specific receipt after revaluing a specific lot may not work
correctly. However, this scenario is highly unlikely to occur in real-world operations.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_valuation_fifo_lot%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Ecosoft
* Quartile

Contributors
~~~~~~~~~~~~

* `Ecosoft <http://ecosoft.co.th>`__:

* Tharathip Chaweewongphan <[email protected]>
* Saran Limpajitkutaporn <[email protected]>
* Pimolnat Suntian <[email protected]>

* `Quartile <https://www.quartile.co>`__:

* Aung Ko Ko Lin
* Yoshi Tashiro

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-newtratip| image:: https://github.com/newtratip.png?size=40px
:target: https://github.com/newtratip
:alt: newtratip

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-newtratip|

This module is part of the `OCA/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_valuation_fifo_lot>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions stock_valuation_fifo_lot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from . import models
from . import wizard
from .hooks import post_init_hook
24 changes: 24 additions & 0 deletions stock_valuation_fifo_lot/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 Ecosoft Co., Ltd (https://ecosoft.co.th)
# Copyright 2024 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

{
"name": "Stock Valuation Fifo Lot",
"version": "16.0.1.0.1",
"category": "Warehouse Management",
"development_status": "Alpha",
"license": "AGPL-3",
"author": "Ecosoft, Quartile, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-workflow",
"depends": ["stock_account"],
"data": [
"views/res_config_settings_views.xml",
"views/stock_move_line_views.xml",
"views/stock_package_level_views.xml",
"views/stock_valuation_layer_views.xml",
"wizard/stock_valuation_layer_revaluation_views.xml",
],
"installable": True,
"post_init_hook": "post_init_hook",
"maintainers": ["newtratip"],
}
40 changes: 40 additions & 0 deletions stock_valuation_fifo_lot/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2024-2025 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from odoo import SUPERUSER_ID, api
from odoo.tools import float_is_zero


def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})

moves = env["stock.move"].search([("stock_valuation_layer_ids", "!=", False)])
for move in moves:
if (
move.product_id.with_company(move.company_id).cost_method != "fifo"
or not move.lot_ids
):
continue
# svls will include the valuation layers of related landed costs as well
svls = move.stock_valuation_layer_ids
svls.lot_ids = move.lot_ids

Check warning on line 20 in stock_valuation_fifo_lot/hooks.py

View check run for this annotation

Codecov / codecov/patch

stock_valuation_fifo_lot/hooks.py#L19-L20

Added lines #L19 - L20 were not covered by tests
if move._is_out():
remaining_qty = sum(svls.mapped("remaining_qty"))

Check warning on line 22 in stock_valuation_fifo_lot/hooks.py

View check run for this annotation

Codecov / codecov/patch

stock_valuation_fifo_lot/hooks.py#L22

Added line #L22 was not covered by tests
if remaining_qty:
# The case where outgoing done qty is reduced
# Let the first move line take such adjustments.
move.move_line_ids[0].qty_base = remaining_qty
continue
consumed_qty = consumed_qty_bal = sum(svls.mapped("quantity")) - sum(

Check warning on line 28 in stock_valuation_fifo_lot/hooks.py

View check run for this annotation

Codecov / codecov/patch

stock_valuation_fifo_lot/hooks.py#L26-L28

Added lines #L26 - L28 were not covered by tests
svls.mapped("remaining_qty")
)
consumed_value = sum(svls.mapped("value")) - sum(svls.mapped("remaining_value"))
product_uom = move.product_id.uom_id

Check warning on line 32 in stock_valuation_fifo_lot/hooks.py

View check run for this annotation

Codecov / codecov/patch

stock_valuation_fifo_lot/hooks.py#L31-L32

Added lines #L31 - L32 were not covered by tests
for ml in move.move_line_ids.sorted("id"):
ml.qty_base = ml.product_uom_id._compute_quantity(ml.qty_done, product_uom)

Check warning on line 34 in stock_valuation_fifo_lot/hooks.py

View check run for this annotation

Codecov / codecov/patch

stock_valuation_fifo_lot/hooks.py#L34

Added line #L34 was not covered by tests
if float_is_zero(consumed_qty_bal, precision_rounding=product_uom.rounding):
continue
qty_to_allocate = min(consumed_qty_bal, ml.qty_base)
ml.qty_consumed += qty_to_allocate
consumed_qty_bal -= qty_to_allocate
ml.value_consumed += consumed_value * qty_to_allocate / consumed_qty

Check warning on line 40 in stock_valuation_fifo_lot/hooks.py

View check run for this annotation

Codecov / codecov/patch

stock_valuation_fifo_lot/hooks.py#L36-L40

Added lines #L36 - L40 were not covered by tests
39 changes: 39 additions & 0 deletions stock_valuation_fifo_lot/i18n/stock_valuation_fifo_lot.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_valuation_fifo_lot
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: stock_valuation_fifo_lot
#: model:ir.model.fields,field_description:stock_valuation_fifo_lot.field_stock_valuation_layer__lot_ids
msgid "Lots/Serial Numbers"
msgstr ""

#. module: stock_valuation_fifo_lot
#: model:ir.model,name:stock_valuation_fifo_lot.model_product_product
msgid "Product"
msgstr ""

#. module: stock_valuation_fifo_lot
#: model:ir.model,name:stock_valuation_fifo_lot.model_stock_landed_cost
msgid "Stock Landed Cost"
msgstr ""

#. module: stock_valuation_fifo_lot
#: model:ir.model,name:stock_valuation_fifo_lot.model_stock_move
msgid "Stock Move"
msgstr ""

#. module: stock_valuation_fifo_lot
#: model:ir.model,name:stock_valuation_fifo_lot.model_stock_valuation_layer
msgid "Stock Valuation Layer"
msgstr ""
10 changes: 10 additions & 0 deletions stock_valuation_fifo_lot/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from . import product_template
from . import product
from . import res_company
from . import res_config_settings
from . import stock_lot
from . import stock_move
from . import stock_move_line
from . import stock_valuation_layer
Loading