mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
Improve performance
* Compute the 'zone' fields in the same method * Remove the dependency on 'zone_location_id', which seems to take a lot of time if not an infinite loop
This commit is contained in:
committed by
Tran Thanh Phuc
parent
21f2f946e7
commit
a29a178e88
@@ -17,7 +17,7 @@ class StockLocation(models.Model):
|
||||
zone_location_id = fields.Many2one(
|
||||
'stock.location',
|
||||
string='Location zone',
|
||||
compute='_compute_zone_location_id',
|
||||
compute='_compute_location_zone',
|
||||
store=True,
|
||||
index=True,
|
||||
)
|
||||
@@ -31,7 +31,7 @@ class StockLocation(models.Model):
|
||||
('other', 'Other'),
|
||||
],
|
||||
string='Location Kind',
|
||||
compute='_compute_location_kind',
|
||||
compute='_compute_location_zone',
|
||||
help='Group location according to their kinds:'
|
||||
'* Zone: locations that are flagged as being zones'
|
||||
'* Area: locations with children that are part of a zone'
|
||||
@@ -40,13 +40,27 @@ class StockLocation(models.Model):
|
||||
'* Other: any other location',
|
||||
)
|
||||
|
||||
@api.depends('is_zone', 'usage', 'location_id.usage', 'zone_location_id',
|
||||
'child_ids')
|
||||
def _compute_location_kind(self):
|
||||
@api.depends('is_zone', 'usage', 'location_id.usage', 'child_ids',
|
||||
'location_id.is_zone')
|
||||
def _compute_location_zone(self):
|
||||
for location in self:
|
||||
if location.is_zone:
|
||||
location.location_kind = 'zone'
|
||||
location.zone_location_id = location
|
||||
continue
|
||||
|
||||
# Get the zone from the parents
|
||||
parent = location.location_id
|
||||
while parent:
|
||||
if parent.is_zone:
|
||||
zone_location = parent
|
||||
break
|
||||
parent = parent.location_id
|
||||
else:
|
||||
zone_location = self.browse()
|
||||
|
||||
location.zone_location_id = zone_location
|
||||
|
||||
# Internal locations whose parent is view are main stocks
|
||||
if (
|
||||
location.usage == 'internal'
|
||||
@@ -57,7 +71,7 @@ class StockLocation(models.Model):
|
||||
# Internal locations having a zone and no children are bins
|
||||
if (
|
||||
location.usage == 'internal'
|
||||
and location.zone_location_id
|
||||
and zone_location
|
||||
and not location.child_ids
|
||||
):
|
||||
location.location_kind = 'bin'
|
||||
@@ -65,7 +79,7 @@ class StockLocation(models.Model):
|
||||
# Internal locations having a zone and children are areas
|
||||
if (
|
||||
location.usage == 'internal'
|
||||
and location.zone_location_id
|
||||
and zone_location
|
||||
and location.child_ids
|
||||
):
|
||||
location.location_kind = 'area'
|
||||
@@ -73,15 +87,6 @@ class StockLocation(models.Model):
|
||||
# All the rest are other locations
|
||||
location.location_kind = 'other'
|
||||
|
||||
@api.depends('is_zone', 'location_id.zone_location_id')
|
||||
def _compute_zone_location_id(self):
|
||||
for location in self:
|
||||
if location.is_zone:
|
||||
location.zone_location_id = location
|
||||
else:
|
||||
location.zone_location_id = \
|
||||
location.location_id.zone_location_id
|
||||
|
||||
@api.multi
|
||||
@api.returns('self', lambda value: value.id)
|
||||
def copy(self, default=None):
|
||||
|
||||
Reference in New Issue
Block a user