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.
This commit is contained in:
Guewen Baconnier
2019-09-13 11:35:31 +02:00
committed by Hai Lang
parent 9e6885b574
commit 8af14c98a2

View File

@@ -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')