From 03042794245949a9d8ef4ddf19fbac7f7e0714f1 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Tue, 3 Mar 2020 14:53:47 +0100 Subject: [PATCH] Run pre-commit --- .../models/stock_location.py | 20 +++---- .../tests/test_stock_location_children.py | 56 +++++++------------ 2 files changed, 30 insertions(+), 46 deletions(-) diff --git a/stock_location_children/models/stock_location.py b/stock_location_children/models/stock_location.py index 2ffd89050..6f2b9e60b 100644 --- a/stock_location_children/models/stock_location.py +++ b/stock_location_children/models/stock_location.py @@ -5,19 +5,19 @@ from odoo import api, fields, models class StockLocation(models.Model): - _inherit = 'stock.location' + _inherit = "stock.location" children_ids = fields.Many2many( - 'stock.location', - 'stock_location_children_ids', - 'parent_id', - 'children_id', - compute='_compute_children_ids', + "stock.location", + "stock_location_children_ids", + "parent_id", + "children_id", + compute="_compute_children_ids", store=True, - help='All the children (multi-level) stock location of this location', + help="All the children (multi-level) stock location of this location", ) - @api.depends('child_ids', 'child_ids.children_ids') + @api.depends("child_ids", "child_ids.children_ids") def _compute_children_ids(self): query = """SELECT sub.id, ARRAY_AGG(sl2.id) AS children FROM stock_location sl2, @@ -35,8 +35,8 @@ class StockLocation(models.Model): for loc in self: all_ids = [] for row in rows: - if row.get('id') == loc.id: - all_ids = row.get('children') + if row.get("id") == loc.id: + all_ids = row.get("children") break if all_ids: loc.children_ids = [(6, 0, all_ids)] diff --git a/stock_location_children/tests/test_stock_location_children.py b/stock_location_children/tests/test_stock_location_children.py index 12d8af11c..f28bbe0cf 100644 --- a/stock_location_children/tests/test_stock_location_children.py +++ b/stock_location_children/tests/test_stock_location_children.py @@ -4,7 +4,6 @@ from odoo.tests import SavepointCase class TestStockLocationChildren(SavepointCase): - @classmethod def setUpClass(cls): super().setUpClass() @@ -14,64 +13,49 @@ class TestStockLocationChildren(SavepointCase): cls.stock_location = ref("stock.stock_location_stock") cls.stock_shelf_1 = ref("stock.stock_location_components") cls.stock_shelf_2 = ref("stock.stock_location_14") - cls.stock_shelf_2_refrigerator = ref( - "stock.location_refrigerator_small" - ) + cls.stock_shelf_2_refrigerator = ref("stock.location_refrigerator_small") def test_location_children(self): self.assertFalse(self.stock_shelf_2_refrigerator.child_ids) - self.assertEqual( - self.stock_shelf_2.child_ids, - self.stock_shelf_2_refrigerator - ) - self.assertEqual( - self.stock_shelf_2.child_ids, - self.stock_shelf_2.children_ids - ) + self.assertEqual(self.stock_shelf_2.child_ids, self.stock_shelf_2_refrigerator) + self.assertEqual(self.stock_shelf_2.child_ids, self.stock_shelf_2.children_ids) self.assertFalse(self.stock_shelf_1.child_ids) self.assertFalse(self.stock_shelf_1.children_ids) self.assertEqual( - self.stock_location.child_ids, - self.stock_shelf_1 | self.stock_shelf_2 + self.stock_location.child_ids, self.stock_shelf_1 | self.stock_shelf_2 ) self.assertEqual( self.stock_location.children_ids, - self.stock_shelf_1 | self.stock_shelf_2 | self.stock_shelf_2_refrigerator + self.stock_shelf_1 | self.stock_shelf_2 | self.stock_shelf_2_refrigerator, ) def test_create_write_location(self): - refrigerator_drawer = self.env['stock.location'].create({ - 'name': 'Refrigerator drawer', - 'location_id': self.stock_shelf_2_refrigerator.id - }) - self.assertEqual( - self.stock_shelf_2_refrigerator.child_ids, - refrigerator_drawer + refrigerator_drawer = self.env["stock.location"].create( + { + "name": "Refrigerator drawer", + "location_id": self.stock_shelf_2_refrigerator.id, + } ) + self.assertEqual(self.stock_shelf_2_refrigerator.child_ids, refrigerator_drawer) self.assertEqual( - self.stock_shelf_2_refrigerator.children_ids, - refrigerator_drawer + self.stock_shelf_2_refrigerator.children_ids, refrigerator_drawer ) self.assertEqual( self.stock_shelf_2.children_ids, - self.stock_shelf_2_refrigerator | refrigerator_drawer + self.stock_shelf_2_refrigerator | refrigerator_drawer, ) self.assertEqual( self.stock_location.children_ids, - self.stock_shelf_1 | self.stock_shelf_2 | - self.stock_shelf_2_refrigerator | refrigerator_drawer + self.stock_shelf_1 + | self.stock_shelf_2 + | self.stock_shelf_2_refrigerator + | refrigerator_drawer, ) refrigerator_drawer.location_id = self.stock_input self.assertFalse(self.stock_shelf_2_refrigerator.child_ids) - self.assertEqual( - self.stock_shelf_2.child_ids, - self.stock_shelf_2_refrigerator - ) - self.assertEqual( - self.stock_shelf_2.child_ids, - self.stock_shelf_2.children_ids - ) + self.assertEqual(self.stock_shelf_2.child_ids, self.stock_shelf_2_refrigerator) + self.assertEqual(self.stock_shelf_2.child_ids, self.stock_shelf_2.children_ids) self.assertEqual( self.stock_location.children_ids, - self.stock_shelf_1 | self.stock_shelf_2 | self.stock_shelf_2_refrigerator + self.stock_shelf_1 | self.stock_shelf_2 | self.stock_shelf_2_refrigerator, )