Odoo Help

0

pass cron id as an arg in the method that the cron calls

By
Vishal Khichadiya
on 6/21/18, 2:21 AM 235 views

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

Vishal Khichadiya
on 6/21/18, 5:40 AM
0

Axel Mendoza

--Axel Mendoza--
13125
| 7 8 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza
On 6/21/18, 3:55 AM

 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


About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 6/21/18, 2:21 AM
Seen: 235 times
Last updated: 6/21/18, 5:41 AM