Skip to content

Commit

Permalink
[ADD] stock_move_value
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Nov 25, 2024
1 parent 845caa2 commit d601bc0
Show file tree
Hide file tree
Showing 14 changed files with 931 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup/stock_move_value/odoo/addons/stock_move_value
6 changes: 6 additions & 0 deletions setup/stock_move_value/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,
)
103 changes: 103 additions & 0 deletions stock_move_value/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
================
Stock Move Value
================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:60a07245e54e8d796953c1da2564b4f6f8cb7d78eea5fb1a37b08cc3b48b7e83
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |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_move_value
: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_move_value
: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 adds value fields to the stock move model, to add visibility
of how the move has affected the stock valuation.

- **Move Value**: Value of the move including related SVL values (i.e.
price differences and landed costs)
- **Move Origin Value**: Corresponding value of the origin move as of
the the time move was done. Only updated for vendor returns.
- **Value Discrepancy**: Move Value + Move Origin Value. Only updated
for vendor returns.
- **To Review**: Selected when Value Discrepancy is not zero. Users are
expected to unselect it when review is done.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

Odoo calculates the cost of outgoing stock moves based on the product's
costing method, no matter what the cause of the operation is. This can
be problematic especially when a user just reverts the purchase receipt
operation which was done by mistake (e.g., processing the wrong receipt
picking) for FIFO and AVCO products, as the returned value is not the
same as the value of the original receipt. Some auditors might see such
inconsistencies as the result of intended manipulation on the financial
performance.

For FIFO products, you can use the OCA module
stock_account_fifo_return_origin (yet to be added with
https://github.com/OCA/stock-logistics-workflow/pull/1649) to return the
same value as the receipt. However, there is no complete solution for
AVCO products.

This module aims to provide users with a means to identify discrepancies
resulting from their purchase return operations, allowing them to take
necessary actions (e.g., inventory revaluation) as appropriate.

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_move_value%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
-------

* Quartile

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.

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions stock_move_value/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions stock_move_value/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2024 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock Move Value",
"version": "16.0.1.0.0",
"author": "Quartile, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-workflow",
"category": "stock",
"license": "AGPL-3",
"depends": ["stock_account"],
"data": [
"views/stock_move_views.xml",
],
"installable": True,
}
92 changes: 92 additions & 0 deletions stock_move_value/i18n/ja.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_move_value
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-13 10:23+0000\n"
"PO-Revision-Date: 2024-07-13 10:23+0000\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_move_value
#: model:ir.model.fields,help:stock_move_value.field_stock_move__move_origin_value
msgid ""
"Corresponding value of the origin move as of the the time move was done. "
"Only updated for vendor returns."
msgstr ""
"在庫移動完了時点での元在庫移動の数量見合い評価額です。仕入返品のときのみ更新されます。"

#. module: stock_move_value
#: model:ir.model.fields,field_description:stock_move_value.field_stock_move__value_currency_id
msgid "Currency"
msgstr "通貨"

#. module: stock_move_value
#: model_terms:ir.ui.view,arch_db:stock_move_value.view_move_search_inherit
msgid "Discrepancy Reviewed"
msgstr "差額レビュー済"

#. module: stock_move_value
#: model:ir.model.fields,field_description:stock_move_value.field_stock_move__move_origin_value
msgid "Move Origin Value"
msgstr "元移動評価額"

#. module: stock_move_value
#: model:ir.model.fields,field_description:stock_move_value.field_stock_move__move_value
msgid "Move Value"
msgstr "移動評価額"

#. module: stock_move_value
#: model:ir.model.fields,help:stock_move_value.field_stock_move__value_discrepancy
msgid "Move Value + Move Origin Value. Only updated for vendor returns."
msgstr "移動評価額 + 元移動評価額。仕入返品のときのみ更新されます。"

#. module: stock_move_value
#: model_terms:ir.ui.view,arch_db:stock_move_value.view_move_search_inherit
msgid "Return Value Discrepancy"
msgstr "返品評価額差異"

#. module: stock_move_value
#: model:ir.model.fields,help:stock_move_value.field_stock_move__to_review_discrepancy
msgid ""
"Selected when Value Discrepancy is not zero. Users are expected to unselect "
"it when review is done."
msgstr ""
"返品評価額差異があるときに選択されます。レビューが済みましたら選択を外してください。"

#. module: stock_move_value
#: model:ir.model,name:stock_move_value.model_stock_move
msgid "Stock Move"
msgstr "在庫移動"

#. module: stock_move_value
#: model_terms:ir.ui.view,arch_db:stock_move_value.view_move_tree
#: model_terms:ir.ui.view,arch_db:stock_move_value.view_stock_move_form_inherit
msgid "To Review"
msgstr "要レビュー"

#. module: stock_move_value
#: model:ir.model.fields,field_description:stock_move_value.field_stock_move__to_review_discrepancy
#: model_terms:ir.ui.view,arch_db:stock_move_value.view_move_search_inherit
msgid "To Review Discrepancy"
msgstr "要差異レビュー"

#. module: stock_move_value
#: model:ir.model.fields,field_description:stock_move_value.field_stock_move__value_discrepancy
msgid "Value Discrepancy"
msgstr "評価額差異"

#. module: stock_move_value
#: model:ir.model.fields,help:stock_move_value.field_stock_move__move_value
msgid ""
"Value of the move including related SVL values (i.e. price differences and "
"landed costs)"
msgstr ""
"関連在庫評価レイヤー(価格差異や仕入諸掛によるもの)の金額を含む移動の評価額。"
1 change: 1 addition & 0 deletions stock_move_value/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_move
74 changes: 74 additions & 0 deletions stock_move_value/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright 2024 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from collections import defaultdict

from odoo import api, fields, models


class StockMove(models.Model):
_inherit = "stock.move"

value_currency_id = fields.Many2one(
"res.currency", related="company_id.currency_id"
)
move_value = fields.Monetary(
compute="_compute_move_value",
store=True,
currency_field="value_currency_id",
help="Value of the move including related SVL values (i.e. price differences "
"and landed costs)",
)
move_origin_value = fields.Monetary(
currency_field="value_currency_id",
help="Corresponding value of the origin move as of the the time move was done. "
"Only updated for vendor returns.",
)
value_discrepancy = fields.Monetary(
currency_field="value_currency_id",
help="Move Value + Move Origin Value. Only updated for vendor returns.",
)
to_review_discrepancy = fields.Boolean(
help="Selected when Value Discrepancy is not zero. Users are expected to "
"unselect it when review is done.",
)

@api.depends(
"stock_valuation_layer_ids",
"stock_valuation_layer_ids.stock_valuation_layer_ids",
)
def _compute_move_value(self):
for move in self:
# There can be multiple svls per move in case landed costs are entered
move.move_value = sum(move.stock_valuation_layer_ids.mapped("value"))

def _action_done(self, cancel_backorder=False):
origin_values = defaultdict(dict)
for move in self:
if not move._is_out():
continue
origin_move = move.origin_returned_move_id
if not origin_move:
continue
# There should be only one record
origin_svls = origin_move.stock_valuation_layer_ids.filtered(
lambda r: r.quantity > 0
)
origin_values[move.id] = {
"remaining_qty": origin_svls.remaining_qty,
"remaining_value": origin_svls.remaining_value,
}
moves = super()._action_done(cancel_backorder)
for move in moves:
move.move_value = sum(move.stock_valuation_layer_ids.mapped("value"))
if not move._is_out() or not move.origin_returned_move_id:
continue
move.move_origin_value = (
origin_values[move.id]["remaining_value"]
* move.product_qty
/ origin_values[move.id]["remaining_qty"]
)
move.value_discrepancy = move.move_origin_value + move.move_value
if move.value_discrepancy != 0.0:
move.to_review_discrepancy = True
return moves
11 changes: 11 additions & 0 deletions stock_move_value/readme/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Odoo calculates the cost of outgoing stock moves based on the product's costing method, no matter what the
cause of the operation is. This can be problematic especially when a user just reverts the purchase receipt
operation which was done by mistake (e.g., processing the wrong receipt picking) for FIFO and AVCO products,
as the returned value is not the same as the value of the original receipt. Some auditors might see such
inconsistencies as the result of intended manipulation on the financial performance.

For FIFO products, you can use the OCA module stock_account_fifo_return_origin (yet to be added with https://github.com/OCA/stock-logistics-workflow/pull/1649)
to return the same value as the receipt. However, there is no complete solution for AVCO products.

This module aims to provide users with a means to identify discrepancies resulting from their purchase
return operations, allowing them to take necessary actions (e.g., inventory revaluation) as appropriate.
11 changes: 11 additions & 0 deletions stock_move_value/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This module adds value fields to the stock move model, to add visibility of how the move
has affected the stock valuation.

- **Move Value**: Value of the move including related SVL values (i.e. price differences
and landed costs)
- **Move Origin Value**: Corresponding value of the origin move as of the the time move
was done. Only updated for vendor returns.
- **Value Discrepancy**: Move Value + Move Origin Value. Only updated for vendor
returns.
- **To Review**: Selected when Value Discrepancy is not zero. Users are expected to
unselect it when review is done.
Loading

0 comments on commit d601bc0

Please sign in to comment.