İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
3635 Görünümler

Hello everyone,

i created stored computed field that get total value based on lines and some conditions the compute function work well, but when remove the line the computed field value not deleted.

any idea ? 

function code:

@api.depends('res_id', 'res_id.consumption_rate', 'res_id.resource_type')
def get_total_values(self):
hour_values = []
ton_values = []
for line in self.res_id:
if line.consumption == 'hour':
hour_values.append(line.consumption_rate)
print(hour_values)
self.total_per_hour_cost = sum(hour_values)
else:
if line.consumption == 'ton':
ton_values.append(line.consumption_rate)
print(ton_values)
self.total_per_ton_cost = sum(ton_values)

Avatar
Vazgeç
En İyi Yanıt

Hi Loay eIhaj,

Initially, Please try to set default value for the functional field in the function method.
Like :

@api.depends('res_id', 'res_id.consumption_rate', 'res_id.resource_type')
def get_total_values(self):
hour_values = []
ton_values = []
self.total_per_hour_cost = 0.0
self.total_per_ton_cost = 0.0
for line in self.res_id:
if line.consumption == 'hour':
hour_values.append(line.consumption_rate)
print(hour_values)
self.total_per_hour_cost = sum(hour_values)
else:
if line.consumption == 'ton':
ton_values.append(line.consumption_rate)
print(ton_values)
self.total_per_ton_cost = sum(ton_values)



Hope it will help you. Please Up vote.
Avatar
Vazgeç
En İyi Yanıt

If you are creating a stored computed field, make sure you have given depends so that when dependent field is changed, value will be recomputed. Also provide your code snippet as well so it's easier to understand the problem rather than guess what might have gone wrong.

Avatar
Vazgeç
Üretici

function code:

@api.depends('res_id', 'res_id.consumption_rate', 'res_id.resource_type')
def get_total_values(self):
hour_values = []
ton_values = []
for line in self.res_id:
if line.consumption == 'hour':
hour_values.append(line.consumption_rate)
print(hour_values)
self.total_per_hour_cost = sum(hour_values)
else:
if line.consumption == 'ton':
ton_values.append(line.consumption_rate)
print(ton_values)
self.total_per_ton_cost = sum(ton_values)

İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Ara 16
7876
4
Şub 20
4036
1
Şub 24
1869
2
Nis 24
1949
0
Tem 24
2835