跳至内容
菜单
此问题已终结
2 回复
6139 查看

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!

形象
丢弃
最佳答案

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 

形象
丢弃
编写者 最佳答案

Thanks dude!

形象
丢弃
相关帖文 回复 查看 活动
1
3月 21
4185
5
12月 23
21345
2
12月 18
6745
3
11月 22
4696
0
10月 17
3208