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

How to transfer binary files from one model to another in on_change?

Iscriviti

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

La domanda è stata contrassegnata
many2oneone2manyonchangebinaryfiles
4 Risposte
7348 Visualizzazioni
Avatar
Yenthe Van Ginneken (Mainframe Monkey)

Hi guys,

I have two models, named sale.order.our.customer and sale.order.our.customer.master.
The master contains default values which are uneditable from within other views.
The model sale.order.our.customer has a many2one to sale.order and a many2one to sale.order.our.customer.master like this:

 'our_customer_id': fields.many2one('sale.order', 'Our customer Reference', required=True, ondelete='cascade', select=True),
    'reference_our_customer_id': fields.many2one('sale.order.our.customer.master', string="Reference"),

In the sale.order model I have the following one2many:

'our_customer_line': fields.one2many('sale.order.our.customer', 'our_customer_id', 'About our customer',copy=True), 

The view is defined in XML like this:
 <page name="Customers" string="Customers">
	<field name="our_customer_line">
        <form string="Our customers">
            <field name="reference_our_customer_id" on_change="reference_our_customer_id_change(reference_our_customer_id)"/>
            <field name="name"/>
	    <field name="image"/>
        </form>
	<tree string="Our customers">
	    <field name="name"/>
	    <field name="image"/>
	</tree>
        </field>
	<field name="intro_text_our_customer"/>
</page>

When the user opens the dropdown (which shows all records from sale.order.our.customer.master) and clicks on an item the on_change function will go off. This on_change function will transfer data from the model sale.order.our.customer.master to sale.order.our.customer. This all works fine for default text fields etc but not for binary fields! The code:

 def reference_our_customer_id_change(self, cr, uid, ids, reference_our_customer_id, context=None):
        vals = {'value': {'name': '', 'image': ''}}
        if reference_our_customer_id:
            reference = self.pool.get('sale.order.our.customer.master').browse(cr, uid, reference_our_customer_id, context=context)
            vals = {'value': {'name': reference.name, 'image': reference.image}}
        return vals

The problem is that this throws up an error when I click on the save button:

 MissingError

One of the documents you are trying to access has been deleted, please try again after refreshing.

While I can see in the treeview that the field knows how big the image is etc. When I click on the download file I will get a file with the following name: "sO8013lW.bin".. It seems to contain the base64 encoding.
So my question is.. How do I transfer a file from one model to another in an on_change function , when it is already uploaded in the db? What am I doing wrong?

Thanks,
Yenthe

0
Avatar
Abbandona
Serpent Consulting Services Pvt. Ltd.

Yenthe, you are doing the right code. Please try out tools.image_resize_image_big(reference.image) Or decode by base64. Thanks.

Yenthe Van Ginneken (Mainframe Monkey)
Autore

@Serpent by default reference.image seems to be a base64 string. When I use tools.image_resize_image_big I will be able to save the record but when I then want to download it I will get a file in .bin format and when opening the file it will be a base64 string. So why is the filename & extension lost when transferring the data? I would really like to copy over the exact file, the filename and the extensions..

Bole

Yenthe... when odoo stores piuctures in DB it stores base64encoded picture, but you still need v7/v6 stype file_name sotred somewhere... try searching in older versions on how to use that.... basicly look at addons/base/ir/ir_attachment.py ... look at columns.. you have datas_fname ( the part you are missing) and store_fname look for some examples baed o0n this.. hope it helps :)

Avatar
Yenthe Van Ginneken (Mainframe Monkey)
Autore Risposta migliore

I eventually fixed this with the image_resize_image_big tool. This will automatically convert and handle the file in the correct way. The solution:

 def reference_our_customer_id_change(self, cr, uid, ids, reference_our_customer_id, context=None):
        vals = {'value': {'name': '', 'image': ''}}
        if reference_our_customer_id:
            reference = self.pool.get('sale.order.our.customer.master').browse(cr, uid, reference_our_customer_id, context=context)
            vals = {'value': {'name': reference.name, 'image': tools.image_resize_image_big(reference.image)}}
        return vals
0
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 give Domain filter for one2many field base on the condition of another field? (Odoo 13) Risolto
many2one one2many onchange domain_filter
Avatar
Avatar
2
lug 22
12757
odoo onchange function on one2many field Risolto
function fields many2one one2many onchange
Avatar
Avatar
Avatar
Avatar
3
ott 22
22371
How To Pass Value on Onchange of Many2one field in One2many Risolto
many2one one2many onchange one2many_list odoo9.0
Avatar
Avatar
3
set 18
13183
Access One2many field from onchange in v9
many2one one2many v7 onchange v9
Avatar
0
lug 16
4523
How to change a boolean field based on another field? (when a many2one is created) Risolto
project many2one one2many task onchange
Avatar
Avatar
Avatar
3
gen 24
13459
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