diff --git a/stock_location_last_inventory_date/README.rst b/stock_location_last_inventory_date/README.rst new file mode 100644 index 000000000..6a0044428 --- /dev/null +++ b/stock_location_last_inventory_date/README.rst @@ -0,0 +1,80 @@ +================================== +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/13.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-13-0/stock-logistics-warehouse-13-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/13.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 + +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..51ee8ff81 --- /dev/null +++ b/stock_location_last_inventory_date/__manifest__.py @@ -0,0 +1,15 @@ +# 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": "13.0.1.0.0", + "development_status": "Alpha", + "category": "Warehouse Management", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["product", "stock"], +} 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..f11de4a08 --- /dev/null +++ b/stock_location_last_inventory_date/i18n/stock_location_last_inventory_date.pot @@ -0,0 +1,43 @@ +# 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+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-01-25 15:06+0000\n" +"PO-Revision-Date: 2021-01-25 15:06+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_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 (only for validated " +"inventories). It is only computed for leaf locations." +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 "" + +#. module: stock_location_last_inventory_date +#: model:ir.model.fields,field_description:stock_location_last_inventory_date.field_stock_location__validated_inventory_ids +msgid "Stock Inventories" +msgstr "" + +#. module: stock_location_last_inventory_date +#: model:ir.model.fields,help:stock_location_last_inventory_date.field_stock_location__validated_inventory_ids +msgid "Stock inventories in state validated for this location." +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..fa0eb421e --- /dev/null +++ b/stock_location_last_inventory_date/models/stock_location.py @@ -0,0 +1,44 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import api, fields, models + + +class StockLocation(models.Model): + _inherit = "stock.location" + + last_inventory_date = fields.Datetime( + "Last Inventory Date", + compute="_compute_last_inventory_date", + store=True, + help="Indicates the last inventory date for the location (only for " + "validated inventories). It is only computed for leaf locations.", + ) + + # This field reuses the Many2many already defined in the model + # stock.inventory, so this definition adds little overhead, and + # allows to create the list of depends needed by the field for the + # Last Inventory Date. + validated_inventory_ids = fields.Many2many( + "stock.inventory", + relation="stock_inventory_stock_location_rel", + column1="stock_location_id", + column2="stock_inventory_id", + string="Stock Inventories", + help="Stock inventories in state validated for this location.", + domain="[('location_ids', 'in', id), ('state', '=', 'done')]", + ) + + @api.depends("validated_inventory_ids", "validated_inventory_ids.write_date") + def _compute_last_inventory_date(self): + """Store date of the last inventory for each leaf location""" + for loc in self: + if ( + loc.usage != "view" + and not loc.child_ids + and loc.validated_inventory_ids + ): + loc.last_inventory_date = loc.validated_inventory_ids.sorted( + lambda inventory: inventory.write_date + )[-1].date + else: + loc.last_inventory_date = False 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..1d2f3d485 --- /dev/null +++ b/stock_location_last_inventory_date/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Carlos Serra-Toro 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..1e297f02f --- /dev/null +++ b/stock_location_last_inventory_date/static/description/index.html @@ -0,0 +1,427 @@ + + + + + + +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

+ +
+
+

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..4cd3f452f --- /dev/null +++ b/stock_location_last_inventory_date/tests/test_stock_location.py @@ -0,0 +1,44 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +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 test_leaf_location(self): + self.assertFalse(self.leaf_location.child_ids) + self.assertFalse(self.leaf_location.validated_inventory_ids) + self.assertFalse(self.leaf_location.last_inventory_date) + 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.validated_inventory_ids.ids, [inventory.id]) + self.assertEqual(self.leaf_location.last_inventory_date, inventory.date) + + def test_top_location(self): + self.assertTrue(self.top_location.child_ids) + self.assertFalse(self.top_location.validated_inventory_ids) + self.assertFalse(self.top_location.last_inventory_date) + 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.top_location.validated_inventory_ids.ids, [inventory.id]) + self.assertFalse(self.top_location.last_inventory_date)