如何在cron调用的方法中将cron id作为arg传递 [英] How to pass cron id as arg in method that the cron calls

查看:118
本文介绍了如何在cron调用的方法中将cron id作为arg传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多cron在不同时间调用同一方法,并且该方法需要找到哪个cron调用了该方法,以基于该cron查找其他记录.

I have many crons that call the same method at different time and the method needs to find that which cron called it to find other record based on that cron.

args不能固定.最终用户会在odoo的前端侧创建大量的cron,因此,只要cron执行并调用该方法,cron就会将其自己的id传递给该方法,因此它应该是动态的.

The args mustn't be fixed. There'll be the number of crons create by end user on the front end side of odoo so whenever the cron executes and call the method the cron should pass it's own id to the method so it should be dynamic.

由cron调用的Python方法:

@api.model
def send_feedback_email_cron(self,id):
    #id is needed to find global channel in which this cron is set.
    global_channel = self.global_channel_id.search([('cron_id','=',id)])
    for rule in global_channel.email_rule_ids:
        rule.send_customer_review_email()
    return True

验证码:

<record id="ir_cron_send_customer_feedback_email_job" model="ir.cron">
    <field name="name">Send Feedback Email to customer</field>
    <field eval="False" name="active"/>
    <field name="user_id" ref="base.user_root"/>
    <field name="interval_number">4</field>
    <field name="interval_type">hours</field>
    <field name="numbercall">-1</field>
    <field eval="False" name="doall"/>
    <field eval="ref('customer_review_global_channel_ept.model_email_global_channel_rule_ept')" name="model_id" />
    <field name="state">code</field>
    <field name="code">model.send_feedback_email_cron()</field>
</record>

推荐答案

使用ir.cron functionargs字段:

<record id="ir_cron_send_customer_feedback_email_job" model="ir.cron">
    <field name="name">Send Feedback Email to customer</field>
    <field eval="False" name="active"/>
    <field name="user_id" ref="base.user_root"/>
    <field name="interval_number">4</field>
    <field name="interval_type">hours</field>
    <field name="numbercall">-1</field>
    <field eval="False" name="doall"/>
    <field eval="ref('customer_review_global_channel_ept.model_email_global_channel_rule_ept')" name="model_id" />
    <field name="function" eval="'send_feedback_email_cron'"/>
    <field name="args" eval="'(...your args...)'"/>
</record>

这篇关于如何在cron调用的方法中将cron id作为arg传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆