diff --git a/setup/stock_account_fifo_return_origin/odoo/addons/stock_account_fifo_return_origin b/setup/stock_account_fifo_return_origin/odoo/addons/stock_account_fifo_return_origin new file mode 120000 index 00000000..7d12f69a --- /dev/null +++ b/setup/stock_account_fifo_return_origin/odoo/addons/stock_account_fifo_return_origin @@ -0,0 +1 @@ +../../../../stock_account_fifo_return_origin \ No newline at end of file diff --git a/setup/stock_account_fifo_return_origin/setup.py b/setup/stock_account_fifo_return_origin/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/stock_account_fifo_return_origin/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_account_fifo_return_origin/README.rst b/stock_account_fifo_return_origin/README.rst new file mode 100644 index 00000000..f7aa90b0 --- /dev/null +++ b/stock_account_fifo_return_origin/README.rst @@ -0,0 +1,73 @@ +================================ +Stock Account FIFO Return Origin +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f365b070c877cb49d483654699911d0f9d351de248cfca5a6cdf11258d8a7017 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/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 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 `_. +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 `_. + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_account_fifo_return_origin/__init__.py b/stock_account_fifo_return_origin/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/stock_account_fifo_return_origin/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_account_fifo_return_origin/__manifest__.py b/stock_account_fifo_return_origin/__manifest__.py new file mode 100644 index 00000000..c4bb6546 --- /dev/null +++ b/stock_account_fifo_return_origin/__manifest__.py @@ -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, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-workflow", + "depends": ["stock_account"], +} diff --git a/stock_account_fifo_return_origin/models/__init__.py b/stock_account_fifo_return_origin/models/__init__.py new file mode 100644 index 00000000..b834c96a --- /dev/null +++ b/stock_account_fifo_return_origin/models/__init__.py @@ -0,0 +1,3 @@ +from . import product +from . import stock_move +from . import stock_move_line diff --git a/stock_account_fifo_return_origin/models/product.py b/stock_account_fifo_return_origin/models/product.py new file mode 100644 index 00000000..519c5a9a --- /dev/null +++ b/stock_account_fifo_return_origin/models/product.py @@ -0,0 +1,20 @@ +# 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_fifo_candidates(self, company): + candidates = super()._get_fifo_candidates(company) + returned_moves = self._context.get("origin_returned_moves") + if not returned_moves: + return candidates + returned_moves = returned_moves.filtered(lambda x: x.product_id == self) + origin_svl = returned_moves.stock_valuation_layer_ids.filtered( + lambda x: x.remaining_qty > 0.00 + ) + candidates = origin_svl | candidates + return candidates diff --git a/stock_account_fifo_return_origin/models/stock_move.py b/stock_account_fifo_return_origin/models/stock_move.py new file mode 100644 index 00000000..ddc109f2 --- /dev/null +++ b/stock_account_fifo_return_origin/models/stock_move.py @@ -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) diff --git a/stock_account_fifo_return_origin/models/stock_move_line.py b/stock_account_fifo_return_origin/models/stock_move_line.py new file mode 100644 index 00000000..a75398d3 --- /dev/null +++ b/stock_account_fifo_return_origin/models/stock_move_line.py @@ -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) diff --git a/stock_account_fifo_return_origin/readme/DESCRIPTION.rst b/stock_account_fifo_return_origin/readme/DESCRIPTION.rst new file mode 100644 index 00000000..94d5d00a --- /dev/null +++ b/stock_account_fifo_return_origin/readme/DESCRIPTION.rst @@ -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. diff --git a/stock_account_fifo_return_origin/static/description/index.html b/stock_account_fifo_return_origin/static/description/index.html new file mode 100644 index 00000000..912eb241 --- /dev/null +++ b/stock_account_fifo_return_origin/static/description/index.html @@ -0,0 +1,415 @@ + + + + + +Stock Account FIFO Return Origin + + + +
+

Stock Account FIFO Return Origin

+ + +

Beta License: AGPL-3 OCA/stock-logistics-workflow Translate me on Weblate Try me on Runboat

+

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

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Quartile
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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 project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/stock_account_fifo_return_origin/tests/__init__.py b/stock_account_fifo_return_origin/tests/__init__.py new file mode 100644 index 00000000..3f123147 --- /dev/null +++ b/stock_account_fifo_return_origin/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_account_fifo_return_origin diff --git a/stock_account_fifo_return_origin/tests/test_stock_account_fifo_return_origin.py b/stock_account_fifo_return_origin/tests/test_stock_account_fifo_return_origin.py new file mode 100644 index 00000000..4dce3df4 --- /dev/null +++ b/stock_account_fifo_return_origin/tests/test_stock_account_fifo_return_origin.py @@ -0,0 +1,85 @@ +# Copyright 2024 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from odoo.tests.common import Form, TransactionCase + + +class TestStockAccountFifoReturnOrigin(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + product_category = cls.env["product.category"].create( + { + "name": "Test Category", + "property_cost_method": "fifo", + "property_valuation": "real_time", + } + ) + cls.product = cls.env["product.product"].create( + { + "name": "Test Product", + "type": "product", + "categ_id": product_category.id, + } + ) + cls.supplier_location = cls.env.ref("stock.stock_location_suppliers") + cls.stock_location = cls.env.ref("stock.stock_location_stock") + cls.picking_type_in = cls.env.ref("stock.picking_type_in") + + def create_receipt_picking(self, price_unit): + picking = self.env["stock.picking"].create( + { + "location_id": self.supplier_location.id, + "location_dest_id": self.stock_location.id, + "picking_type_id": self.picking_type_in.id, + } + ) + + move = self.env["stock.move"].create( + { + "name": "Test Move", + "product_id": self.product.id, + "product_uom_qty": 10, + "product_uom": self.product.uom_id.id, + "location_id": self.supplier_location.id, + "location_dest_id": self.stock_location.id, + "picking_id": picking.id, + "price_unit": price_unit, + } + ) + move._action_confirm() + move._action_assign() + move.move_line_ids.qty_done = 10 + picking.button_validate() + return picking + + def test_stock_account_fifo_return(self): + picking = self.create_receipt_picking(100) + move = picking.move_ids[0] + stock_valuation_layer = move.stock_valuation_layer_ids[0] + self.assertEqual(stock_valuation_layer.value, 1000) + + picking = self.create_receipt_picking(200) + move = picking.move_ids[0] + stock_valuation_layer = move.stock_valuation_layer_ids[0] + self.assertEqual(stock_valuation_layer.value, 2000) + + return_picking_wizard_form = Form( + self.env["stock.return.picking"].with_context( + active_ids=picking.ids, + active_id=picking.id, + active_model="stock.picking", + ) + ) + return_picking_wizard = return_picking_wizard_form.save() + return_picking_wizard.product_return_moves.write({"quantity": 10}) + return_picking_wizard_action = return_picking_wizard.create_returns() + return_picking = self.env["stock.picking"].browse( + return_picking_wizard_action["res_id"] + ) + return_move = return_picking.move_ids + return_move.move_line_ids.qty_done = 10 + return_picking.button_validate() + return_valuation_layer = return_move.stock_valuation_layer_ids[0] + self.assertEqual(abs(return_valuation_layer.value), 2000)