From 7f8102ad03ec4d27d2995f33bd63a13b41aff646 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Fri, 13 Sep 2019 11:35:31 +0200 Subject: [PATCH] Change the area field as a related field It is not stored because we only need it for the generation of the name. It slows creation of locations for no value. If we need to search on it, we can use a search method. --- .../models/stock_location.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/stock_location_bin_name/models/stock_location.py b/stock_location_bin_name/models/stock_location.py index d746b765c..3fa503d79 100644 --- a/stock_location_bin_name/models/stock_location.py +++ b/stock_location_bin_name/models/stock_location.py @@ -17,19 +17,14 @@ class StockLocation(models.Model): ".{level:0>2}'") area = fields.Char( - 'Area', - compute='_compute_area', - store=True, + string='Area', + # Field used for _onchange_attribute_compute_name, so we + # have the name in the record's cache. Does not need to be + # stored as we already have 'area_location_id' + related='area_location_id.name', + readonly=True, ) - @api.depends('name', 'location_kind', 'location_id.area') - def _compute_area(self): - for location in self: - if location.location_kind == 'area': - location.area = location.name - else: - location.area = location.location_id.area - @api.multi @api.onchange('corridor', 'row', 'rack', 'level', 'posx', 'posy', 'posz')