Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
23892 มุมมอง

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

อวตาร
ละทิ้ง

Is it necesary to format current_date string?

คำตอบที่ดีที่สุด

Hi 

The syntax of search method is wrong.

change this line

self.search([('date', '=', current_date)]).write({'state': 'confirm'})
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Datetime change Format issue in odoo10?? แก้ไขแล้ว
1
ก.ย. 19
13256
2
ก.ค. 25
4702
3
มิ.ย. 25
973
2
ธ.ค. 24
7815
How to ORDER BY? [Odoo 10] แก้ไขแล้ว
2
พ.ย. 24
28605