Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

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

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

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

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
many2oneone2manyonchangebinaryfiles
4 Replies
7336 Tampilan
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
Buang
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)
Penulis

@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)
Penulis Jawaban Terbai

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
Buang
Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
How to give Domain filter for one2many field base on the condition of another field? (Odoo 13) Diselesaikan
many2one one2many onchange domain_filter
Avatar
Avatar
2
Jul 22
12750
odoo onchange function on one2many field Diselesaikan
function fields many2one one2many onchange
Avatar
Avatar
Avatar
Avatar
3
Okt 22
22360
How To Pass Value on Onchange of Many2one field in One2many Diselesaikan
many2one one2many onchange one2many_list odoo9.0
Avatar
Avatar
3
Sep 18
13180
Access One2many field from onchange in v9
many2one one2many v7 onchange v9
Avatar
0
Jul 16
4520
How to change a boolean field based on another field? (when a many2one is created) Diselesaikan
project many2one one2many task onchange
Avatar
Avatar
Avatar
3
Jan 24
13450
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة 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 adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

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