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

I have the following code called from an ir.cron entry.  The code works perfectly when 'Run Manually' but the record is not updated when run automatically.  Any ideas why ?  Does it have to be run under sudo ?

def reset_date(self):
_logger.debug("Finding records with ecd < %s", fields.Date.context_today(self))
records = self.env['module.name'].search([('ecd', '
for record in records:
if record.state == 'prelodged':
_logger.debug("Checking dr with name %s for ecd < %s", record.name, \fields.datetime.now())
record.write({'ecd': date.today()})

อวตาร
ละทิ้ง

Did you check if method called and the _logger.debug shows in log when run automatically

ผู้เขียน คำตอบที่ดีที่สุด

Yes, you do have to use sudo() if you're writing to a record within a cron job.  The line should be:

record.sudo().write({'ecd': date.today()})
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ต.ค. 23
2224
1
มี.ค. 20
3410
1
พ.ย. 24
4788
0
มี.ค. 24
1991
0
ม.ค. 24
77