[FIX] stock: complete_name of stock location

Have the following location structure: Loc A -> Loc B -> Loc C
The `complete_name` fields are:
- Loc A
- Loc A/Loc B
- Loc A/Loc B/Loc C

When changing Loc A to Loc D, the `complete_name` are:
- Loc D
- Loc D/Loc B
- Loc A/Loc B/Loc C

Compute `complete_name` of stock location using `complete_name` of
parent instead of parsing the full bunch of ancestors.  This improves
the computation speed, and moreover solves the recursivity problem.

Closes #21585
This commit is contained in:
Nicolas Seinlet
2017-12-12 13:15:47 +01:00
committed by Nicolas Martinelli
parent 2720eb84ee
commit eb36f42729
+5 -7
View File
@@ -69,15 +69,13 @@ class Location(models.Model):
_sql_constraints = [('barcode_company_uniq', 'unique (barcode,company_id)', 'The barcode for a location must be unique per company !')]
@api.one
@api.depends('name', 'location_id.name')
@api.depends('name', 'location_id.complete_name')
def _compute_complete_name(self):
""" Forms complete name of location from parent location to child location. """
name = self.name
current = self
while current.location_id:
current = current.location_id
name = '%s/%s' % (current.name, name)
self.complete_name = name
if self.location_id.complete_name:
self.complete_name = '%s/%s' % (self.location_id.complete_name, self.name)
else:
self.complete_name = self.name
@api.multi
def name_get(self):