diff --git a/setup/stock_location_empty/odoo/addons/stock_location_empty b/setup/stock_location_empty/odoo/addons/stock_location_empty new file mode 120000 index 000000000..b874f5b01 --- /dev/null +++ b/setup/stock_location_empty/odoo/addons/stock_location_empty @@ -0,0 +1 @@ +../../../../stock_location_empty \ No newline at end of file diff --git a/setup/stock_location_empty/setup.py b/setup/stock_location_empty/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_location_empty/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_location_empty/README.rst b/stock_location_empty/README.rst new file mode 100644 index 000000000..1d1d32216 --- /dev/null +++ b/stock_location_empty/README.rst @@ -0,0 +1,83 @@ +==================== +Stock Location Empty +==================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_location_empty + :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_empty + :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| + +Adds a filter for empty stock location. +Adds a new list of stock location with a stock quantity. + +**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 +~~~~~~~~~~~~ + +* Patrick Tombez +* Thierry Ducrest +* `Trobz `_: + + * Son Ho + +Other credits +~~~~~~~~~~~~~ + +The migration of this module from 12.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_empty/__init__.py b/stock_location_empty/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_location_empty/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_location_empty/__manifest__.py b/stock_location_empty/__manifest__.py new file mode 100644 index 000000000..527ffff93 --- /dev/null +++ b/stock_location_empty/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +{ + "name": "Stock Location Empty", + "summary": "Adds a filter for empty stock location", + "version": "14.0.1.0.0", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Warehouse", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "depends": [ + "stock", + ], + "data": [ + "views/stock.xml", + ], + "installable": True, + "application": False, +} diff --git a/stock_location_empty/i18n/fr.po b/stock_location_empty/i18n/fr.po new file mode 100644 index 000000000..430827698 --- /dev/null +++ b/stock_location_empty/i18n/fr.po @@ -0,0 +1,90 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_location_empty +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-11-22 07:37+0000\n" +"PO-Revision-Date: 2019-11-22 09:06+0100\n" +"Last-Translator: Thierry Ducrest \n" +"Language-Team: English\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"Language: en_US\n" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +msgid "Customer" +msgstr "Client" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +msgid "Customer Locations" +msgstr "Emplacements clients" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_inherit +msgid "Empty" +msgstr "Vide" + +#. module: stock_location_empty +#: model:ir.ui.menu,name:stock_location_empty.stock_location_empty_menu +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_inherit +msgid "Empty stock" +msgstr "Emplacements vides" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +msgid "Internal" +msgstr "Interne" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +msgid "Internal Locations" +msgstr "Emplacements internes" + +#. module: stock_location_empty +#: model:ir.model,name:stock_location_empty.model_stock_location +msgid "Inventory Locations" +msgstr "Emplacements de stock" + +#. module: stock_location_empty +#: model:ir.actions.act_window,name:stock_location_empty.action_stock_location_empty +msgid "Locations" +msgstr "Emplacements" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +msgid "Parent Location" +msgstr "Emplacement parent" + +#. module: stock_location_empty +#: model:ir.model.fields,field_description:stock_location_empty.field_stock_location__stock_quantity +msgid "Stock Amount" +msgstr "Quantité en stock" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_tree3 +msgid "Stock Location" +msgstr "Emplacement de stock" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +msgid "Stock Locations" +msgstr "Emplacements de stock" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +msgid "Vendor" +msgstr "Fournisseur" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +msgid "Vendor Locations" +msgstr "Adresses du vendeur" diff --git a/stock_location_empty/i18n/stock_location_empty.pot b/stock_location_empty/i18n/stock_location_empty.pot new file mode 100644 index 000000000..fd571055f --- /dev/null +++ b/stock_location_empty/i18n/stock_location_empty.pot @@ -0,0 +1,90 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_location_empty +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-11-22 07:37+0000\n" +"PO-Revision-Date: 2019-11-22 07:37+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_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +msgid "Customer" +msgstr "" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +msgid "Customer Locations" +msgstr "" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_inherit +msgid "Empty" +msgstr "" + +#. module: stock_location_empty +#: model:ir.ui.menu,name:stock_location_empty.stock_location_empty_menu +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_inherit +msgid "Empty stock" +msgstr "" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +msgid "Internal" +msgstr "" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +msgid "Internal Locations" +msgstr "" + +#. module: stock_location_empty +#: model:ir.model,name:stock_location_empty.model_stock_location +msgid "Inventory Locations" +msgstr "" + +#. module: stock_location_empty +#: model:ir.actions.act_window,name:stock_location_empty.action_stock_location_empty +msgid "Locations" +msgstr "" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +msgid "Parent Location" +msgstr "" + +#. module: stock_location_empty +#: model:ir.model.fields,field_description:stock_location_empty.field_stock_location__stock_amount +msgid "Stock Amount" +msgstr "" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_tree3 +msgid "Stock Location" +msgstr "" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +msgid "Stock Locations" +msgstr "" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +msgid "Vendor" +msgstr "" + +#. module: stock_location_empty +#: model_terms:ir.ui.view,arch_db:stock_location_empty.view_location_search_empty_2 +msgid "Vendor Locations" +msgstr "" + diff --git a/stock_location_empty/models/__init__.py b/stock_location_empty/models/__init__.py new file mode 100644 index 000000000..88493e35d --- /dev/null +++ b/stock_location_empty/models/__init__.py @@ -0,0 +1 @@ +from . import stock_location diff --git a/stock_location_empty/models/stock_location.py b/stock_location_empty/models/stock_location.py new file mode 100644 index 000000000..6ff7e0b18 --- /dev/null +++ b/stock_location_empty/models/stock_location.py @@ -0,0 +1,45 @@ +# Copyright 2018 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from psycopg2 import sql + +from odoo import fields, models + + +class StockLocation(models.Model): + _inherit = "stock.location" + + stock_amount = fields.Float( + compute="_compute_location_amount", search="_search_location_amount" + ) + + def _search_location_amount(self, operator, value): + if operator not in ("=", "!=", "<", "<=", ">", ">="): + return [] + query = sql.SQL( + """ + SELECT loc.id FROM stock_location loc + LEFT OUTER JOIN stock_quant quant ON loc.id = quant.location_id + GROUP BY loc.id + HAVING coalesce(sum(quantity), 0) {operator} %(value)s;""".format( + operator=operator + ) + ) + + self.env.cr.execute(query, {"value": value}) + res = self.env.cr.fetchall() + ids = [row[0] for row in res] + return [("id", "in", ids)] + + def _compute_location_amount(self): + query = sql.SQL( + """ + SELECT location_id, sum(quantity) + FROM stock_quant + WHERE location_id IN %(values)s + GROUP BY location_id; + """ + ) + self.env.cr.execute(query, {"values": tuple(self.ids)}) + totals = dict(self.env.cr.fetchall()) + for location in self: + location.stock_amount = totals.get(location.id, 0) diff --git a/stock_location_empty/readme/CONTRIBUTORS.rst b/stock_location_empty/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..b7634598f --- /dev/null +++ b/stock_location_empty/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* Patrick Tombez +* Thierry Ducrest +* `Trobz `_: + + * Son Ho diff --git a/stock_location_empty/readme/CREDITS.rst b/stock_location_empty/readme/CREDITS.rst new file mode 100644 index 000000000..ca6e4f9cd --- /dev/null +++ b/stock_location_empty/readme/CREDITS.rst @@ -0,0 +1 @@ +The migration of this module from 12.0 to 14.0 was financially supported by Camptocamp diff --git a/stock_location_empty/readme/DESCRIPTION.rst b/stock_location_empty/readme/DESCRIPTION.rst new file mode 100644 index 000000000..797079417 --- /dev/null +++ b/stock_location_empty/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +Adds a filter for empty stock location. +Adds a new list of stock location with a stock quantity. diff --git a/stock_location_empty/static/description/index.html b/stock_location_empty/static/description/index.html new file mode 100644 index 000000000..d6e93e289 --- /dev/null +++ b/stock_location_empty/static/description/index.html @@ -0,0 +1,435 @@ + + + + + + +Stock Location Empty + + + +
+

Stock Location Empty

+ + +

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

+

Adds a filter for empty stock location. +Adds a new list of stock location with a stock quantity.

+

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 12.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_empty/tests/__init__.py b/stock_location_empty/tests/__init__.py new file mode 100644 index 000000000..3f8c8c487 --- /dev/null +++ b/stock_location_empty/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_location_empty diff --git a/stock_location_empty/tests/test_stock_location_empty.py b/stock_location_empty/tests/test_stock_location_empty.py new file mode 100644 index 000000000..1bad22878 --- /dev/null +++ b/stock_location_empty/tests/test_stock_location_empty.py @@ -0,0 +1,39 @@ +from odoo.tests import SavepointCase + + +class TestStockLocationChildren(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.stock_input = cls.env["stock.location"].create( + { + "name": "Test", + "usage": "internal", + } + ) + cls.stock_quant1 = cls.env["stock.quant"].create( + { + "product_id": cls.env.ref("product.product_delivery_01").id, + "location_id": cls.stock_input.id, + "quantity": 60, + } + ) + cls.stock_quant1 = cls.env["stock.quant"].create( + { + "product_id": cls.env.ref("product.product_delivery_02").id, + "location_id": cls.stock_input.id, + "quantity": 50, + } + ) + + def test_stock_location_amount(self): + self.assertEqual(self.stock_input.stock_amount, 110.0) + location_record = self.env["stock.location"].search( + [("stock_amount", "=", 110.0)] + ) + self.assertEqual(location_record.stock_amount, 110) + record_search = self.env["stock.location"].search( + [("stock_amount", "in", [110, 111])] + ) + all_record = self.env["stock.location"].search([]) + self.assertEqual(record_search, all_record) diff --git a/stock_location_empty/views/stock.xml b/stock_location_empty/views/stock.xml new file mode 100644 index 000000000..9d7449a8f --- /dev/null +++ b/stock_location_empty/views/stock.xml @@ -0,0 +1,93 @@ + + + + + stock.location.tree + stock.location + + + + + + + + + + + + + stock.location.search.inherit + stock.location + + + + + + + + + + + stock.location.search2 + stock.location + + + + + + + + + + + + + + + Locations + stock.location + ir.actions.act_window + + + {'search_default_in_location':1, 'search_default_stock_amount': 1} + + + + Empty stock + + + + + +