Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
960 Lượt xem
@api.depends('category_id')
def compute_duration_display(self):
if self.category_id == 1:
self.number_of_days_display = 10
elif self
.category_id == 2:
self.number_of_days_display = 10
elif self
.category_id == 3:
self.number_of_days_display = 15
elif self
.category_id == 4:
self.number_of_days_display = 20

i tried this code but iam getting error.

Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks for your answer.

Then how can i compare without using id's?

Câu trả lời hay nhất

Hi,

If the category_id is many2one field and if you need to perform comparison using ID, then you have to change self.category_id to self.category_id.id


Also comparison using the hard codes id's is not a good practice.


Thanks & Regards

Walnut Software Solutions

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 6 25
1796
3
thg 7 25
3394
1
thg 5 25
1542
1
thg 5 25
1803
4
thg 5 25
2926