From e3436549d14b3450f928c6c0b1445bf6a6777941 Mon Sep 17 00:00:00 2001 From: kranokporn Date: Tue, 14 Jul 2020 17:52:49 +0700 Subject: [PATCH] [IMP] stock_report_quantity_by_location: black, isort, prettier --- .../__manifest__.py | 14 +-- .../readme/CONTRIBUTORS.rst | 2 +- .../readme/DESCRIPTION.rst | 2 +- .../test_stock_report_quantity_by_location.py | 17 ++-- .../stock_report_quantity_by_location.py | 92 +++++++++---------- ...tock_report_quantity_by_location_views.xml | 1 - 6 files changed, 58 insertions(+), 70 deletions(-) diff --git a/stock_report_quantity_by_location/__manifest__.py b/stock_report_quantity_by_location/__manifest__.py index e0bf6e9..2b8595c 100644 --- a/stock_report_quantity_by_location/__manifest__.py +++ b/stock_report_quantity_by_location/__manifest__.py @@ -3,18 +3,12 @@ { "name": "Stock Report Quantity By Location", "summary": "Stock Report Quantity By Location", - "version": "12.0.1.0.0", - "author": "Eficent, " - "Odoo Community Association (OCA)", + "version": "13.0.1.0.0", + "author": "Eficent, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-reporting", "category": "Warehouse Management", "license": "AGPL-3", - "depends": [ - "product", - "stock", - ], - "data": [ - 'wizards/stock_report_quantity_by_location_views.xml', - ], + "depends": ["product", "stock"], + "data": ["wizards/stock_report_quantity_by_location_views.xml"], "installable": True, } diff --git a/stock_report_quantity_by_location/readme/CONTRIBUTORS.rst b/stock_report_quantity_by_location/readme/CONTRIBUTORS.rst index 01f149a..a78f031 100644 --- a/stock_report_quantity_by_location/readme/CONTRIBUTORS.rst +++ b/stock_report_quantity_by_location/readme/CONTRIBUTORS.rst @@ -1,3 +1,3 @@ * Eficent Business and IT Consulting Services, S.L. (https://www.eficent.com) * Jordi Ballester Alomar - * Hector Villarreal \ No newline at end of file + * Hector Villarreal diff --git a/stock_report_quantity_by_location/readme/DESCRIPTION.rst b/stock_report_quantity_by_location/readme/DESCRIPTION.rst index a3ccc04..e9de6ac 100644 --- a/stock_report_quantity_by_location/readme/DESCRIPTION.rst +++ b/stock_report_quantity_by_location/readme/DESCRIPTION.rst @@ -1,2 +1,2 @@ This module adds an additional reporting on Inventory side where warehouse -location quantities are shown by all stockable products. \ No newline at end of file +location quantities are shown by all stockable products. 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 aaf17da..69ae799 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 @@ -5,18 +5,17 @@ from odoo.tests.common import SavepointCase class TestStockReportQuantityByLocation(SavepointCase): - @classmethod def setUpClass(cls): super(TestStockReportQuantityByLocation, cls).setUpClass() - cls.stock_loc = cls.env.ref('stock.stock_location_stock') + cls.stock_loc = cls.env.ref("stock.stock_location_stock") def test_wizard(self): - self.wizard = self.env[ - 'stock.report.quantity.by.location.prepare'].create( - {'location_ids': [(4, self.stock_loc.id)]}) + self.wizard = self.env["stock.report.quantity.by.location.prepare"].create( + {"location_ids": [(4, self.stock_loc.id)]} + ) wiz_creator = self.wizard.open() - wizard_lines = self.env['stock.report.quantity.by.location'].search( - wiz_creator['domain']) - self.assertFalse( - any(wiz.location_id != self.stock_loc for wiz in wizard_lines)) + wizard_lines = self.env["stock.report.quantity.by.location"].search( + wiz_creator["domain"] + ) + self.assertFalse(any(wiz.location_id != self.stock_loc for wiz in wizard_lines)) 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 5d5a180..5b5dcf8 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,27 +1,30 @@ # Copyright 2019 Eficent Business and IT Consulting Services, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import fields, models, _ +from odoo import _, fields, models class StockReportByLocationPrepare(models.TransientModel): - _name = 'stock.report.quantity.by.location.prepare' - _description = 'Stock Report Quantity By Location Prepare' + _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) + location_ids = fields.Many2many( + comodel_name="stock.location", string="Locations", required=True + ) 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)], + "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 @@ -29,49 +32,42 @@ class StockReportByLocationPrepare(models.TransientModel): 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', 'product_id'], - ['product_id']) - mapping = dict( - [(quant_group['product_id'][0], - quant_group['quantity']) - for quant_group in quant_groups] + quant_groups = self.env["stock.quant"].read_group( + [("location_id", "child_of", [loc.id])], + ["quantity", "product_id"], + ["product_id"], ) - products = self.env['product.product'].search( - [('type', '=', 'product')]) + mapping = { + quant_group["product_id"][0]: quant_group["quantity"] + for quant_group in quant_groups + } + products = self.env["product.product"].search([("type", "=", "product")]) for product in products: - r = self.env['stock.report.quantity.by.location'].create({ - 'product_id': product.id, - 'product_category_id': product.categ_id.id, - 'uom_id': product.uom_id.id, - 'quantity': mapping.get(product.id, 0.0), - 'location_id': loc.id, - 'wiz_id': self.id, - 'default_code': product.default_code, - }) + r = self.env["stock.report.quantity.by.location"].create( + { + "product_id": product.id, + "product_category_id": product.categ_id.id, + "uom_id": product.uom_id.id, + "quantity": mapping.get(product.id, 0.0), + "location_id": loc.id, + "wiz_id": self.id, + "default_code": product.default_code, + } + ) recs.append(r.id) return recs class StockReportQuantityByLocation(models.TransientModel): - _name = 'stock.report.quantity.by.location' - _description = 'Stock Report By Location' + _name = "stock.report.quantity.by.location" + _description = "Stock Report By Location" - wiz_id = fields.Many2one( - comodel_name='stock.report.quantity.by.location.prepare') - product_id = fields.Many2one( - comodel_name='product.product', - required=True, - ) + wiz_id = fields.Many2one(comodel_name="stock.report.quantity.by.location.prepare") + product_id = fields.Many2one(comodel_name="product.product", required=True) product_category_id = fields.Many2one( - comodel_name='product.category', - string='Product Category', - ) - location_id = fields.Many2one( - comodel_name='stock.location', - required=True, + comodel_name="product.category", string="Product Category" ) + location_id = fields.Many2one(comodel_name="stock.location", required=True) quantity = fields.Float() - uom_id = fields.Many2one(comodel_name='uom.uom', string='Product UoM',) - default_code = fields.Char('Internal Reference',) + uom_id = fields.Many2one(comodel_name="uom.uom", string="Product UoM") + default_code = fields.Char("Internal Reference") 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 84170db..4284275 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 @@ -77,4 +77,3 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -