details: https://code.tryton.org/tryton/commit/350b077d44c0
branch: default
user: Cédric Krier <[email protected]>
date: Thu Jan 29 15:24:10 2026 +0100
description:
Allow customizing SQL expression of field
diffstat:
trytond/CHANGELOG | 1 +
trytond/doc/ref/fields.rst | 11 +++++++++++
trytond/trytond/model/fields/field.py | 11 +++++++++++
trytond/trytond/tests/test_tryton.py | 2 +-
4 files changed, 24 insertions(+), 1 deletions(-)
diffs (69 lines):
diff -r 26aca1c56728 -r 350b077d44c0 trytond/CHANGELOG
--- a/trytond/CHANGELOG Thu Jan 29 12:42:56 2026 +0100
+++ b/trytond/CHANGELOG Thu Jan 29 15:24:10 2026 +0100
@@ -1,3 +1,4 @@
+* Add support for column_<field name> method
* Use tables and Model as arguments for sql_column of the Field
* Add support for basic authentication for user application
* Support the conversion of MJML reports to HTML
diff -r 26aca1c56728 -r 350b077d44c0 trytond/doc/ref/fields.rst
--- a/trytond/doc/ref/fields.rst Thu Jan 29 12:42:56 2026 +0100
+++ b/trytond/doc/ref/fields.rst Thu Jan 29 15:24:10 2026 +0100
@@ -222,6 +222,17 @@
See :ref:`default value <topics-fields_default_value>`
+Reading
+=======
+
+A class method could be defined for each field which must return a SQL
+expression as column instead of the default one.
+The method signature is::
+
+ column_<field name>(tables)
+
+Where ``tables`` is a nested dictionary, see :ref:`tables <ref-tables>`.
+
Searching
=========
diff -r 26aca1c56728 -r 350b077d44c0 trytond/trytond/model/fields/field.py
--- a/trytond/trytond/model/fields/field.py Thu Jan 29 12:42:56 2026 +0100
+++ b/trytond/trytond/model/fields/field.py Thu Jan 29 15:24:10 2026 +0100
@@ -206,6 +206,16 @@
return decorator
+def column_method(func):
+ @wraps(func)
+ def wrapper(self, tables, Model):
+ method = getattr(Model, f'column_{self.name}', None)
+ if method:
+ return method(tables)
+ return func(self, tables, Model)
+ return wrapper
+
+
def domain_method(func):
@wraps(func)
def wrapper(self, domain, tables, Model):
@@ -421,6 +431,7 @@
def sql_cast(self, expression):
return Cast(expression, self.sql_type().base)
+ @column_method
def sql_column(self, tables, Model):
table, _ = tables[None]
return Column(table, self.name)
diff -r 26aca1c56728 -r 350b077d44c0 trytond/trytond/tests/test_tryton.py
--- a/trytond/trytond/tests/test_tryton.py Thu Jan 29 12:42:56 2026 +0100
+++ b/trytond/trytond/tests/test_tryton.py Thu Jan 29 15:24:10 2026 +0100
@@ -655,7 +655,7 @@
def test_methods(mname, model, attr):
for prefixes in [['default_'],
['on_change_', 'on_change_with_'],
- ['order_'], ['domain_'], ['autocomplete_']]:
+ ['column_'], ['order_'], ['domain_'], ['autocomplete_']]:
if attr in {'on_change_with', 'on_change_notify'}:
continue
# TODO those method should be renamed