Replace warehouse field on location by a property

The Function field is not efficient so its usage should be reserved to
server side code only.
This commit is contained in:
Cédric Krier
2026-05-07 18:36:18 +02:00
parent 8dfa6915b7
commit 8aaf6e1eb5
+3 -4
View File
@@ -82,8 +82,6 @@ class Location(DeactivableMixin, tree(), ModelSQL, ModelView):
"Flat Children",
help="Check to enforce a single level of children with no "
"grandchildren.")
warehouse = fields.Function(fields.Many2One('stock.location', 'Warehouse'),
'get_warehouse')
input_location = fields.Many2One(
"stock.location", "Input", states={
'invisible': Eval('type') != 'warehouse',
@@ -341,7 +339,8 @@ class Location(DeactivableMixin, tree(), ModelSQL, ModelView):
def default_type():
return 'storage'
def get_warehouse(self, name):
@property
def warehouse(self):
# Order by descending left to get the first one in the tree
with inactive_records():
locations = self.search([
@@ -349,7 +348,7 @@ class Location(DeactivableMixin, tree(), ModelSQL, ModelView):
('type', '=', 'warehouse'),
], order=[('left', 'DESC')])
if locations:
return locations[0].id
return locations[0]
@classmethod
def get_default_warehouse(cls):