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

[16.0][MIG] stock_valuation_fifo_lot: Migration to 16.0 #1676

Open
wants to merge 17 commits into
base: 16.0
Choose a base branch
from
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,
)
178 changes: 178 additions & 0 deletions stock_valuation_fifo_lot/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
========================
Stock Valuation Fifo Lot
========================

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

.. |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 only, for valued incoming
moves, and 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.

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.
4 changes: 4 additions & 0 deletions stock_valuation_fifo_lot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from . import models
from .hooks import post_init_hook
23 changes: 23 additions & 0 deletions stock_valuation_fifo_lot/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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.0",
"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",
],
"installable": True,
"post_init_hook": "post_init_hook",
"maintainers": ["newtratip"],
}
42 changes: 42 additions & 0 deletions stock_valuation_fifo_lot/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2024 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 = move.stock_valuation_layer_ids
svls.lot_ids = move.lot_ids
if move._is_out():
remaining_qty = sum(svls.mapped("remaining_qty"))
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(
svls.mapped("remaining_qty")
)
total_value = sum(svls.mapped("value")) + sum(
svls.stock_valuation_layer_ids.mapped("value")
)
consumed_value = total_value - sum(svls.mapped("remaining_value"))
product_uom = move.product_id.uom_id
for ml in move.move_line_ids.sorted("id"):
ml.qty_base = ml.product_uom_id._compute_quantity(ml.qty_done, product_uom)
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
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 ""
9 changes: 9 additions & 0 deletions stock_valuation_fifo_lot/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

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
Loading