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

i don't want to write multiple time.

_defaults = {

'extra_cleaning_hourly_rate': lambda self, cr, uid, c: self.pool.get('res.company').browse(cr, uid, uid, c).extra_cleaning_hourly_rate,

'extra_cleaning_hourly_rate_material': lambda self, cr, uid, c: self.pool.get('res.company').browse(cr, uid, uid, c).extra_cleaning_hourly_rate_material,

'extra_cleaning_hourly_rate_material': lambda self, cr, uid, c: self.pool.get('res.company').browse(cr, uid, uid, c).window_cleaning_hourly_rate,

}

อวตาร
ละทิ้ง

it's not making sense , extra_cleaning_hourly_rate_material can have to two default on the basis on "certain condition" (so apply that condition in one lambda )

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

Hi Vijay,

Here you go!

- override the default_get method to achieve this.

 in dictionary you have to pass key as your field name for which you want to set default value, would your updated value for that field.

#v7
def default_get(self, cr, uid, ids, context=None):
    # Either prepare your dictionary here to update in result dictionary    
    result = super(class_name, self).default_get(cr, uid, ids, context=context) # or directly update your result dictionary with new fields value to be updatr    return result


#v8
@api.model
def default_get(self, vals):
#update dictionary with default fields
    result = super(product_new_revision, self).default_get(vals)
#Update dictionary with default fields
    return result
eg. Update dictionary value in this format -> {'field_name': 'default value'}

Hope this will help.

Regards,

Anil.

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

Hello,

You can use the default_get method it returns a dict mapping fields names with their default values.

You can also check an example here 

Hope this could help

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.พ. 20
4229
0
มี.ค. 25
1264
0
ม.ค. 25
3310
1
ส.ค. 23
14623
change password แก้ไขแล้ว
1
ส.ค. 23
13260