Idea for a new kind of field

56 views
Skip to first unread message

Cédric Krier

unread,
Jun 28, 2014, 3:17:02 PM6/28/14
to tryton
Hi,

Sometimes, a Function field could be just written as SQL expression and
it is a pity to have to write a getter and searcher.
So the idea will be to have a field that will behaves like a Function
field but you will only have to define the SQL statement.

To have such feature, we will need to redesign the API of field.
For now, field could have a get, set and convert_domain methods.

The get method if defined is called to modify or compute the value.
API: `get(self, ids, Model, name, values=None)`

The set method if defined is called to set the value in create/write
instead of being a UPDATE column.
API: `set(self, Model, name, ids, value, *[ids, value, …])`

The convert_domain is always called when searching on the field.
API: `convert_domain(self, domain, tables, Model)`

The awkward is that the 'set' method presences is used on
`ModelSQL.read` to know if the column must be a column in `SELECT`.


My proposal is to re-use the existing `sql_column` (from changeset
156f1cfee9f2) instead of 'set' method for read.
Then we could change the API of get method: get(self, Model, name, ids)
We will no more need of values because such case could be handle with
sql_column.

So the new field could be:

class FunctionSQL(_Function): #common part with Function
def __init__(self, field, column, setter=None, loading='eager'):

def sql_column(self, table, Model):
return getattr(Model, self.column)(table)

# convert_domain should work out of the box
# no get

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Albert Cervera i Areny

unread,
Jul 1, 2014, 4:29:37 AM7/1/14
to tryto...@googlegroups.com
I think this would be a nice improvement.


--
Albert Cervera i Areny
Tel. 93 553 18 03
@albertnan
www.NaN-tic.com
Reply all
Reply to author
Forward
0 new messages