How to force recalculation of depending fields?


I just began learning Tryton framework and, first, I wish to say how it looks great !
So, sorry if my first questions seem dumb…

If have some calculated fields (readonly on the view side). If I do any change in the calculation code, how to force the system to recalculate these fields’ values ?
tytond-admin -u doesn’t seems to launch any recalculation.

Below is a sample case :

def on_change_with_dependingField(self):
return doCalculation(self.aField,self.anotherField)

I wish to force the evaluation of ‘dependingField’, because I did some logic changes in the function ‘doCalculation’.

Thank you for your help.

Welcome to Tryton!

As far as I understand, calculated fields should not be stored in the DB. Tryton has fields.Function() that calculates the value dynamically and is not stored in the DB.

Otherwise, when updating code or needing migrations, there is a pattern used in official modules using the __register__() method.

Another option is creating a proteus script to perform specific tasks in the DB. They use it to create the demo DB.

fields.Function on docs
fields.Function in trytond_product
Demo script

Thank you for this kind and well documented answer.

I understand now that these fields should be calculated ‘on the fly’, I can apply this advice for most of the cases.

As far as I know, searcher function can only return domains for fields in the database.
But then, how one should handle search for the most complex logics, that can only implemented in Python and barely not in SQL ?

Function fields are automatically updated on server side, if you need to update the values on the client side you can combine them with on_change_with methods

Here is one example from the account module.

As the in operator accepts a query, you can use and sql query to compute the matching ids of your search and then return the following domain:

[(‘id’, ‘in’, query)]

Here is an example from the account_payment module

Hope it helps

Great examples, Thank You !
I didn’t realized queries could be so powerful.

Btw, great community, thank you again.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.