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

        _defaults = {
            'name': time.strftime('%Y-%m-%d %H:%M:%S'),
            'date': time.strftime('%Y-%m-%d'),
        }

 

It seems work fine, but in all open erp version had same issue. return same time for all records.

Like to create log. default datetime return same time for all logs.

 

 

 

 

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

Hello Zahin

You can use the field 'create_date', this is the "magic" column of openerp which is managed by openerp itself, so you will not need to put any default value for this and system will automatically put value in it.

create_date=fields.datetime("Log Date")

OR

create a function which returns date

    def _get_default_date(self,cr,uid,context={}):     
        return fields.date.context_today('your.model.name',cr,uid,context=context)

_defaults={'date':_get_default_date}

 

Hope this helps !!!

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

I also learned it from the hard way that when _defaults evaluate time directly it will evaluate it on server start ONLY.  Use fields.date.today() and fields.date.now() instead (see odoo/openerp/osv/fields.py).

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
เม.ย. 25
1299
Odoo Server Error แก้ไขแล้ว
1
เม.ย. 25
1499
0
พ.ย. 24
1691
0
ต.ค. 24
1684
1
พ.ค. 24
4964