Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

How to load an PIL.Image element in a Binary field?

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
deniedpermissionsbinary
1 Atsakyti
3000 Rodiniai
Portretas
Gaston Carrera

Hello!, 


 I have a binary fields and i need to fill it with a Image previously edited with PIL library, so for that i override default_get() function, 



    mapa=fields.Binary('')


    @api.model

    def default_get(self, fields):


        resul = super(ModelMap, self).default_get(fields)

​

    ​filepath='/odoo/odoo-server/addons/my_module/static/src/img/'

    ​mapa = Image.open(filepath+'Map_odoo.png').convert('RGB')

​

​**here i process mapa object**

until here its all ok, ​but now i try first:


    ​mapa.save(filepath+'Mapa_odoo_temp.png')

        resul['mapa']=filepath+'Mapa_odoo_temp.png'

​but doesnt work, raise a "Permission denied" because i cannot create that file , not in the module path and in any other path either, and idk how solve this...

​
​fo that i try another way, ​

​map2=open(filepath+"Mapa_odoo_temp.png", "wb")

    ​map2.write(base64.decodebytes(mapa))

    ​map2.close()

        resul['mapa']=filepath+'Mapa_odoo_temp.png'


​​but doesnt work too


​so finally try giving the image directly  

        resul['mapa']=mapa

​ 

​but this dont crash but dont display the image "the image cannot be loaded" or something similar.


 Could somebody tell me how i could do? so thanks.

 

0
Portretas
Atmesti
Portretas
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,


To fill a binary field with an image processed using the PIL library in Odoo, you need to convert the image to a base64 encoded string and then assign it to the binary field.


Here's how you can modify your default_get function:


from PIL import Image

import base64

from io import BytesIO

from odoo import api, fields, models



class ModelMap(models.Model):

    _name = 'model.map'

    mapa = fields.Binary('Map Image')

    @api.model

    def default_get(self, fields):

        resul = super(ModelMap, self).default_get(fields)

        filepath = '/odoo/odoo-server/addons/my_module/static/src/img/'

        with Image.open(filepath + 'Map_odoo.png').convert('RGB') as mapa:

            mapa = mapa.resize((100, 100))

            buffer = BytesIO()

            mapa.save(buffer, format='PNG')

            image_base64 = base64.b64encode(buffer.getvalue()).decode('utf-8')

            resul['mapa'] = image_base64

        return result


Hope it helps

1
Portretas
Atmesti
Gaston Carrera
Autorius

Yes! its perfect, so thanks. its solved.

Gaston Carrera
Autorius

Sorry i need to ask again, because this work, but dont apply the changes when i do "mapa.save(buffer, format='PNG')"... you know what can be?

Gaston Carrera
Autorius

add info: if i apply a "resize((64,64))" after all yes this make effect, but for some reason dont read good the ImageDraw chages (apply lines) and some changes pixel-by-pixel that i made in the image in array mode.
Important to say that all this proces work fine when i do out of odoo, in a python script directly

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

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

Registracija
Related Posts Replies Rodiniai Veikla
[Errno 13] Permission denied
denied permissions v14
Portretas
Portretas
1
spal. 22
6777
how can i give anonymous user as a group some permission in odoo? Solved
permissions
Portretas
Portretas
Portretas
2
kov. 25
6571
when I install Odoo 12 ...this error occur when i create or delete database.
denied
Portretas
0
saus. 22
6020
How to allow only admin to create countries and states in sales/customer module?
permissions
Portretas
0
liep. 21
3224
Download binary files with original format Solved
binary
Portretas
Portretas
2
gruod. 23
26168
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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