From b1766c6d9bb6cd5cf4980ef0db9ebb2326ca029a Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 24 Nov 2023 00:45:05 +0100 Subject: [PATCH] [MIG] stock_report_quantity_by_location: Migration to 16.0 --- stock_report_quantity_by_location/README.rst | 15 ++-- .../__manifest__.py | 2 +- .../readme/CONTRIBUTORS.rst | 3 + .../static/description/index.html | 10 ++- .../test_stock_report_quantity_by_location.py | 2 +- .../wizards/__init__.py | 1 + .../stock_report_quantity_by_location.py | 82 +------------------ ...ock_report_quantity_by_location_prepare.py | 81 ++++++++++++++++++ ...tock_report_quantity_by_location_views.xml | 2 +- 9 files changed, 104 insertions(+), 94 deletions(-) create mode 100644 stock_report_quantity_by_location/wizards/stock_report_quantity_by_location_prepare.py 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 `_. 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. @@ -64,6 +64,9 @@ Contributors * Ecosoft (http://ecosoft.co.th) * Kranokporn Thongdoung + * FactorLibre (http://factorlibre.com) + * Hugo Córdoba + Maintainers ~~~~~~~~~~~ @@ -77,6 +80,6 @@ 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/__manifest__.py b/stock_report_quantity_by_location/__manifest__.py index 28f14f0..a395a4b 100644 --- a/stock_report_quantity_by_location/__manifest__.py +++ b/stock_report_quantity_by_location/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Stock Report Quantity By Location", "summary": "Stock Report Quantity By Location", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "author": "ForgeFlow, Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-reporting", "category": "Warehouse Management", diff --git a/stock_report_quantity_by_location/readme/CONTRIBUTORS.rst b/stock_report_quantity_by_location/readme/CONTRIBUTORS.rst index 5b72712..8d3e0dd 100644 --- a/stock_report_quantity_by_location/readme/CONTRIBUTORS.rst +++ b/stock_report_quantity_by_location/readme/CONTRIBUTORS.rst @@ -4,3 +4,6 @@ * Ecosoft (http://ecosoft.co.th) * Kranokporn Thongdoung + + * FactorLibre (http://factorlibre.com) + * Hugo Córdoba diff --git a/stock_report_quantity_by_location/static/description/index.html b/stock_report_quantity_by_location/static/description/index.html index 469fffd..69d23bc 100644 --- a/stock_report_quantity_by_location/static/description/index.html +++ b/stock_report_quantity_by_location/static/description/index.html @@ -367,9 +367,9 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:57c3689eae5fca6394308789a0d776c7eae48bd21fc51808841922b00e25ebfb +!! source digest: sha256:a267bfa205872d07d7a0a055440a79c70bca49f300b53a8ad40f0114d80fab09 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/stock-logistics-reporting Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/stock-logistics-reporting Translate me on Weblate Try me on Runboat

This module adds an additional reporting on Inventory side where warehouse location quantities are shown by all stockable products.

Table of contents

@@ -389,7 +389,7 @@ location quantities are shown by all stockable products.

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.

@@ -411,6 +411,8 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
@@ -421,7 +423,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

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). - + Stock Report Quantity By Location Search stock.report.quantity.by.location