跳至內容
選單
此問題已被標幟
1 回覆
6694 瀏覽次數

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.

Python Method that call by cron:

    @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


Cron code:
 
    <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>

頭像
捨棄
作者

@Axel Mendoza Your answer is right but not suit to my requirement .. This ID should be dynamic and what you do is fixed.. Instead of this I can also pass the id as in argument like model.send_feedback_email_cron(14).

最佳答案

 You could set a context value available to the method send_feedback_email_cron like:

 <field name="code">model.with_context(from_cron1=True).send_feedback_email_cron()</field>

And check against that context value inside the method like:

def send_feedback_email_cron(self):
    if self.env.context.get('from_cron1', False):
        # do your stuff


頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
7月 24
2589
1
6月 24
5051
1
1月 24
2435
1
10月 23
10723
1
10月 23
98