Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4526 Lượt xem

hello dear odooers,

Im facing a problem here , i created with studio a computed field which calculates the sum of  a  colomn x_studio_subtotal_delivery also created by studio.

i used this code :

for record in self:
for rec in record.order_line:

if rec. x_studio_subtotal_delivery:
record['x_studio_sum']=rec. x_studio_subtotal_delivery

with dependencies : x_studio_sum

but sum is always zero it hasnt been calculated. i know  i can do it with agreagation but i need this sum to calculate other fields 

Please help me solve this issue.

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

I tried this code yes the field is calculated but it gave me this error when i tried to create a new sale order:

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/odoo/src/odoo/14.0/odoo/http.py", line 640, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/odoo/src/odoo/14.0/odoo/http.py", line 316, in _handle_exception
    raise exception.with_traceback(None) from new_cause
  File "", line 4
    sum=+rec.x_studio_subtotal_delivery
    ^
IndentationError: expected an indented block

Ảnh đại diện
Huỷ bỏ

keep proper indentations between lines

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

Hi,
You are giving the computed field itself as the Dependencies. Instead of that give 'order_line' as dependencies.
Also if you want the value as sum of value from each of the order line , you have give the code as :

sum = 0
for record in self:
for rec in record.order_line:
if rec. x_studio_subtotal_delivery:
sum += rec. x_studio_subtotal_delivery
record['x_studio_sum'] = sum

Regards

Ảnh đại diện
Huỷ bỏ