diff --git a/setup/stock_location_last_inventory_date/odoo/addons/stock_location_last_inventory_date b/setup/stock_location_last_inventory_date/odoo/addons/stock_location_last_inventory_date new file mode 120000 index 000000000..f6b3dd1eb --- /dev/null +++ b/setup/stock_location_last_inventory_date/odoo/addons/stock_location_last_inventory_date @@ -0,0 +1 @@ +../../../../stock_location_last_inventory_date \ No newline at end of file diff --git a/setup/stock_location_last_inventory_date/setup.py b/setup/stock_location_last_inventory_date/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_location_last_inventory_date/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_location_last_inventory_date/README.rst b/stock_location_last_inventory_date/README.rst new file mode 100644 index 000000000..fc77b50d4 --- /dev/null +++ b/stock_location_last_inventory_date/README.rst @@ -0,0 +1,86 @@ +================================== +Stock Location Last Inventory Date +================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_location_last_inventory_date + :alt: OCA/stock-logistics-warehouse +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-14-0/stock-logistics-warehouse-14-0-stock_location_last_inventory_date + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/153/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Add a stored computed field on locations that states the last inventory date +of the location (only for validated inventories). This is only computed +for leaf locations, not parent ones. + +.. 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 `_ + +**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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* Carlos Serra-Toro +* `Trobz `_: + +Other credits +~~~~~~~~~~~~~ + +The migration of this module from 13.0 to 14.0 was financially supported by Camptocamp + +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-warehouse `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_location_last_inventory_date/__init__.py b/stock_location_last_inventory_date/__init__.py new file mode 100644 index 000000000..67e28b5c3 --- /dev/null +++ b/stock_location_last_inventory_date/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from . import models diff --git a/stock_location_last_inventory_date/__manifest__.py b/stock_location_last_inventory_date/__manifest__.py new file mode 100644 index 000000000..77a148e4d --- /dev/null +++ b/stock_location_last_inventory_date/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +{ + "name": "Stock Location Last Inventory Date", + "summary": "Show the last inventory date for a leaf location", + "version": "14.0.1.0.0", + "development_status": "Alpha", + "category": "Warehouse", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["product", "stock"], + "data": ["views/stock_location_views.xml"], +} diff --git a/stock_location_last_inventory_date/i18n/stock_location_last_inventory_date.pot b/stock_location_last_inventory_date/i18n/stock_location_last_inventory_date.pot new file mode 100644 index 000000000..672ad01f0 --- /dev/null +++ b/stock_location_last_inventory_date/i18n/stock_location_last_inventory_date.pot @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_location_last_inventory_date +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.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_location_last_inventory_date +#: model:ir.model.fields,help:stock_location_last_inventory_date.field_stock_location__last_inventory_date +msgid "" +"Indicates the last inventory date for the location, including inventory done" +" on parents location." +msgstr "" + +#. module: stock_location_last_inventory_date +#: model:ir.model,name:stock_location_last_inventory_date.model_stock_location +msgid "Inventory Locations" +msgstr "" + +#. module: stock_location_last_inventory_date +#: model:ir.model.fields,field_description:stock_location_last_inventory_date.field_stock_location__last_inventory_date +msgid "Last Inventory Date" +msgstr "" diff --git a/stock_location_last_inventory_date/models/__init__.py b/stock_location_last_inventory_date/models/__init__.py new file mode 100644 index 000000000..e06d283bf --- /dev/null +++ b/stock_location_last_inventory_date/models/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from . import stock_location diff --git a/stock_location_last_inventory_date/models/stock_location.py b/stock_location_last_inventory_date/models/stock_location.py new file mode 100644 index 000000000..4d377b841 --- /dev/null +++ b/stock_location_last_inventory_date/models/stock_location.py @@ -0,0 +1,27 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import fields, models + + +class StockLocation(models.Model): + _inherit = "stock.location" + + last_inventory_date = fields.Datetime( + "Last Inventory Date", + compute="_compute_last_inventory_date", + help="Indicates the last inventory date for the location, " + "including inventory done on parents location.", + ) + + def _compute_last_inventory_date(self): + for location in self: + location_ids = [ + int(location_id) + for location_id in location.parent_path.rstrip("/").split("/") + ] + last_inventory = self.env["stock.inventory"].search( + [("location_ids", "in", location_ids), ("state", "=", "done")], + order="date desc", + limit=1, + ) + location.last_inventory_date = last_inventory.date diff --git a/stock_location_last_inventory_date/readme/CONTRIBUTORS.rst b/stock_location_last_inventory_date/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..d5dd63c17 --- /dev/null +++ b/stock_location_last_inventory_date/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Carlos Serra-Toro +* `Trobz `_: diff --git a/stock_location_last_inventory_date/readme/CREDITS.rst b/stock_location_last_inventory_date/readme/CREDITS.rst new file mode 100644 index 000000000..f37ebe757 --- /dev/null +++ b/stock_location_last_inventory_date/readme/CREDITS.rst @@ -0,0 +1 @@ +The migration of this module from 13.0 to 14.0 was financially supported by Camptocamp diff --git a/stock_location_last_inventory_date/readme/DESCRIPTION.rst b/stock_location_last_inventory_date/readme/DESCRIPTION.rst new file mode 100644 index 000000000..8335d5376 --- /dev/null +++ b/stock_location_last_inventory_date/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +Add a stored computed field on locations that states the last inventory date +of the location (only for validated inventories). This is only computed +for leaf locations, not parent ones. diff --git a/stock_location_last_inventory_date/static/description/icon.png b/stock_location_last_inventory_date/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_location_last_inventory_date/static/description/icon.png differ diff --git a/stock_location_last_inventory_date/static/description/index.html b/stock_location_last_inventory_date/static/description/index.html new file mode 100644 index 000000000..3aedc5054 --- /dev/null +++ b/stock_location_last_inventory_date/static/description/index.html @@ -0,0 +1,433 @@ + + + + + + +Stock Location Last Inventory Date + + + +
+

Stock Location Last Inventory Date

+ + +

Alpha License: AGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runbot

+

Add a stored computed field on locations that states the last inventory date +of the location (only for validated inventories). This is only computed +for leaf locations, not parent ones.

+
+

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

+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

The migration of this module from 13.0 to 14.0 was financially supported by Camptocamp

+
+
+

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

+

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

+
+
+
+ + diff --git a/stock_location_last_inventory_date/tests/__init__.py b/stock_location_last_inventory_date/tests/__init__.py new file mode 100644 index 000000000..8f8e66e4f --- /dev/null +++ b/stock_location_last_inventory_date/tests/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from . import test_stock_location diff --git a/stock_location_last_inventory_date/tests/test_stock_location.py b/stock_location_last_inventory_date/tests/test_stock_location.py new file mode 100644 index 000000000..8453738ae --- /dev/null +++ b/stock_location_last_inventory_date/tests/test_stock_location.py @@ -0,0 +1,82 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import fields +from odoo.exceptions import AccessError +from odoo.tests import SavepointCase + + +class TestStockLocation(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product = cls.env.ref("product.product_product_7") + cls.leaf_location = cls.env.ref("stock.location_refrigerator_small") + cls.top_location = cls.leaf_location.location_id + + def _create_user(self, name, groups): + return ( + self.env["res.users"] + .with_context({"no_reset_password": True}) + .create( + { + "name": name.capitalize(), + "password": "password", + "login": name, + "email": "{}@test.com".format(name.lower()), + "groups_id": [(6, 0, groups.ids)], + "company_ids": [(6, 0, self.env["res.company"].search([]).ids)], + } + ) + ) + + def test_leaf_location_non_privileged_user(self): + stock_user = self._create_user( + "Stock Normal", self.env.ref("stock.group_stock_user") + ) + stock_manager = self._create_user( + "Stock Admin", self.env.ref("stock.group_stock_manager") + ) + inventory = self.env["stock.inventory"].create( + { + "name": "Inventory Adjustment", + "product_ids": [(4, self.product.id)], + "location_ids": [(4, self.leaf_location.id)], + } + ) + inventory.with_user(stock_user).action_start() + inventory.with_user(stock_manager).action_validate() + self.assertEqual( + self.leaf_location.with_user(stock_user).last_inventory_date, inventory.date + ) + try: + # Triggers the computation indirectly, `date` is in the depends. + inventory.with_user(stock_user).date = fields.Datetime.now() + except AccessError: + self.fail("A non-privileged user could not trigger the recomputation.") + + def test_leaf_location(self): + self.assertFalse(self.leaf_location.child_ids) + inventory = self.env["stock.inventory"].create( + { + "name": "Inventory Adjustment", + "product_ids": [(4, self.product.id)], + "location_ids": [(4, self.leaf_location.id)], + } + ) + inventory.action_start() + inventory.action_validate() + self.assertEqual(self.leaf_location.last_inventory_date, inventory.date) + self.assertFalse(self.top_location.last_inventory_date) + + def test_top_location(self): + inventory = self.env["stock.inventory"].create( + { + "name": "Inventory Adjustment", + "product_ids": [(4, self.product.id)], + "location_ids": [(4, self.top_location.id)], + } + ) + inventory.action_start() + inventory.action_validate() + self.assertEqual(self.leaf_location.last_inventory_date, inventory.date) + self.assertEqual(self.top_location.last_inventory_date, inventory.date) diff --git a/stock_location_last_inventory_date/views/stock_location_views.xml b/stock_location_last_inventory_date/views/stock_location_views.xml new file mode 100644 index 000000000..d8bc18599 --- /dev/null +++ b/stock_location_last_inventory_date/views/stock_location_views.xml @@ -0,0 +1,13 @@ + + + + stock.location.last.inventory.date + stock.location + + + + + + + +