This question has been flagged
1 Reply
6453 Views

I've got a char field and I'm trying to set the default value to the current year, but it doesn't work. Is it possible to do this? I know I could do it with compute but I need that the user can input different values if he needs to.

year = fields.Char(string='Year', default=str(datetime.now().year))

and yes I have datetime imported from datetime.

Avatar
Discard
Best Answer

def get_year(self):

    return str(datetime.now().year)

year = fields.Char(string='Year', default=get_year)

Avatar
Discard
Author

Thanks... it works, have tried that already but had the method after the field declaration. Moved it before it, and it works.