Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
4515 Vizualizări

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.

Imagine profil
Abandonează
Autor Cel mai bun răspuns

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

Imagine profil
Abandonează

keep proper indentations between lines

Cel mai bun răspuns

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

Imagine profil
Abandonează