RPC method to know if a field is a Function or how to fill the field when creating a new record

43 views
Skip to first unread message

Javier Uribe

unread,
Aug 7, 2018, 3:55:06 AM8/7/18
to tryton
Hello, I'm developing a Framework to develop mobile tryton apps so I have to comunicate the client mobile with the server. I used the rpc method fields_get and default to fill the field's definitions but I'm struggling to understand how Tryton fills the fields.function, because the fields_get doesn't give you the info about it neither it is a fields.function or its function to call, so this field remains empty if I don't fill it manually.

When it comes to read a record it is easy because the read rpc method gives you the value, the problem comes when I have to create a new record and I have to fill it with all the default_values but I can't fill the function fields with its values.

Thanks.

Cédric Krier

unread,
Aug 7, 2018, 4:15:05 AM8/7/18
to tryton
On 2018-08-07 00:50, Javier Uribe wrote:
> Hello, I'm developing a Framework to develop mobile tryton apps so I have to comunicate the client mobile with the server. I used the rpc method fields_get and default to fill the field's definitions but I'm struggling to understand how Tryton fills the fields.function, because the fields_get doesn't give you the info about it neither it is a fields.function or its function to call, so this field remains empty if I don't fill it manually.

This is done on purpose. Function fields is a server details. They
must behave like the field they impersonate. So you must not know the
getter, setter or searcher because you can not call them remotely. You
must just use the read/create/write API as for any other fields.

> When it comes to read a record it is easy because the read rpc method gives you the value, the problem comes when I have to create a new record and I have to fill it with all the default_values but I can't fill the function fields with its values.

You should but be careful that some function fields have no setter so
they are described as readonly. You should never send value for readonly
fields. We will one day enforce this https://bugs.tryton.org/issue4207

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

Javier Uribe

unread,
Aug 7, 2018, 4:40:05 AM8/7/18
to tryton
So, lets say for instance that we have a field moves which is a Fields.function which has a method get_moves(). And I have just created a record that has this field, the fields_get tells me that it is a readonly. How should I fill the field moves with its value?

Cédric Krier

unread,
Aug 7, 2018, 5:00:06 AM8/7/18
to tryton
On 2018-08-07 01:26, Javier Uribe wrote:
> So, lets say for instance that we have a field moves which is a Fields.function which has a method get_moves(). And I have just created a record that has this field, the fields_get tells me that it is a readonly. How should I fill the field moves with its value?

Like any other field with the value read.

Javier Uribe

unread,
Aug 7, 2018, 5:40:06 AM8/7/18
to tryton
So, can I read a field of a record that doesn't exist yet?, if that so, that's my problem I haven't seen how to do that.

Cédric Krier

unread,
Aug 7, 2018, 5:55:06 AM8/7/18
to tryton
On 2018-08-07 02:02, Javier Uribe wrote:
> El martes, 7 de agosto de 2018, 11:00:06 (UTC+2), Cédric Krier escribió:
> > On 2018-08-07 01:26, Javier Uribe wrote:
> > > So, lets say for instance that we have a field moves which is a Fields.function which has a method get_moves(). And I have just created a record that has this field, the fields_get tells me that it is a readonly. How should I fill the field moves with its value?
> >
> > Like any other field with the value read.
>
> So, can I read a field of a record that doesn't exist yet?, if that so, that's my problem I haven't seen how to do that.

Of course, you can not read a record that does not exist.
I was answering about the creation like you said in your previous
message.

But the default value of a readonly field is just like the default value
of any field. But you must not send the value of readonly field to the
server for creation.

Javier Uribe

unread,
Aug 7, 2018, 6:20:05 AM8/7/18
to tryton
First of all, thanks a lot for your time but I still don't get how to do what I want. I want to read a field function of a record that doesn't exist because I'm creating, so basically when i'm creating a record and it is not saved on the server I only have the default values, but the function fields I understand that the must be filled as well. So what I want is to populate the model with the default values and the function fields. The default_values can be read easily using the RPC method default_get, however the function fields cannot be read from a record that does not exist.

Thank you again.

Cédric Krier

unread,
Aug 7, 2018, 6:40:06 AM8/7/18
to tryton
On 2018-08-07 03:12, Javier Uribe wrote:
> El martes, 7 de agosto de 2018, 11:55:06 (UTC+2), Cédric Krier escribió:
> > On 2018-08-07 02:02, Javier Uribe wrote:
> > > El martes, 7 de agosto de 2018, 11:00:06 (UTC+2), Cédric Krier escribió:
> > > > On 2018-08-07 01:26, Javier Uribe wrote:
> > > > > So, lets say for instance that we have a field moves which is a Fields.function which has a method get_moves(). And I have just created a record that has this field, the fields_get tells me that it is a readonly. How should I fill the field moves with its value?
> > > >
> > > > Like any other field with the value read.
> > >
> > > So, can I read a field of a record that doesn't exist yet?, if that so, that's my problem I haven't seen how to do that.
> >
> > Of course, you can not read a record that does not exist.
> > I was answering about the creation like you said in your previous
> > message.
> >
> > But the default value of a readonly field is just like the default value
> > of any field. But you must not send the value of readonly field to the
> > server for creation.
>
> First of all, thanks a lot for your time but I still don't get how to do what I want. I want to read a field function of a record that doesn't exist because I'm creating, so basically when i'm creating a record and it is not saved on the server I only have the default values, but the function fields I understand that the must be filled as well. So what I want is to populate the model with the default values and the function fields. The default_values can be read easily using the RPC method default_get, however the function fields cannot be read from a record that does not exist.

As I already said. There is nothing special about Function field on the
client side because client side does not know anything about Function
field and should never know anything about it.
So default value for function field are just like any default value of
any kind of field.

Now maybe, you would like to have the field (function or not) been
updated when the user fill the form. This is managed by the on_change
methods:
https://tryton-readthedocs.readthedocs.io/projects/server/en/latest/topics/models/fields_on_change.html
And again, client does not care about Function field or not also for the
on_change feature.



PS: Could you trim your quotes when answering, especially signature,
thanks.

Javier Uribe

unread,
Aug 7, 2018, 7:02:03 AM8/7/18
to tryton
Ah ok, I think I understand now. So if the field function does not have a on_change as a getter, for example, a field moves which has as a getter get_moves(). This methos will not be trigger when creating a record, will it?
So I only have to care to trigger on_change and on_change with causing that the fields function which has this on_change as getter will be filled.

My only doubt then is with these cases in which the field does not have an on_change method as a getter, and during the process of creating a record I want to use this field. Because if i'm not wrong, on Tryton if i'm creating a record and I print moves (using the same example), this will trigger get_moves. How does Tryton client get this value?

Cédric Krier

unread,
Aug 7, 2018, 7:40:05 AM8/7/18
to tryton
On 2018-08-07 03:57, Javier Uribe wrote:
> Ah ok, I think I understand now. So if the field function does not have a on_change as a getter, for example, a field moves which has as a getter get_moves(). This methos will not be trigger when creating a record, will it?

No, the getter are only called when reading records.

> So I only have to care to trigger on_change and on_change with causing that the fields function which has this on_change as getter will be filled.
>
> My only doubt then is with these cases in which the field does not have an on_change method as a getter, and during the process of creating a record I want to use this field. Because if i'm not wrong, on Tryton if i'm creating a record and I print moves (using the same example), this will trigger get_moves. How does Tryton client get this value?

The print action will save the record before being launched.

Javier Uribe

unread,
Aug 7, 2018, 9:21:31 AM8/7/18
to tryton
El martes, 7 de agosto de 2018, 13:40:05 (UTC+2), Cédric Krier escribió:
> On 2018-08-07 03:57, Javier Uribe wrote:
> > Ah ok, I think I understand now. So if the field function does not have a on_change as a getter, for example, a field moves which has as a getter get_moves(). This methos will not be trigger when creating a record, will it?
>
> No, the getter are only called when reading records.
>
> > So I only have to care to trigger on_change and on_change with causing that the fields function which has this on_change as getter will be filled.
> >
> > My only doubt then is with these cases in which the field does not have an on_change method as a getter, and during the process of creating a record I want to use this field. Because if i'm not wrong, on Tryton if i'm creating a record and I print moves (using the same example), this will trigger get_moves. How does Tryton client get this value?
>
> The print action will save the record before being launched.
>
> --
I see, therefore, I only have to call all the on_change and on_change_with during the creation of a record, because these will call all the field functions needed. The other fields.function which does not have on_change are not to be invoked until they are not in a read record.

The only thing that I think it wouldn't work is the domain/states because what if there is a domain/state which mentions an Eval(fieldFUnction), so I have to have it on my context but I can't because I can't read a field.function (which does not have an on change getter). So the states makes my field invisible for example when creating a record. How do I put in my context these fields?

Cédric Krier

unread,
Aug 7, 2018, 10:05:06 AM8/7/18
to tryton
On 2018-08-07 06:21, Javier Uribe wrote:
> El martes, 7 de agosto de 2018, 13:40:05 (UTC+2), Cédric Krier escribió:
> > On 2018-08-07 03:57, Javier Uribe wrote:
> > > Ah ok, I think I understand now. So if the field function does not have a on_change as a getter, for example, a field moves which has as a getter get_moves(). This methos will not be trigger when creating a record, will it?
> >
> > No, the getter are only called when reading records.
> >
> > > So I only have to care to trigger on_change and on_change with causing that the fields function which has this on_change as getter will be filled.
> > >
> > > My only doubt then is with these cases in which the field does not have an on_change method as a getter, and during the process of creating a record I want to use this field. Because if i'm not wrong, on Tryton if i'm creating a record and I print moves (using the same example), this will trigger get_moves. How does Tryton client get this value?
> >
> > The print action will save the record before being launched.
> >
> I see, therefore, I only have to call all the on_change and on_change_with during the creation of a record, because these will call all the field functions needed. The other fields.function which does not have on_change are not to be invoked until they are not in a read record.

No, you must not call all the on_change's only those related to a field
the user has changed.
Implementing the full client stack is an heavy job, you may better use
the web client which is responsive or make a tailored application which
does not care about following the client protocol.

> The only thing that I think it wouldn't work is the domain/states because what if there is a domain/state which mentions an Eval(fieldFUnction), so I have to have it on my context but I can't because I can't read a field.function (which does not have an on change getter). So the states makes my field invisible for example when creating a record. How do I put in my context these fields?

You must use its default value if there is one or its fallback value
depending of the field (usually None but it is an empty list for One2Many etc.)

Javier Uribe

unread,
Aug 7, 2018, 10:10:43 AM8/7/18
to tryton
Ok thank you very much
Reply all
Reply to author
Forward
0 new messages