Skip to Content
Menú
This question has been flagged
2 Respostes
6142 Vistes

Hello,

I'm new to Odoo I have problem with simple cron job that all it has to do is to update a single field, but can't make it done. Basically when I call this function from cron job does't have any records. What should I do to access my records? Please be more specific :)

Here is my model:


    @api.model

    def being_created(self):

        for rec in self:

            delta = datetime.now() - rec.create_date

            # if delta.days == 1:

            #     rec.created = f'{delta.days} day ago'

            # else:

            #     rec.created = f'{delta.days} days ago'

            rec.created = delta


And my cron XML:

<odoo>

    <data noupdate="1">

        <record id="BeingCreated_cron" forcecreate='True' model="ir.cron">

            <field name="name">Being Created</field>

            <field eval="True" name="active"/>

            <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_clients_clients"/>

            <field name="state">code</field>

            <field name="code">model.being_created()</field>

        </record>   

    </data>

</odoo> 


Thanks and have a great day!

Avatar
Descartar
Best Answer

Dear Galin Jelev,

model.being_created() calls with zero objects. Thats why no records displayed.

Use below code to get all records in the model.

@api.model
def being_created(self):
for rec in self.env['your.model'].search([]):
# Your code

Thanks

 iWesabe 

Avatar
Descartar
Autor Best Answer

Thanks dude!

Avatar
Descartar
Related Posts Respostes Vistes Activitat
1
de març 21
4186
5
de des. 23
21346
2
de des. 18
6746
3
de nov. 22
4696
0
d’oct. 17
3208