Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
14325 มุมมอง

Odoo V11 

I want to set time as default in ir.cron object for currency update

I am getting error like this when I try loading the module data .

odoo.tools.convert.ParseError: "<class 'TypeError'>: "'module' object is not callable" while evaluating' datetime.combine(datetime.now().date() + timedelta(days=1), time(hour=15,minute=40))'"

How can I solve this problem ? 

My data code:

<record model="ir.cron" id="ir_cron_currency_update_every_day">
        <field name="name">Currency Rate Update</field>
        <field name="interval_number">1</field>
        <field name="interval_type">days</field><!-- it s every day -->
        <field name="numbercall">-1</field>
        <field name="state">code</field>
        <field name="doall" eval="False"/>
        <field name="model_id" ref="currency_rate_update.model_currency_rate_update_service"/>
        <field name="nextcall" eval="datetime.combine(datetime.now().date() + timedelta(days=1),time(hour=15,minute=40))"/>
        <field name="code">model._run_currency_update()</field>
</record>

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

Try this code,

<record model="ir.cron" id="ir_cron_currency_update_every_day">
<field name="name">Currency Rate Update</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field><!-- it s every day -->
<field name="numbercall">-1</field>
<field name="state">code</field>
<field name="doall" eval="False"/>
<field name="model_id" ref="currency_rate_update.model_currency_rate_update_service"/>
<field name="nextcall" eval="(DateTime.now() + timedelta(days=1)).strftime('%Y-%m-%d 15:40:%S')" />
<field name="code">model._run_currency_update()</field>
</record>


Also, make sure that whether there is a need to set the next execution time as the next execution time will get set automatically based on the given interval number and interval type.


Thanks

อวตาร
ละทิ้ง
ผู้เขียน

Thank you so much :) I have tried this code and it worked. But, I had to use 'datetime.now ()' instead of 'DateTime.now ()'

คำตอบที่ดีที่สุด

This error statement TypeError: 'module' object is not callable is raised as you are being confused about the Class name and Module name. The problem is in the import line . You are importing a module, not a class. This happend because the module name and class name have the same name .

If you have a class "MyClass" in a file called "MyClass.py" , then you should import :

 from MyClass import MyClass

In Python , a script is a module, whose name is determined by the filename . So when you start out your file MyClass.py with import MyClass you are creating a loop in the module structure.

http://net-informations.com/python/iq/typeerror.htm

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.พ. 24
15421
1
ธ.ค. 22
4931
2
ธ.ค. 22
14358
2
มิ.ย. 22
6194
2
มิ.ย. 22
4603