Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
6691 Visualizzazioni

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>

Avatar
Abbandona
Autore

@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).

Risposta migliore

 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


Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
lug 24
2588
1
giu 24
5046
1
gen 24
2434
1
ott 23
10719
1
ott 23
98