Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
6673 Widoki

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>

Awatar
Odrzuć
Autor

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

Najlepsza odpowiedź

 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


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
lip 24
2527
1
cze 24
5005
1
sty 24
2366
1
paź 23
10689
1
paź 23
98