Define Function field with column_ as searchable and sortable

This commit is contained in:
Cédric Krier
2026-02-25 09:08:24 +01:00
parent e4c5d7c575
commit c0396ab1db
2 changed files with 8 additions and 2 deletions
+6 -2
View File
@@ -240,10 +240,14 @@ class Function(Field):
def searchable(self, model):
return super().searchable(model) and (
bool(self.searcher) or hasattr(model, f'domain_{self.name}'))
bool(self.searcher)
or hasattr(model, f'domain_{self.name}')
or hasattr(model, f'column_{self.name}'))
def sortable(self, model):
return super().sortable(model) and hasattr(model, f'order_{self.name}')
return super().sortable(model) and (
hasattr(model, f'order_{self.name}')
or hasattr(model, f'column_{self.name}'))
def getter_multiple(self, method):
"Returns True if getter function accepts multiple fields"
@@ -158,6 +158,7 @@ class FieldFunctionTestCase(TestCase):
result = Model.search([('value_inc', '=', 43)])
self.assertEqual(result, [record])
self.assertTrue(Model.value_inc.searchable(Model))
@with_transaction()
def test_no_getter_order(self):
@@ -174,6 +175,7 @@ class FieldFunctionTestCase(TestCase):
self.assertEqual(asc, sorted(asc))
self.assertEqual(desc, sorted(asc, reverse=True))
self.assertTrue(Model.value_inc.sortable(Model))
@with_transaction()
def test_no_getter_relation(self):