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

compute field not working properly

Iscriviti

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

La domanda è stata contrassegnata
pythonmodelcomputetechnical
2 Risposte
5239 Visualizzazioni
Avatar
Sagar Shah

Hi have a Image field setup for compute, and it depends on 2 fields, however I noticed when one of the 2 fields is edited it triggers compute but doesn't pass the value of other field properly and hence the compute logic fails, wanted to know if this is a known issue?


from odoo import api, models, fields
from PIL import Image
import io
import base64
import qrcode
import lnurl

class custom_info(models.Model):

_inherit = 'hr.employee'
employee_ln_address = fields.Char(string="Employee lightning address : ", required=False)
employee_ln_qr_image = fields.Image(compute="_compute_ln_qr_image",string="Employee lightning QR code")


@api.depends('image_1920','employee_ln_address')
def _compute_ln_qr_image(self):
    ​for record in self:
        record.employee_ln_qr_image=False
        if record.image_1920:
            logo = Image.open(io.BytesIO(base64.b64decode(record.image_1920)))
            basewidth = 200
            wpercent = (basewidth/float(logo.size[0]))
            hsize = int((float(logo.size[1])*float(wpercent)))
            logo = logo.resize((basewidth, hsize), Image.ANTIALIAS)
            QRcode =qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H)
            if record.employee_ln_address:
                lnusr,lndomain = record.employee_ln_address.split('@')
                qrmessage = 'lightning:'+lnurl.encode('https://'+lndomain+'/.well-known/lnurlp/'+lnusr)
                QRcode.add_data(qrmessage)
                QRcode.make()
                QRcolor = 'Black'
                QRimg = QRcode.make_image(fill_color=QRcolor, back_color="white").convert('RGB')# adding color to QR code
                pos = ((QRimg.size[0] - logo.size[0]) // 2,(QRimg.size[1] - logo.size[1]) // 2)
                QRimg.paste(logo, pos)
                QRinMem = io.BytesIO()
                QRimg.save(QRinMem,"JPEG")
                QRinMem.seek(0)
                  record.employee_ln_qr_image=base64.b64encode(QRinMem.read())

0
Avatar
Abbandona
Ray Carnes (ray)

I would post the code for "logic for compute" to give people more clues.

Sagar Shah
Autore

have updated the full code for compute now

Avatar
Jort de Vreeze
Risposta migliore

I have done something similar for a project where I created QR codes to be printed by a label printer. What worked for me was the following:

Change the field from field.Image(compute='_compute_ln_qr_image')​ to field.Binary(compute='_compute_ln_qr_image')​

The remainder of your code is similar like for my project code. Try to add logging (e.g., _logger.info(Image Size:{QRimg.size}')​ so you can check whether the QR code generated is a valid image.

In your view you should use the image widget:

[field name="employee_ln_qr_image" widget="image" readonly="True"/]

I hope this helps!

0
Avatar
Abbandona
Sagar Shah
Autore

Thanks tried it but didn't work. The problem is one of the fields that the QR field depends on is a image field, I'm trying to embed the employee Avatar in the QR code, and that seems to be the problem. If I edit the Avatar and it trigger compute it works fine, but if I edit the other field on which the compute is dependent it tirggers compute method but for some reason doesn't pass the value of the other image field that it depends on

Avatar
shubham shiroya
Risposta migliore

try this way:

you can use the @api.onchange decorator instead of @api.depends to trigger the compute method when the employee_ln_address field is modified. The @api.onchange decorator ensures that the compute method receives the correct value of the modified field.

@api.onchange('employee_ln_address')
def _onchange_employee_ln_address(self):
for record in self:
record.employee_ln_qr_image = False
if record.image_1920:
# Your compute logic goes here
# ...

By using the @api.onchange decorator, the _onchange_employee_ln_address method will be triggered whenever the employee_ln_address field is modified, ensuring that the compute logic receives the correct value.

Make sure to remove the @api.depends decorator from the _compute_ln_qr_image method.

0
Avatar
Abbandona
Sagar Shah
Autore

Thanks, i tried onchange as well but same behavior, I am not sure but something specific to image fields, other fields i don't see any issue

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 get a person's age from his date of birth in Odoo? Risolto
python compute
Avatar
Avatar
Avatar
2
mag 20
6844
What is active_id? Risolto
python technical
Avatar
Avatar
Avatar
2
gen 24
13817
Loading a Model Object with data loaded from an API
python model
Avatar
Avatar
1
mar 15
8994
v16: why Odoo raise this error - compute to get Length Risolto
model compute odoo16features
Avatar
Avatar
2
ott 23
4604
How product lines comes in sale order lines when you validate a delivery order directly from delivery?
python technical v14
Avatar
0
mag 21
2107
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