I have a problem with running a scheduler in Odoo 15.
我在Odoo 15中运行调度程序时遇到问题。
I have a function python like this for sending messages to chat:
我有一个这样的函数,用来发送聊天消息:
def action_send_notification(self):
today_date = datetime.today()
for i in self:
if i.search([('date_end','<',today_date)]):
message = "STR has been expired"
recipient1 = i.employee_id.user_id.partner_id.id
recipient2 = i.env['res.users'].sudo().search([('name', 'ilike', 'admin')])
channel = i.env['mail.channel'].channel_get([recipient1])
channel_id = i.env['mail.channel'].browse(channel["id"])
channel_id.message_post(
body=message,
message_type='comment',
subtype_xmlid='mail.mt_comment',)
For cron XML, here it is:
对于cron XML,如下所示:
<record id="STR_notif_expiration_scheduler" model="ir.cron">
<field name="name">STR Notif Expiration</field>
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="doall">0</field>
<field name="model_id" ref="model_hr_str"/>
<field name="code">model.action_send_notification()</field>
<field name="priority">5</field>
</record>
When I run by clicking Run Manually it's not working.
It's not running automatically as well.
当我通过单击手动运行来运行时,它不工作。它也不会自动运行。
But when I try to run the python function by a custom button, it's working.
但是,当我尝试通过一个定制按钮运行python函数时,它起作用了。
My expectation is that the scheduler can run by Run Manually and even automatically.
我的期望是调度程序可以通过手动甚至自动运行来运行。
更多回答
优秀答案推荐
Try Using @api.model decorator on the method.also add
<field name="state">code</field>
. It should work
尝试在该方法上使用@api.Model修饰器。还要添加
代码
。它应该能行得通
更多回答
thanks for your solution but its still not working on me , even when I put @api.model decorator , its show error function() takes 1 positional argument but 2 were given
谢谢你的解决方案,但它对我仍然不起作用,即使当我放置@api.Model修饰符时,它的show error函数()接受1个位置参数,但给出了2个
我是一名优秀的程序员,十分优秀!