Skip to content

Commit

Permalink
[ADD] stock_account_return_origin_difference
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Jul 11, 2024
1 parent e6f3c42 commit c2d3f88
Show file tree
Hide file tree
Showing 10 changed files with 559 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/stock_account_return_origin_difference/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,
)
56 changes: 56 additions & 0 deletions stock_account_return_origin_difference/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
======================================
Stock Account Return Origin Difference
======================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:52cb3f6e0ddac8e9dda227d5cf06e51bf04f0d442395e672035deeaf6e717fe4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-qrtl%2Faxls--custom-lightgray.png?logo=github
:target: https://github.com/qrtl/axls-custom/tree/16.0/stock_account_return_origin_difference
:alt: qrtl/axls-custom

|badge1| |badge2| |badge3|

This module checks if there is a unit cost difference between the stock
valuation layers (SVLs) of receipts and their returns.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/qrtl/axls-custom/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/qrtl/axls-custom/issues/new?body=module:%20stock_account_return_origin_difference%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 part of the `qrtl/axls-custom <https://github.com/qrtl/axls-custom/tree/16.0/stock_account_return_origin_difference>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions stock_account_return_origin_difference/__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_account_return_origin_difference/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock Account Return Origin Difference",
"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,
}
1 change: 1 addition & 0 deletions stock_account_return_origin_difference/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_move
37 changes: 37 additions & 0 deletions stock_account_return_origin_difference/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2023 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


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

return_origin_svl_difference = fields.Boolean()

def _action_done(self, cancel_backorder=False):
moves = super()._action_done(cancel_backorder)
for move in moves:
if not (move._is_out() and move.origin_returned_move_id):
continue
origin_move_svls = (
move.origin_returned_move_id.stock_valuation_layer_ids.filtered(
lambda r: r.quantity > 0
)
)
for svl in origin_move_svls:
origin_move_svls |= svl.stock_valuation_layer_ids
origin_unit_cost = 0
return_unit_cost = 0
if origin_move_svls:
origin_value = sum(origin_move_svls.mapped("value"))
origin_quantity = sum(origin_move_svls.mapped("quantity"))
origin_unit_cost = origin_value / origin_quantity
return_move_svls = move.stock_valuation_layer_ids
if return_move_svls:
return_value = sum(return_move_svls.mapped("value"))
return_quantity = sum(return_move_svls.mapped("quantity"))
return_unit_cost = abs(return_value / return_quantity)
if origin_unit_cost != return_unit_cost:
move.return_origin_svl_difference = True
return moves
2 changes: 2 additions & 0 deletions stock_account_return_origin_difference/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module checks if there is a unit cost difference between the stock
valuation layers (SVLs) of receipts and their returns.
Loading

0 comments on commit c2d3f88

Please sign in to comment.