mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
Run pre-commit
This commit is contained in:
@@ -5,19 +5,19 @@ from odoo import api, fields, models
|
|||||||
|
|
||||||
class StockLocation(models.Model):
|
class StockLocation(models.Model):
|
||||||
|
|
||||||
_inherit = 'stock.location'
|
_inherit = "stock.location"
|
||||||
|
|
||||||
children_ids = fields.Many2many(
|
children_ids = fields.Many2many(
|
||||||
'stock.location',
|
"stock.location",
|
||||||
'stock_location_children_ids',
|
"stock_location_children_ids",
|
||||||
'parent_id',
|
"parent_id",
|
||||||
'children_id',
|
"children_id",
|
||||||
compute='_compute_children_ids',
|
compute="_compute_children_ids",
|
||||||
store=True,
|
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):
|
def _compute_children_ids(self):
|
||||||
query = """SELECT sub.id, ARRAY_AGG(sl2.id) AS children
|
query = """SELECT sub.id, ARRAY_AGG(sl2.id) AS children
|
||||||
FROM stock_location sl2,
|
FROM stock_location sl2,
|
||||||
@@ -35,8 +35,8 @@ class StockLocation(models.Model):
|
|||||||
for loc in self:
|
for loc in self:
|
||||||
all_ids = []
|
all_ids = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
if row.get('id') == loc.id:
|
if row.get("id") == loc.id:
|
||||||
all_ids = row.get('children')
|
all_ids = row.get("children")
|
||||||
break
|
break
|
||||||
if all_ids:
|
if all_ids:
|
||||||
loc.children_ids = [(6, 0, all_ids)]
|
loc.children_ids = [(6, 0, all_ids)]
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ from odoo.tests import SavepointCase
|
|||||||
|
|
||||||
|
|
||||||
class TestStockLocationChildren(SavepointCase):
|
class TestStockLocationChildren(SavepointCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
@@ -14,64 +13,49 @@ class TestStockLocationChildren(SavepointCase):
|
|||||||
cls.stock_location = ref("stock.stock_location_stock")
|
cls.stock_location = ref("stock.stock_location_stock")
|
||||||
cls.stock_shelf_1 = ref("stock.stock_location_components")
|
cls.stock_shelf_1 = ref("stock.stock_location_components")
|
||||||
cls.stock_shelf_2 = ref("stock.stock_location_14")
|
cls.stock_shelf_2 = ref("stock.stock_location_14")
|
||||||
cls.stock_shelf_2_refrigerator = ref(
|
cls.stock_shelf_2_refrigerator = ref("stock.location_refrigerator_small")
|
||||||
"stock.location_refrigerator_small"
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_location_children(self):
|
def test_location_children(self):
|
||||||
self.assertFalse(self.stock_shelf_2_refrigerator.child_ids)
|
self.assertFalse(self.stock_shelf_2_refrigerator.child_ids)
|
||||||
self.assertEqual(
|
self.assertEqual(self.stock_shelf_2.child_ids, self.stock_shelf_2_refrigerator)
|
||||||
self.stock_shelf_2.child_ids,
|
self.assertEqual(self.stock_shelf_2.child_ids, self.stock_shelf_2.children_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.child_ids)
|
||||||
self.assertFalse(self.stock_shelf_1.children_ids)
|
self.assertFalse(self.stock_shelf_1.children_ids)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.stock_location.child_ids,
|
self.stock_location.child_ids, self.stock_shelf_1 | self.stock_shelf_2
|
||||||
self.stock_shelf_1 | self.stock_shelf_2
|
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.stock_location.children_ids,
|
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):
|
def test_create_write_location(self):
|
||||||
refrigerator_drawer = self.env['stock.location'].create({
|
refrigerator_drawer = self.env["stock.location"].create(
|
||||||
'name': 'Refrigerator drawer',
|
{
|
||||||
'location_id': self.stock_shelf_2_refrigerator.id
|
"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.child_ids, refrigerator_drawer)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.stock_shelf_2_refrigerator.children_ids,
|
self.stock_shelf_2_refrigerator.children_ids, refrigerator_drawer
|
||||||
refrigerator_drawer
|
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.stock_shelf_2.children_ids,
|
self.stock_shelf_2.children_ids,
|
||||||
self.stock_shelf_2_refrigerator | refrigerator_drawer
|
self.stock_shelf_2_refrigerator | refrigerator_drawer,
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.stock_location.children_ids,
|
self.stock_location.children_ids,
|
||||||
self.stock_shelf_1 | self.stock_shelf_2 |
|
self.stock_shelf_1
|
||||||
self.stock_shelf_2_refrigerator | refrigerator_drawer
|
| self.stock_shelf_2
|
||||||
|
| self.stock_shelf_2_refrigerator
|
||||||
|
| refrigerator_drawer,
|
||||||
)
|
)
|
||||||
refrigerator_drawer.location_id = self.stock_input
|
refrigerator_drawer.location_id = self.stock_input
|
||||||
self.assertFalse(self.stock_shelf_2_refrigerator.child_ids)
|
self.assertFalse(self.stock_shelf_2_refrigerator.child_ids)
|
||||||
self.assertEqual(
|
self.assertEqual(self.stock_shelf_2.child_ids, self.stock_shelf_2_refrigerator)
|
||||||
self.stock_shelf_2.child_ids,
|
self.assertEqual(self.stock_shelf_2.child_ids, self.stock_shelf_2.children_ids)
|
||||||
self.stock_shelf_2_refrigerator
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
self.stock_shelf_2.child_ids,
|
|
||||||
self.stock_shelf_2.children_ids
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.stock_location.children_ids,
|
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,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user