Hello,
I want to fill a date field by the date of today(current day) when moving from state to another ( ex from pending to done )
How can do that, thanks
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hello,
I want to fill a date field by the date of today(current day) when moving from state to another ( ex from pending to done )
How can do that, thanks
Hi there,
You can do this by using an @api.onchange function on the field you'd like to detect changes on. Then you can write on another field. A theoretical example:
import datetime @api.onchange('state') def change_date_field(self):
self.your_date_field = datetime.datetime.today().strftime('%Y-%m-%d')
Regards,
Yenthe
Hi,
Suppose if you have got a function for changing the state of the record, either you can edit the original function or override the function using the super and do the necessary.
Suppose if this the function for changing the state of the record,
@api.multi
def button_done(self):
self.write({'state': 'done'})
and your date field is,
date = fields.Date('Date')
Now you can edit the original function and assign current date like this,
import datetime
@api.one
def button_confirm(self):
self.date = datetime.date.today()
self.state = 'confirm'
also, you can do it by overriding the function.
Thanks
Why not @api.onchange? Better is also @api.multi with self.ensure_one() honestly.
Yeah, just missed it
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up