Community mailing list archives
Re: how to set a unique default value for new fieldsby
Hi Stefan and Ondrej,
I am trying with "post_init_hook" on Odoo 8 without success,
I follow this example : https://github.com/OCA/partner-contact/blob/8.0/partner_external_maps/__openerp__.py
Is "post_init_hook" executed only at installation or -i ? or is available for module update -u ?
Ondrej, is _set_default_value_on_column another way to do ? not easy to find example...
On Thu, Mar 24, 2016 at 11:22 AM, Ondrej Kuznik <firstname.lastname@example.org> wrote:
On 24/03/16 09:18, Stefan Rijnhart wrote: > On 03/24/2016 09:32 AM, pedro cachaca wrote: >> >> But when I update the module, all existing records get the >> same value uuid for token... >> > > Hi Pedro, > > as you found out, when a new field is added to the Odoo datamodel, and > it has a default method, this method is only called once and the result > is applied to all existing records. Afterwards, the method is called for > every new record that is being created. > > You need to write a post_init_hook to generate distinct tokens for > existing records. Just beware that this will not work if you are trying to enforce the field's uniqueness as well, for that (on 8.0 and later), you need to hook into _set_default_value_on_column or your constraint is not going to be added. -- Consultant credativ Ltd Suite 5, Bloxam Court Corporation Street UK office: +44 1788 298150 Rugby Email: email@example.com CV21 2DU Web: http://www.credativ.co.uk We would love to hear you your feedback on the service provided. If you have anything you would like to contact us on the service we have provided, please send your feedback to firstname.lastname@example.org credativ Ltd is registered in England & Wales, company no. 5261743 Certified by CompTIA / AccredIT UK with the ICT Supply standard of quality for Software Product Design and Development