Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ

Good evening

I created a calculated field with Odoo Studio on the 'Bill of Materials' model in order to divide the quantity to be produced (base field) by the product density (associated field).

but every time after execution I end up with errors and I don't understand where this problem comes from

Here is the code I am using:


for record in self :

                record.x_studio_cv =   record.product_qty / record.x_studio_density


Thank you in advance for your help


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi Abou bakkar 

try

for record in self :
result = 0
if record.x_studio_density !=0:
​result = record.product_qty / record.x_studio_density
record.x_studio_cv =  result 

or 


for record in self:
    record.x_studio_cv = record.product_qty / record.x_studio_density if record.x_studio_density else 0




This prevent error dividing by 0 if some records has no density


Hope this help you

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 7 24
874
1
thg 6 25
15308
3
thg 4 25
5441
Compute Fields Đã xử lý
2
thg 7 24
2354
0
thg 7 24
1221