Skip to content

Commit

Permalink
add stock_account_fifo_return_origin
Browse files Browse the repository at this point in the history
  • Loading branch information
yostashiro committed Jun 22, 2024
1 parent 92445cb commit 184b703
Show file tree
Hide file tree
Showing 13 changed files with 568 additions and 2 deletions.
6 changes: 6 additions & 0 deletions setup/stock_account_fifo_return_origin/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,
)
70 changes: 70 additions & 0 deletions stock_account_fifo_return_origin/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
================================
Stock Account FIFO Return Origin
================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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_account_fifo_return_origin
: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_account_fifo_return_origin
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/154/16.0
:alt: Try me on Runbot

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

This module makes adjustment to the standard behavior with regards to candidate SVLs
that are used in purchase returns; if the SVL linked to the origin move (receipt) has
remaining quantity, that SVL should be consumed first.

**Table of contents**

.. contents::
:local:

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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_account_fifo_return_origin%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 Limited

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_account_fifo_return_origin>`_ 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_account_fifo_return_origin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
11 changes: 11 additions & 0 deletions stock_account_fifo_return_origin/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2024 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Stock Account FIFO Return Origin",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Quartile Limited, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-workflow",
"depends": ["stock_account_product_run_fifo_hook"],
}
3 changes: 3 additions & 0 deletions stock_account_fifo_return_origin/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import product
from . import stock_move
from . import stock_move_line
19 changes: 19 additions & 0 deletions stock_account_fifo_return_origin/models/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class Product(models.Model):
_inherit = "product.product"

def _get_candidates(self, company):
candidates = super()._get_candidates(company)
returned_moves = self._context.get("origin_returned_moves")
if not returned_moves:
return candidates
origin_svl = returned_moves.filtered(
lambda x: x.product_id == self
).stock_valuation_layer_ids
candidates = origin_svl | candidates
return candidates
19 changes: 19 additions & 0 deletions stock_account_fifo_return_origin/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


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

def _action_done(self, cancel_backorder=False):
origin_returned_moves = self.browse()
for move in self:
if move._is_out():
origin_returned_moves |= move.origin_returned_move_id
# We cannot assign origin returned move context to individual moves, therefore
# assign them all to self
if origin_returned_moves:
self = self.with_context(origin_returned_moves=origin_returned_moves)
return super()._action_done(cancel_backorder)
14 changes: 14 additions & 0 deletions stock_account_fifo_return_origin/models/stock_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models


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

@api.model
def _create_correction_svl(self, move, diff):
if move._is_in() and diff < 0:
move = move.with_context(origin_returned_moves=move)
return super()._create_correction_svl(move, diff)
3 changes: 3 additions & 0 deletions stock_account_fifo_return_origin/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module makes adjustment to the standard behavior with regards to candidate SVLs
that are used in purchase returns; if the SVL linked to the origin move (receipt) has
remaining quantity, that SVL should be consumed first.
Loading

0 comments on commit 184b703

Please sign in to comment.