Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
23889 Tampilan

In order to change the state of a record from draft to confirm depending on its own given date... in model after importing datetime, date:

date = fields.Date('Date', default=lambda * a: time.strftime('%Y-%m-%d'))
state = fields.Selection([('draft', 'Draft'), ('confirm', 'Confirm')], readonly=True, default='draft')

method:

@api.multi
def confirm_record(self):
current_date = str(datetime.now().date())
self.search(['date', '==', current_date]).write({'state': 'confirm'}):
return True
     

this metod is call by an automated action (ir.cron) and log file says:

ValueError: Invalid leaf date.

Odoo 10

Avatar
Buang

Is it necesary to format current_date string?

Jawaban Terbai

Hi 

The syntax of search method is wrong.

change this line

self.search([('date', '=', current_date)]).write({'state': 'confirm'})
Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
1
Sep 19
13248
2
Jul 25
4691
3
Jun 25
970
2
Des 24
7809
2
Nov 24
28599