Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

Why doesn't fetchall() return the same thing as the SQL request?

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
postgresqlv7api
18 Besvarelser
22155 Visninger
Avatar
Yug Faa

When I run this query on Postgresql :

SELECT code, total FROM hr_payslip_line WHERE slip_id=1

I get :

____________________________
|  code    |    total      |
__________________________
|  BASE    |    57000.00   |
____________________________

And when I run this code :

    sql = '''
        SELECT code, total FROM hr_payslip_line WHERE slip_id=%s
    ''' % (slip.id)
    cr.execute(sql)
    for code, total in cr.fetchall() :                
        raise osv.except_osv(_('Info'),_('code : %s\nTotal :  %s\nSlip ID : %s\nSQL : %s ' % (code, total,slip.id,sql)))

I've used the raise to catch the error I get this dialog :

    Info

code : BASE
Total : None
Slip ID : 1
SQL : SELECT code, total FROM hr_payslip_line WHERE slip_id=1

The problem is that the total return None and not 57000.00 More informations : 1. I've one slip 2. I've one line 3. the field total is a stored function

1
Avatar
Kassér
Daniel Reis

Can you add slip.id to your debug message and post the result?

Yug Faa
Forfatter

The debug is updated, I have used also res = cr.fetchall() and setting res[0] get 'BASE' and res[1] get False

Avatar
Quentin De Paoli (qdp)
Bedste svar

that's because your code is wrong :-) you should have used

for row in cr.fetchall() :                
        raise osv.except_osv(_('Info'),_('code : %s\nTotal :  %s ' % (row[0], row[1])))

you can also use

    for row in cr.dictfetchall() :                
            raise osv.except_osv(_('Info'),_('code : %s\nTotal :  %s ' % (row['code'], row['total'])))

or you can (could?) also use the browse record instead of using an SQL query that ignore the orm (and the access rights checking for example): try with the following:

for line in slip.line_ids:
    raise osv.except_osv(_('Info'),_('code : %s\nTotal :  %s ' % (line.code, line.total)))

if, even with that you cannot get a value for line.total, it means that the total line is not yet computed. To force the computation, just manually call _calculate_total().

4
Avatar
Kassér
Yug Faa
Forfatter

I replaced the code by the last one I get the same thing code='BASE' and Total=None,

Quentin De Paoli (qdp)

na... you should have done something wrong. Print the row before the raise please

Yug Faa
Forfatter

for row in cr.fetchall() : raise osv.except_osv(_('Info'),_('Row : %s' % (row,))) I get : Info

Row : (u'BASE', None) I guess that the problem is the type of total in the orm because it's a field calcultaed but it's stored !!

Quentin De Paoli (qdp)

i don't get the reason, this kind of code is widely used in OpenERP and without any problem... but you can still use the browse record to access the total -_- I updated my answer with a code avoiding the SQL query...

Yug Faa
Forfatter

It's my first thing that I have done, using browse get the same thing, when i print line.total I get None so I switch to SQL as solution but not work, it's a very complicate case, but if i find the problem I will publish it, I'm already advanced In OpenObject, and it's first time that I face som

Yug Faa
Forfatter

calling the function _calculate_total() has resolved the problem.

Avatar
Fabien Pinckaers (fp)
Bedste svar

Your code is correct, there are two possibilities:

  • You changed the value of total before or after the code you shown. As you used raise, the transactions are rollbacked and, when you perform your manual query in SQL, you do not see the changed value. Do a cr.commit() just before raise, you may get NULL in your manual SQL query after calling the python code.
  • Both tests are not on the same database.
1
Avatar
Kassér
Quentin De Paoli (qdp)

exactly...

Yug Faa
Forfatter

Of course the moment when the query is executed the value of total is False, there is an interference, but how can I get the same thing as the sql request, I use just one database, and I puted cr.commit() before the sql execution, and always same thing, I can share with you all the file

Avatar
CARLOS ALBERTO GARCIA BRIZUELA
Bedste svar

For me works this way:

  1. sql = "..."

  2. result = self.env.cr.execute(sql)

  3. value = ''

  4. for res in self.env.cr.dictfetchall():

  5.        if (value != ''):

  6.             value += ','

  7.         value += res['number']


  8. record.invoices = value

Hope it helps

0
Avatar
Kassér
Avatar
allanjm
Bedste svar

cr.execute('''SELECT code, total FROM hr_payslip_line WHERE slip_id=%s''' % (slip.id)) x = cr.fetchone() #Only if it returns one (1) row

raise osv.except_osv('Info', 'code : %s\nTotal : %s' % (x[0], x[1]))

#or to return just one row SELECT code, SUM(total) FROM hr_payslip_line WHERE slip_id=1 GROUP BY code

0
Avatar
Kassér
Avatar
Yug Faa
Forfatter Bedste svar

I guess that the problem is an interference between the function compute_sheet in the hr_payroll module and my function

I have a stored fucntion field that get total from what shown above, but I put store=False it works well, for me it's not logic and I declared this as a bug,

There is somthing that not good in this module, as a advanced developper I get always values of stored function in the database using SQL and anawhere, this time it's different for me, If I Try to use cr.commit(), there isn't any changes, if I use cr.rollback() I get an other message that say that a field quantity from the object hr_payslip_line doesn't exist, for my module there is not any treatement of field quantity

So if you have a logic to resolve this problem, I'm gratfull for you

To recap : I want to compute a stored function field, I execute the code above and it don't work

0
Avatar
Kassér
Quentin De Paoli (qdp)

just manually call _calculate_total()

Yug Faa
Forfatter

Ohh Quentin you're found a path , Thank you now I see 57000.00, I have to set this resolved

Quentin De Paoli (qdp)

ok let me add this in my answer, then you can check my answer as correct ^^

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
v7 - How to "query-insert" a stage change in a task journal ?
postgresql v7
Avatar
Avatar
4
nov. 16
4387
Is there a v7 API guide? Løst
v7 api
Avatar
Avatar
1
mar. 15
4955
Anyone using PostgreSQL 9.3 with OpenERP 7.0? Feedback? Good? Bad? Same?
postgresql v7
Avatar
Avatar
Avatar
2
mar. 15
6912
How call an API when values change in DataBase? Løst
postgresql api write
Avatar
Avatar
Avatar
3
maj 21
8870
v7 google api configuration, why do I get XmlHttpRequestError ?
google v7 api
Avatar
0
mar. 15
4455
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now