From eb36f427292e7f0777d3da0093be51b9f56ca14c Mon Sep 17 00:00:00 2001 From: Nicolas Seinlet Date: Tue, 12 Dec 2017 10:16:11 +0100 Subject: [PATCH] [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 --- addons/stock/models/stock_location.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/addons/stock/models/stock_location.py b/addons/stock/models/stock_location.py index eb88b140a1b..aed705023fd 100644 --- a/addons/stock/models/stock_location.py +++ b/addons/stock/models/stock_location.py @@ -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):