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/__manifest__.py b/stock_location_empty/__manifest__.py index a86533fcd..527ffff93 100644 --- a/stock_location_empty/__manifest__.py +++ b/stock_location_empty/__manifest__.py @@ -3,14 +3,15 @@ { "name": "Stock Location Empty", - "version": "12.0.1.0.0", + "summary": "Adds a filter for empty stock location", + "version": "14.0.1.0.0", "author": "Camptocamp, Odoo Community Association (OCA)", "license": "AGPL-3", - "category": "stock", + "category": "Warehouse", + "website": "https://github.com/OCA/stock-logistics-warehouse", "depends": [ "stock", ], - "website": "https://github.com/OCA/stock-logistics-warehouse", "data": [ "views/stock.xml", ], diff --git a/stock_location_empty/i18n/fr.po b/stock_location_empty/i18n/fr.po index 75d7db891..430827698 100644 --- a/stock_location_empty/i18n/fr.po +++ b/stock_location_empty/i18n/fr.po @@ -65,7 +65,7 @@ msgid "Parent Location" msgstr "Emplacement parent" #. module: stock_location_empty -#: model:ir.model.fields,field_description:stock_location_empty.field_stock_location__stock_amount +#: model:ir.model.fields,field_description:stock_location_empty.field_stock_location__stock_quantity msgid "Stock Amount" msgstr "Quantité en stock" diff --git a/stock_location_empty/models/stock_location.py b/stock_location_empty/models/stock_location.py index c02b3ae7a..6ff7e0b18 100644 --- a/stock_location_empty/models/stock_location.py +++ b/stock_location_empty/models/stock_location.py @@ -1,45 +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 api, fields, models +from odoo import fields, models class StockLocation(models.Model): _inherit = "stock.location" - stock_amount = fields.Integer( + stock_amount = fields.Float( compute="_compute_location_amount", search="_search_location_amount" ) - @api.multi def _search_location_amount(self, operator, value): if operator not in ("=", "!=", "<", "<=", ">", ">="): return [] - # pylint: disable=sql-injection - self.env.cr.execute( + 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) %s %%s;""" - % operator, - (value,), + HAVING coalesce(sum(quantity), 0) {operator} %(value)s;""".format( + operator=operator + ) ) - ids = [row[0] for row in self.env.cr.fetchall()] + + self.env.cr.execute(query, {"value": value}) + res = self.env.cr.fetchall() + ids = [row[0] for row in res] return [("id", "in", ids)] - @api.multi def _compute_location_amount(self): - self.env.cr.execute( + query = sql.SQL( """ SELECT location_id, sum(quantity) FROM stock_quant - WHERE location_id IN %s + WHERE location_id IN %(values)s GROUP BY location_id; - """, - (tuple(self.ids),), + """ ) + 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 index 37ed81474..b7634598f 100644 --- a/stock_location_empty/readme/CONTRIBUTORS.rst +++ b/stock_location_empty/readme/CONTRIBUTORS.rst @@ -1,2 +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/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 index 9c137ebff..9d7449a8f 100644 --- a/stock_location_empty/views/stock.xml +++ b/stock_location_empty/views/stock.xml @@ -76,7 +76,6 @@ Locations stock.location ir.actions.act_window - form {'search_default_in_location':1, 'search_default_stock_amount': 1} - + + Empty stock + + + +