Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
1891 Lượt xem
There are two many2one fields. From these two fields
(assigned_to.assigned_quantity & vendor_name.unit),
I want to calculate the difference between them. Please check the below code.

@api.depends("assigned_to.assigned_quantity", "vendor_name.unit")
​def _compute_quantity(self):
​​total_buy = 0
​total_assign = 0
​for record in self:
​for rec1 in record.assigned_to:
​​total_assign += rec1.assigned_quantity​
​for rec2 in record.vendor_name:
​total_buy += rec2.unit
​quantity = total_buy - total_assign
​record.quantity_new = quantity


The code is showing proper value in the form view.

Though when I use it tree view it shows cumulative value. 

Is there any way to fix it? 


Thank you. 

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

It works! Thank You so much! 

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

Hi,

You have to move the total_buy and total_assign variables inside the for loop to resolve the issue. Just move the lines inside the for loop after for record in self, this will resolve your issue.


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
0
thg 8 19
3615
1
thg 12 15
6236
1
thg 10 20
7808
1
thg 3 15
8112
1
thg 11 24
2093