Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
449 Ansichten

Hi everybody!!

Please i have a field which is a result of a function (fields.function). But my function contains an SQL request and i didnt understand how to create it.

Here is what i have tried:

def _total_get(self, cr, uid, context=None):

cr.execute('select total from hr_payslip_line where code = "22001"')

return cr.fetchall()

Please help

Avatar
Verwerfen
Beste Antwort

Hello


Function field signature:

 (self, cr, uid, ids, field_name, arg, context=None):

and you need to return the result for each id in ids...

So if it's the same for each ids:

dict.fromkeys(ids, result)


==>  You shloud have something like that...

def _total_get(self, cr, uid, ids, fieldname, arg, context=None):
    cr.execute('select total from hr_payslip_line where code = "22001"')
    # supposing you are waiting only one element ??? always for this code 22001 ? 
total = cr.fetchone()[0];
    return dict.fromkeys(ids, total)

 

But it's a strange case... Usually, we want a result distinct according the id given...


Let us know if it's work for you !

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
4
Okt. 16
31879
1
Sept. 15
4508
1
Juni 15
1442
0
Apr. 15
1042
2
Apr. 15
1412