Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

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

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
many2oneone2manyonchangebinaryfiles
4 Răspunsuri
7334 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
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)
Autor

@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 :)

Imagine profil
Yenthe Van Ginneken (Mainframe Monkey)
Autor Cel mai bun răspuns

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
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

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

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
How to give Domain filter for one2many field base on the condition of another field? (Odoo 13) Rezolvat
many2one one2many onchange domain_filter
Imagine profil
Imagine profil
2
iul. 22
12749
odoo onchange function on one2many field Rezolvat
function fields many2one one2many onchange
Imagine profil
Imagine profil
Imagine profil
Imagine profil
3
oct. 22
22359
How To Pass Value on Onchange of Many2one field in One2many Rezolvat
many2one one2many onchange one2many_list odoo9.0
Imagine profil
Imagine profil
3
sept. 18
13179
Access One2many field from onchange in v9
many2one one2many v7 onchange v9
Imagine profil
0
iul. 16
4520
How to change a boolean field based on another field? (when a many2one is created) Rezolvat
project many2one one2many task onchange
Imagine profil
Imagine profil
Imagine profil
3
ian. 24
13449
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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