I assigned (m2o) to my_object a cron (Automation->Scheduled Actions). The cron execute (Python code) a method. I need to have the id (or name) of the cron that call the method inside the method to do some actions on the objects assigned to the cron.
I think that the cron-object is not defined when the method execute, but it can be when the method is called. So I think that the way is to pass the id as argument but I don't know how to do so. I tried with "env" without succes.
Cron Python code
<record id="myobject_cron_task" forcecreate='True' model="ir.cron">
<field name="name">MyModel Task</field>
<field name="active" eval="True" />
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="model_id" ref="model_my_object"/>
<field name="state">code</field>
<field name="code">model.my_method(cron_id)</field>
</record>
Method
def my_method(self, active_cron_id):
sel_objec = self.env['my.object'].search([('cron_id', '=', active_cron_id)])
print(sel_objec)
NB: same question asked here without solution