1

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.

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.

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>

1 Answers1

0

Use ir.cron function and args fields:

<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>
forvas
  • 9,801
  • 7
  • 62
  • 158
  • I don't want to send fix args all the time. There'll be the number of crons create by end user on front end side of odoo so whenever the cron executes and call the method the cron should pass the id to the method. – Vishal Khichadiya Jun 21 '18 at 10:44
  • Apologies your edits are removed when I add some information in the question! – Vishal Khichadiya Jun 21 '18 at 10:58