Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

Trying to extract a pdf file from ir_attachment.dbdatas

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
attachmentpostgresqlopenerp7
3 Risposte
10973 Visualizzazioni
Avatar
Cameron

Hi - we have a crashed Openerp 7 db adn where trying to extract a pdf file from ir_attachment.dbdatas

I have tried directly via SQL but although I can retrieve something it appears to be "Gobbledygook!!

Is there a way of extracting files from the db?

copy 
(SELECT 
db_datas
FROM
ir_attachment
WHERE
name='Invoice_SAJ_2016_0964_.pdf')
to '/tmp/Invoice.pdf' (FORMAT "binary");

Any advice please.

If I open each file in a text editor each file starts with "PGCOPY" - a clue maybe?

1
Avatar
Abbandona
Jaime Vasquez

Hi Cameron,

Querying the database will not work because the pdf file is encoded by openerp. You have to use some python code to extract the pdf file:

Please fix the python code accordingly. I dunno how to paste and format a code block in this forum. :)

Formated Code: http://paste.ofcode.org/hecdAnzV2xKXnL238r8Scm

import psycopg2

import base64

def main():

# Try to connect

try:

conn=psycopg2.connect("dbname='yourdatabase' user='openerp' password='openerp'")

except:

print "unable to connect to database."

cur = conn.cursor()

try:

cur.execute("""select

a.name

, a.create_date

, regexp_replace(a.description , E'[\\n\\r]+', ' ', 'g' ) description

, a.datas_fname

, a.id

, a.db_datas --binary attachment encoded

from ir_attachment a

where a.datas_fname is not null

order by id

limit 10;

""")

except:

print "Error querying Postgresql"

rows = cur.fetchall()

try:

for row in rows:

print row[0] # name

print row[1] # description

print row[2] # datas_fname

print row[3]

#save pdf to disk

#invalid pdf. It's encoded in base64 by openerp

f = open('c:/Temp/file.pdf', 'wb')

f.write(row[5])

f.close()

#valid pdf.

f= open('c:/Temp/file_decode.pdf', 'wb')

#we have to decode first

f.write(base64.b64decode(row[5]))

f.close()

except ValueError:

print ValueError

if __name__ == '__main__':

main()

Greetings.

Cameron
Autore

Jamie - :) I cannot thank you enough. Worked a treat. Thank you, thank you, thank you :)

Avatar
Cameron
Autore Risposta migliore

This is my reHASH of Sir 'Jaime Vasquez' above code, I tried converting his comment to an answer but kept failing.

Jaime, please forgive my poor rehash of your coding, I'm still in the "Jowels flapping in the wind, vertical acceleration learning phase" :)


import psycopg2

import base64

def main():

#Dataase details

host='192.168.0.100'

port= '5432'

dbname='CrashedDbName'

user='openerp'

password='LittlePigLetMeIn'

#Database connection

try:

conn = psycopg2.connect ("host='"+host+"' port= '"+port+"' dbname= '"+dbname+"' user= '"+user+"' password= '"+password+"'")

cur = conn.cursor()

print "Connected"

except:

print "Unable to connect to database."

return

try:

#Invoice range to extract

for Invoice in range (768,967):

SearchString = "SELECT a.name, description, a.create_date, a.datas_fname, a.id, a.db_datas FROM ir_attachment a WHERE a.datas_fname = '"+"INVSAJ20160"+str(Invoice)+".pdf.pdf"+"';"

cur.execute(SearchString)

rows = cur.fetchall()

#Save Invocies to file

for row in rows:

if row[5]:

#valid pdf

#Save path

f= open('C:\Users\Me\Documents\Invoices\INVSAJ20160'+str(Invoice)+'.pdf', 'wb')

#We have to decode first

f.write(base64.b64decode(row[5]))

f.close()

except:

print ValueError

return

if __name__ == '__main__':

main()

1
Avatar
Abbandona
Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
How to automatically add a text file to attached document in OpenERP 7?
attachment openerp7 ir
Avatar
0
ott 15
4811
How can I know the password of the openerp Postgresql user ? v7
password postgresql openerp7
Avatar
Avatar
1
mar 15
10146
Restrict To Return None Value from the SQL Query Risolto
postgresql sql openerp7 odooV8
Avatar
Avatar
Avatar
2
dic 19
6993
How to represent Postgresql interval in Openerp 7 ?
postgresql python2.7 openerp7 postgresql9.3
Avatar
0
ott 18
3990
White/blank screen when loading OpenERP
javascript postgresql python2.7 openerp7
Avatar
Avatar
Avatar
Avatar
Avatar
5
gen 18
15770
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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