Contributors mailing list archives

contributors@odoo-community.org

Re: Problem with computed default values

by
Groupement Régional Alimentaire de Proximité, Sylvain LE GAL
- 11/04/2016 15:17:45
Hi Daniel,

AFAIK, default is called once. I had the same problem. Maybe you can try to prepopulate your new column, with an init function, but you'll have problem with new items if there are created massively. (by import, etc....)

Maybe overload the create function is the best / easier way to do what you want. (I guess your field is readonly and so overload write function is unncessary.)

Kind regards.


Sylvain LE GAL
Service informatique
GRAP - Groupement Régional Alimentaire de Proximité

3 Grande rue des Feuillants, 69001 Lyon
Bureau :
(+33) 09.72.32.33.17
Astreinte :
(+33) 06.81.85.61.43
GRAP sur le Web : Site Web | Facebook | Twitter
GRAP - service Informatique sur le Web : Twitter


2016-04-11 17:08 GMT+02:00 Daniel Reis <dgreis@sapo.pt>:
Hello all,

I'm in need of some expert help.

I added a field to a model, to be used as a random unique identifier:
     token = fields.Char('Token', default=lambda s: str(uuid.uuid4()))

The problem is that, the already existing records all got the same exact uuid.
It seems that the lambda is evaluated once, before a mass update,  
instead of per record, as I expected.

Am I missing something?
Thanks for any help.

--
Daniel Reis






_______________________________________________
Mailing-List: http://odoo-community.org/groups/contributors-15
Post to: mailto:contributors@odoo-community.org
Unsubscribe: http://odoo-community.org/groups?unsubscribe