Community mailing list archives

community@mail.odoo.com

Re: how to set a unique default value for new fields

by
Pedro Cachaca
- 03/24/2016 07:21:43
Hi Stefan and Ondrej,

I am trying  with "post_init_hook" on Odoo 8 without success,

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...

Thanks


On Thu, Mar 24, 2016 at 11:22 AM, Ondrej Kuznik <ondrej.kuznik@credativ.co.uk> 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:      ondrej.kuznik@credativ.co.uk
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 feedback@credativ.co.uk

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

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe