Skip to Content
Menu
This question has been flagged
2 Replies
3796 Views

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.

Avatar
Discard
Author Best Answer

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

Avatar
Discard

keep proper indentations between lines

Best Answer

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

Avatar
Discard