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

Modify ORM create method behavior two times using inheritance [Old API] [SOLVED]

Iscriviti

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

La domanda è stata contrassegnata
createormmethodoverride
1 Rispondi
6845 Visualizzazioni
Avatar
TEIMI Yassine

Dears,

I want to change the following create method behavior (The code part I want to change is in bold) :

class hr_evaluation_interview(osv.Model): 
_name = 'hr.evaluation.interview'
_inherit = 'mail.thread'
_rec_name = 'user_to_review_id'
_description = 'Appraisal Interview'
def create(self, cr, uid, vals, context=None):
    phase_obj = self.pool.get('hr_evaluation.plan.phase')
    survey_id = phase_obj.read(cr, uid, vals.get('phase_id'), fields=['survey_id'], context=context)['survey_id'][0]
    if vals.get('user_id'):
        user_obj = self.pool.get('res.users')
        partner_id = user_obj.read(cr, uid, vals.get('user_id'), fields=['partner_id'], context=context)['partner_id'][0]

    else:
        partner_id = None
    user_input_obj = self.pool.get('survey.user_input')
    if not vals.get('deadline'):
        vals['deadline'] = (datetime.now() + timedelta(days=28)).strftime(DF)
        ret = user_input_obj.create(cr, uid, {'survey_id': survey_id,
            'deadline': vals.get('deadline'),
            'type': 'link',
            'partner_id': partner_id}, context=context)
         vals['request_id'] = ret
    return super(hr_evaluation_interview, self).create(cr, uid, vals, context=context)

It's the hr_evaluation_interview create method, I want when the interview request is created, the partner_id field receive a different value than it receives now.

The partner_id receives the user_id (user related to the hr evaluator), I want it to be the evaluated employee (interviewd_id).

So I did the following using inheritance (changed code is in bold) :

class HrEvaluationInterview(osv.Model): 
_inherit = 'hr.evaluation.interview'
_columns = {
'interviewd_id': fields.many2one('hr.employee','Employee evaluated'),
}
def create(self, cr, uid, vals, context=None):
    phase_obj = self.pool.get('hr_evaluation.plan.phase')
    survey_id = phase_obj.read(cr, uid, vals.get('phase_id'), fields=['survey_id'], context=context)['survey_id'][0]
    employee_obj = self.pool.get('hr.employee')
    us_id = employee_obj.read(cr, uid, vals.get('interviewd_id'), fields=['user_id'], context=context)['user_id'][0]
    if vals.get('user_id'):
        user_obj = self.pool.get('res.users')
        partner_id = user_obj.read(cr, uid, us_id, fields=['partner_id'], context=context)['partner_id'][0]

    else:
        partner_id = None
        user_input_obj = self.pool.get('survey.user_input')
    if not vals.get('deadline'):
        vals['deadline'] = (datetime.now() + timedelta(days=28)).strftime(DF)
    ret = user_input_obj.create(cr, uid, {'survey_id': survey_id,
        'deadline': vals.get('deadline'),
        'type': 'link',
        'partner_id': partner_id}, context=context)
    vals['request_id'] = ret
    return super(HrEvaluationInterview, self).create(cr, uid, vals, context=context)

The problem is that the behavior didn't change, it keeps doing the same things did by the parent method. Maybe it's because the return I'm doing, can you advise me something ?

Thanks a lot.

0
Avatar
Abbandona
Avatar
Axel Mendoza
Risposta migliore

Hi @Yassine TEIMI

You need to bypass the super method in your return by changing this:

return super(HrEvaluationInterview, self).create(cr, uid, vals, context=context)

to this:

return osv.Model.create(self, cr, uid, vals, context=context)

This have the drawback that it will skip all the next create method overrides that could be executed by the super call but it will work

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

A better way to do the changes that you need is like:

class HrEvaluationInterview(osv.Model): 
_inherit = 'hr.evaluation.interview'
_columns = {
'interviewd_id': fields.many2one('hr.employee','Employee evaluated'),
}

def create(self, cr, uid, vals, context=None): 
us_id = self.pool.get('hr.employee').read(cr, uid, vals.get('interviewd_id'), fields=['user_id'], context=context)['user_id'][0]
vals['user_id'] = us_id
return super(HrEvaluationInterview, self).create(cr, uid, vals, context=context)

The approach is to change the vals['user_id'] so the code of original create method get another partner based on the changed user_id. With your old code you left the user_id in vals intact and that can lead to others errors, but if what you need to do is to have the same user_id but a different partner_id then left that as is. This is just another solution

1
Avatar
Abbandona
TEIMI Yassine
Autore

Indeed that's what I was looking for, the create method first override is now replaced correctly. it creates just one time not twice. Thanks. But, I still have a problem with partner_id field it doesn't get the correct value (the same as old one) I'm looking for why, because the main purpose of this override is to change the partner_id received value.

Axel Mendoza

Did you mean to change the partner_id passed to the create of the survey.user_input??

TEIMI Yassine
Autore

Yes, I've checked it, it works fine now, partner_id with the correct value. Thanks a lot Axel.

Axel Mendoza

Happy to help

TEIMI Yassine
Autore

Just a final question, it will work if I use self.create(cr, uid, vals, context) instead of osv.Model.create(self,cr,uid, vals, context) ?

Axel Mendoza

I think that it will not work, but you are free to try it

TEIMI Yassine
Autore

Okay, Thanks.

Axel Mendoza

I used before to call self.create and lead me to very rare behavior like recursive call to the same create method, but if that works for you, go ahead

Axel Mendoza

see the answer update for another approach

TEIMI Yassine
Autore

Yes, that's what i was thinking, the create method recursiveness, because you call the same method, and it gives an infinite calling loop. Thank you for the second appraoch, indeed, it's a better one, I'll test it. Cheers.

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à
Modify ORM create method behavior two times using inheritance [Old API]
create orm method override
Avatar
0
nov 15
13
Where can I find CRUD source code?
create method unlink override
Avatar
Avatar
1
gen 22
4532
How to override an overrided method Risolto
create method override if Odoo13
Avatar
Avatar
Avatar
Avatar
3
set 22
14964
Record does not exist or have been deleted
create method
Avatar
Avatar
1
gen 19
12116
one create method 2 separate models
create method
Avatar
Avatar
1
ott 17
4085
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