跳至內容
選單
此問題已被標幟
2 回覆
2153 瀏覽次數

Hi

How are you everybody?

I have this problem  thank you

ValueErrorExpected singleton: financial.grant(1, 3, 4)


頭像
捨棄
最佳答案

Hi Salama,

A singleton error means that the result that you get contains multiple values while your code expects one record to be returned.
You can solve this by looping over the records and doing your logic there. For example:

for grant in financial_grant:
    print('grant record: ' + str(grant.name))

Odoo is telling you that the result contains a recordset, so multiple records, while it expected one.
There can be a lot of reasons for this but usually it means that you're not looping over records while you should or that you're calling 'self' within a loop instead of the record.
You can find quite some reports with singleton errors where you might learn from. For example:

https://www.odoo.com/nl_NL/forum/help-1/question/expected-singleton-71132
https://www.odoo.com/nl_NL/forum/help-1/question/valueerror-expected-singleton-144675
https://www.odoo.com/nl_NL/forum/help-1/question/valueerror-expected-singleton-s-self-147617
https://www.odoo.com/nl_NL/forum/help-1/question/valueerror-expected-singleton-stock-picking-141910#answer-141916 

Regards, 
Yenthe

頭像
捨棄
作者 最佳答案

@api.one
@api.depends('required_hours','completed_hours')#,'seniority_classamount_amount','seniority_pay','category_class_basic_grant','diplom_premium','performance_bonus','grade_premium','sem_owe_him')
def presence_avarage_count(self):
for r in self:
if r.required_hours > r.completed_hours :
r.presence_avarage = (float)(r.completed_hours / r.required_hours)
r.percentage_presence_avarage = r.presence_avarage * 100
else:
r.presence_avarage = -2



@api.one
@api.depends('presence_avarage','g_spy','g_indebtedness','g_bg','g_scm','g_pb','g_gp','g_dp')
for t in self:
if t.presence_avarage > 0:
t.g_final = (((t.g_spy * t.g_scm) + (2 * t.g_pb) + t.g_bg + t.g_gp + t.g_dp) * 3 * t.presence_avarage) + t.g_indebtedness
#t.a = t.g_spy * t.g_scm
#t.b = t.g_pb * 2
#t.c = t.a + t.g_bg + t.g_gp + t.g_dp + t.b
#t.d = 3 * t.c * t.presence_avarage
#t.g_final = t.d + t.g_indebtedness
else:
t.g_final = -3

頭像
捨棄