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

Hi Forum!


I would need to set the value of the 'overtime_w' field as the default value for the 'overtime_w_edit' field without a related field.


overtime_w = fields.Float(compute='_compute_t_overtime_w')
overtime_w_edit = fields.Float()
Regards,

Steven

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

its very simple! just add a default key and value in py file just like bellow

discount = fields.Float(string='Discount (%)', digits='Discount', default=0.0)

name=fields.Char(string='Name',default="My Company")

Have Charm !!

Please upvote my ansar

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

i tried this method but i get 0 as the value, i don't know why even though there are no errors.

Thank you for your help!

if you use compute field, return default value by your function
in your case _compute_t_overtime_w

for further assistant .give me your complete code of function _compute_t_overtime_w

Edit your code of _compute_t_overtime_w :

@api.multi
def _compute_t_overtime_w(self):
self.overtime_weekdays = sum((self.attendance_ids.mapped('overtime_50_numeric')))
if self.overtime_weakdays==0:
self.overtime_weakdays="your expected default value"

your code and question are confusing,
where is the field overtime_w in the given code??
get clarified to get solutions!!

ผู้เขียน

'overtime_w' is on the same model as the 'overtime_w_edit' field.

ผู้เขียน

Sorry i write it wrong:
@api.multi
def _compute_t_overtime_w(self):
self.overtime_w = sum((self.attendance_ids.mapped('overtime_50_numeric')))
This is the right code.

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ค. 22
3872
Default value editable on field แก้ไขแล้ว
1
ส.ค. 19
3791
1
ธ.ค. 21
6302
0
ต.ค. 21
2865
0
เม.ย. 21
1985