跳至内容
菜单
此问题已终结
4 回复
7452 查看

Hello.

I want to change state by current date, when choose current date the state automaticaly move (ex from draft to expired)?

How can i do that, thanks

形象
丢弃
编写者 最佳答案

Thank you for guiding me using Scheduled Action Paresh.

I adding the the model=ir.cron in my .xml and adding python function to change the state from active to expired.

didn't work with:

    record.cop_expiry < datetime.datetime.today()
beside of using it, i'm using this:

    record.cop_expiry <= fields.Date.today():

It works well to me

形象
丢弃
最佳答案

Hi Boby:

You can define a Scheduled Action which will run every day after midnight and update the previous day's draft records to expired.

To define the Scheduled Action, you need to activate developer mode and go to Settings > Technical > Scheduled Actions.

形象
丢弃
编写者

With Scheduled Actions how can i know when current date is match with the expired date?

I have this model:

class xapiens_employee(models.Model):

_inherit = 'hr.employee'

certificate_state = fields.Selection(string="COP Status", selection=[

('draft', 'Draft'),

('expired', 'Expired')], readonly=True, default='draft')

class certificate_proficiency(models.Model):

_name = 'hr.certificate.proficiency'

_description = 'Certificate Proficiency'

_rec_name = 'certificate_name_cop'

cop_emp_id = fields.Many2one('hr.employee', string="COP Employee Name")

cop_file_name = fields.Char(String="File Name COP")

certificate_name_cop = fields.Many2one('hr.certificate.proficiency.name', string="Certificate Name")

cop_number = fields.Char('Number')

cop_issue = fields.Date('Issued')

cop_expiry = fields.Date('Expiry'))

When Date Today is match with cop_expiry, the certificate_state move to expired

Based on your description of what you are trying to do, you need to check for records where expiry date is before the date on which the job runs.

record.cop_expiry < datetime.datetime.today()

相关帖文 回复 查看 活动
3
3月 22
6995
1
10月 21
7775
3
6月 25
1006
1
1月 25
17901
4
5月 24
12623