diff --git a/stock_report_quantity_by_location/README.rst b/stock_report_quantity_by_location/README.rst
index eb29780..22d2f6e 100644
--- a/stock_report_quantity_by_location/README.rst
+++ b/stock_report_quantity_by_location/README.rst
@@ -7,7 +7,7 @@ Stock Report Quantity By Location
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- !! source digest: sha256:57c3689eae5fca6394308789a0d776c7eae48bd21fc51808841922b00e25ebfb
+ !! source digest: sha256:a267bfa205872d07d7a0a055440a79c70bca49f300b53a8ad40f0114d80fab09
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -17,13 +17,13 @@ Stock Report Quantity By Location
: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--reporting-lightgray.png?logo=github
- :target: https://github.com/OCA/stock-logistics-reporting/tree/15.0/stock_report_quantity_by_location
+ :target: https://github.com/OCA/stock-logistics-reporting/tree/16.0/stock_report_quantity_by_location
:alt: OCA/stock-logistics-reporting
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
- :target: https://translation.odoo-community.org/projects/stock-logistics-reporting-15-0/stock-logistics-reporting-15-0-stock_report_quantity_by_location
+ :target: https://translation.odoo-community.org/projects/stock-logistics-reporting-16-0/stock-logistics-reporting-16-0-stock_report_quantity_by_location
: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-reporting&target_branch=15.0
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-reporting&target_branch=16.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -42,7 +42,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues This module adds an additional reporting on Inventory side where warehouse
location quantities are shown by all stockable products. Table of contents
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.
+feedback.Do not contact contributors directly about support or help with technical issues.
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-reporting project on GitHub.
+This module is part of the OCA/stock-logistics-reporting project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/stock_report_quantity_by_location/tests/test_stock_report_quantity_by_location.py b/stock_report_quantity_by_location/tests/test_stock_report_quantity_by_location.py index 34b8d9f..7dc19a9 100644 --- a/stock_report_quantity_by_location/tests/test_stock_report_quantity_by_location.py +++ b/stock_report_quantity_by_location/tests/test_stock_report_quantity_by_location.py @@ -7,7 +7,7 @@ from odoo.tests.common import TransactionCase class TestStockReportQuantityByLocation(TransactionCase): @classmethod def setUpClass(cls): - super(TestStockReportQuantityByLocation, cls).setUpClass() + super().setUpClass() cls.stock_loc = cls.env.ref("stock.stock_location_stock") def test_wizard(self): diff --git a/stock_report_quantity_by_location/wizards/__init__.py b/stock_report_quantity_by_location/wizards/__init__.py index 6e08ce7..c74f96d 100644 --- a/stock_report_quantity_by_location/wizards/__init__.py +++ b/stock_report_quantity_by_location/wizards/__init__.py @@ -1 +1,2 @@ +from . import stock_report_quantity_by_location_prepare from . import stock_report_quantity_by_location diff --git a/stock_report_quantity_by_location/wizards/stock_report_quantity_by_location.py b/stock_report_quantity_by_location/wizards/stock_report_quantity_by_location.py index 2c38a36..bb0dce0 100644 --- a/stock_report_quantity_by_location/wizards/stock_report_quantity_by_location.py +++ b/stock_report_quantity_by_location/wizards/stock_report_quantity_by_location.py @@ -1,86 +1,6 @@ # Copyright 2019-21 ForgeFlow, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import _, fields, models - - -class StockReportByLocationPrepare(models.TransientModel): - _name = "stock.report.quantity.by.location.prepare" - _description = "Stock Report Quantity By Location Prepare" - - location_ids = fields.Many2many( - comodel_name="stock.location", string="Locations", required=True - ) - availability = fields.Selection( - selection=[("on_hand", "On Hand"), ("unreserved", "Unreserved")], - default="on_hand", - help="Unreserved is the Stock On Hand minus the reservations", - ) - with_quantity = fields.Boolean( - string="Quantity > 0", - default=True, - help="Show only the products that have existing quantity on hand", - ) - - def open(self): - self.ensure_one() - self._compute_stock_report_by_location() - action = { - "type": "ir.actions.act_window", - "view_mode": "pivot,tree", - "name": _("Stock Report by Location"), - "context": { - "search_default_quantity_gt_zero": 1, - "group_by_no_leaf": 1, - "group_by": [], - }, - "res_model": "stock.report.quantity.by.location", - "domain": [("wiz_id", "=", self.id)], - } - return action - - def _compute_stock_report_by_location(self): - self.ensure_one() - recs = [] - for loc in self.location_ids: - quant_groups = self.env["stock.quant"].read_group( - [("location_id", "child_of", [loc.id])], - ["quantity", "reserved_quantity", "product_id"], - ["product_id"], - ) - mapping = {} - for quant_group in quant_groups: - qty_on_hand = quant_group["quantity"] - qty_reserved = quant_group["reserved_quantity"] - qty_unreserved = qty_on_hand - qty_reserved - qty_dict = { - "quantity_on_hand": qty_on_hand, - "quantity_reserved": qty_reserved, - "quantity_unreserved": qty_unreserved, - } - mapping.setdefault(quant_group["product_id"][0], qty_dict) - products = self.env["product.product"].search([("type", "=", "product")]) - vals_list = [] - for product in products: - qty_dict = mapping.get(product.id, {}) - qty_on_hand = qty_dict.get("quantity_on_hand", 0.0) - qty_reserved = qty_dict.get("quantity_reserved", 0.0) - qty_unreserved = qty_dict.get("quantity_unreserved", 0.0) - if (self.with_quantity and qty_on_hand) or not self.with_quantity: - vals_list.append( - { - "product_id": product.id, - "product_category_id": product.categ_id.id, - "uom_id": product.uom_id.id, - "quantity_on_hand": qty_on_hand, - "quantity_reserved": qty_reserved, - "quantity_unreserved": qty_unreserved, - "location_id": loc.id, - "wiz_id": self.id, - "default_code": product.default_code, - } - ) - recs = self.env["stock.report.quantity.by.location"].create(vals_list) - return recs.ids +from odoo import fields, models class StockReportQuantityByLocation(models.TransientModel): diff --git a/stock_report_quantity_by_location/wizards/stock_report_quantity_by_location_prepare.py b/stock_report_quantity_by_location/wizards/stock_report_quantity_by_location_prepare.py new file mode 100644 index 0000000..2a37056 --- /dev/null +++ b/stock_report_quantity_by_location/wizards/stock_report_quantity_by_location_prepare.py @@ -0,0 +1,81 @@ +# Copyright 2019-21 ForgeFlow, S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import _, fields, models + + +class StockReportByLocationPrepare(models.TransientModel): + _name = "stock.report.quantity.by.location.prepare" + _description = "Stock Report Quantity By Location Prepare" + + location_ids = fields.Many2many( + comodel_name="stock.location", string="Locations", required=True + ) + availability = fields.Selection( + selection=[("on_hand", "On Hand"), ("unreserved", "Unreserved")], + default="on_hand", + help="Unreserved is the Stock On Hand minus the reservations", + ) + with_quantity = fields.Boolean( + string="Quantity > 0", + default=True, + help="Show only the products that have existing quantity on hand", + ) + + def open(self): + self.ensure_one() + self._compute_stock_report_by_location() + action = { + "type": "ir.actions.act_window", + "view_mode": "pivot,tree", + "name": _("Stock Report by Location"), + "context": { + "search_default_quantity_gt_zero": 1, + "group_by_no_leaf": 1, + "group_by": [], + }, + "res_model": "stock.report.quantity.by.location", + "domain": [("wiz_id", "=", self.id)], + } + return action + + def _compute_stock_report_by_location(self): + self.ensure_one() + vals_list = [] + for loc in self.location_ids: + quant_groups = self.env["stock.quant"].read_group( + [("location_id", "child_of", [loc.id])], + ["quantity", "reserved_quantity", "product_id"], + ["product_id"], + ) + mapping = {} + for quant_group in quant_groups: + qty_on_hand = quant_group["quantity"] + qty_reserved = quant_group["reserved_quantity"] + qty_unreserved = qty_on_hand - qty_reserved + qty_dict = { + "quantity_on_hand": qty_on_hand, + "quantity_reserved": qty_reserved, + "quantity_unreserved": qty_unreserved, + } + mapping.setdefault(quant_group["product_id"][0], qty_dict) + products = self.env["product.product"].search([("type", "=", "product")]) + for product in products: + qty_dict = mapping.get(product.id, {}) + qty_on_hand = qty_dict.get("quantity_on_hand", 0.0) + qty_reserved = qty_dict.get("quantity_reserved", 0.0) + qty_unreserved = qty_dict.get("quantity_unreserved", 0.0) + if not self.with_quantity or qty_on_hand: + vals_list.append( + { + "product_id": product.id, + "product_category_id": product.categ_id.id, + "uom_id": product.uom_id.id, + "quantity_on_hand": qty_on_hand, + "quantity_reserved": qty_reserved, + "quantity_unreserved": qty_unreserved, + "location_id": loc.id, + "wiz_id": self.id, + "default_code": product.default_code, + } + ) + self.env["stock.report.quantity.by.location"].create(vals_list) diff --git a/stock_report_quantity_by_location/wizards/stock_report_quantity_by_location_views.xml b/stock_report_quantity_by_location/wizards/stock_report_quantity_by_location_views.xml index aeddbf5..f98b8a6 100644 --- a/stock_report_quantity_by_location/wizards/stock_report_quantity_by_location_views.xml +++ b/stock_report_quantity_by_location/wizards/stock_report_quantity_by_location_views.xml @@ -79,7 +79,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -