Subject: [tryton] Re: field Function to update by on_change

From: Cédric Krier <[email-masked]>
Date: Sun, 27 Jul 2008 00:15:32 +0200

I push the implementation in changesets: 56493f850cd9, 885d4a90fcea

It is not really like I talk previously. In fact it looks more like the
on_change behavior. That is why I call it on_change_with. So it is like
the on_change except that the function is called when one of the field
in the list of the on_change_with attributes is changed.

I don't re-use the function to compute the field function. Because I try
to do it with the purchase line amount and for this simple field I find
many problems that I was not able to fix in a generic way.
So I prefered to have a simple behavior and let the developpers care
about the intergrity of the result of the two function. And nothing
preventes one function to call the other one.

-- 
Cédric Krier

B2CK sprl
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email: [email-masked]
Website: http://www.b2ck.com/

---

From: Bertrand Chenal <[email-masked]>
Date: Mon, 21 Jul 2008 17:36:35 +0200

Le Sun, 20 Jul 2008 19:18:43 +0200,
Cédric Krier <[email-masked]> a écrit :

> For the issue184 [1], it would be great to find a generic solution that
> allows to update field Function without the need to re-write a function.
> 
> So the problem is that the function of a field Function is:
> 
> fcnt(self, cursor, user, ids, name, arg, context=None)
> 
> We work on ids so we need to have the record saved in the DB but we can
> not have it for the on_change call from the client.
> 
> The solutions, I see, are:
> 
>  - change the api for field Function to allow to works on
>    BrowserRecordList instead of ids.  And make the client to call this
>    function when any field of the record change in the interface.
> 
>  - Add on_change on each fields which re-compute the field.
> 
>  - Add a new param on field Function that looks like a on_change but
>    it is called when one of the fields is changed instead of the main
>    field and the return value is the computed value.
> 
> 
> So any comments or ideas are welcome.
> 
> 
> [1] http://bugs.tryton.org/roundup/issue184
> 

I have a preference for the third solution: i.e a new param on the function
field. This will not break the actual api and will be easy to use: actualy a
lot of  computed field are like:

for o in self.browse(...):
    [compute stuff]
    res[o.i] = stuff
return res

So it will be easy to define a compute_stuff function and to call it inside
the loop. And this function is exactly what we need.

Another though:
Maybe we also need to break a little the api, instead of using on_change
(1) param on fields we could define something like "update_with" which will
define the fields which will trigger an update_function for the current field.
And this param is the one we need for the question above.

(1) which means: if this field change call the onchange fonction with the
following fields as param, but sometimes there is no on_change on these very
fields which is a bit counter-intituve (if a field is needed to update other
fields why there is no on_change on it?).

-- 
Bertrand Chenal

B2CK sprl
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email: [email-masked]
Website: http://www.b2ck.com/

--~--~---------~--~----~------------~-------~--~----~
--
[email-masked] mailing list
-~----------~----~----~----~------~----~------~--~---

---

From: Cédric Krier <[email-masked]>
Date: Sun, 20 Jul 2008 19:18:43 +0200

-- 
Cédric Krier

B2CK sprl
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59