Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
3645 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor

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)

Related Posts Odpovědi Zobrazení Aktivita
1
pro 16
7876
4
úno 20
4037
1
úno 24
1873
2
dub 24
1949
0
čvc 24
2836