コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
6697 ビュー

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
2599
1
6月 24
5066
1
1月 24
2445
1
10月 23
10741
1
10月 23
98