Skip to Content
Menu
This question has been flagged
2 Replies
5106 Views

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
Discard
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
Discard
Author Best Answer

Thanks dude!

Avatar
Discard
Related Posts Replies Views Activity
1
Mar 21
2652
5
Dec 23
19328
2
Dec 18
5691
3
Nov 22
3271
0
Oct 17
2092