Siirry sisältöön
Odoo Menu
  • Kirjaudu sisään
  • Kokeile ilmaiseksi
  • Sovellukset
    Talous
    • Kirjanpito
    • Laskutus
    • Kulut
    • Datataulukot (BI)
    • Asiakirjat
    • Allekirjoita
    Myynti
    • CRM
    • Myynti
    • Kassajärjestelmä myymälään
    • Kassajärjestelmä ravintolaan
    • Tilaukset
    • Vuokraus
    Verkkosivut
    • Verkkosivun Rakennustyökalu
    • Verkkokauppa
    • Blogi
    • Foorumi
    • Livechat
    • Verkko-oppiminen
    Toimitusketju
    • Varastointi
    • Tuotanto
    • Tuotteen elinkaaren hallinta (PLM)
    • Ostot
    • Huolto
    • Laatu
    Henkilöstöhallinto
    • Työntekijät
    • Rekrytointi
    • Vapaat
    • Arvioinnit
    • Suositukset
    • Kuljetuskalusto
    Markkinointi
    • Somemarkkinointi
    • Sähköpostimarkkinointi
    • Tekstiviestimarkkinointi
    • Tapahtumat
    • Markkinoinnin automaatio
    • Kyselyt
    Palvelut
    • Projekti
    • Työaikakirjaukset
    • Kenttähuolto
    • Asiakaspalvelu
    • Suunnittelu
    • Ajanvaraukset
    Tuottavuus
    • Viestintä
    • Hyväksynnät
    • IoT
    • IP-puhe
    • Tietokirjasto
    • WhatsApp
    Kolmannen osapuolen sovellukset Odoo-Studio Odoo-Pilvialusta
  • Toimialat
    Vähittäiskauppa
    • Kirjakauppa
    • Vaatekauppa
    • Huonekaluliike
    • Ruokakauppa
    • Laitteistokauppa
    • Lelukauppa
    Ruoka & Majoitus
    • Baari ja Pubi
    • Ravintola
    • Pikaruoka
    • Majatalo
    • Juomien jakelija
    • Hotelli
    Kiinteistöt
    • Kiinteistönvälitystoimisto
    • Arkkitehtitoimisto
    • Rakentaminen
    • Kiinteistönhallinta
    • Puutarhanhoito
    • Kiinteistön omistajien yhdistys
    Konsultointi
    • Tilitoimisto
    • Odoo-kumppani
    • Markkinointitoimisto
    • Lakitoimisto
    • Osaajahankinta
    • Tilintarkastus & sertifiointi
    Tuotanto
    • Tekstiili
    • Metalli
    • Huonekalut
    • Ruoka
    • Panimo
    • Yrityslahjat
    Terveys & Liikunta
    • Urheiluseura
    • Silmälasiliike
    • Kuntokeskus
    • Hyvinvointialan ammattilaiset
    • Apteekki
    • Kampaamo
    Kaupat
    • Yleismies
    • IT-laitteisto & Tuki
    • Aurinkoenergiajärjestelmät
    • Suutari
    • Siivouspalvelut
    • LVI-palvelut
    Muut
    • Voittoa tavoittelematon järjestö
    • Ympäristötoimisto
    • Mainostaulujen vuokraus  
    • Valokuvaus
    • Leasing-pyörät
    • Ohjelmistojen jälleenmyyjä
    Selaa kaikkia toimialoja
  • Yhteisö
    Opi
    • Kurssit
    • Dokumentaatio
    • Todistukset
    • Koulutus
    • Blogi
    • Podcast
    Kannusta kouluttautumaan
    • Koulutusohjelmat
    • Scale Up! Liiketoimintapeli
    • Vieraile Odoolla
    Hanki ohjelmisto
    • Lataa
    • Vertaile versioita
    • Julkaisut
    Tee yhteistyötä
    • Github
    • Foorumi
    • Tapahtumat
    • Käännökset
    • Ryhdy kumppaniksi
    • Kumppanipalvelut
    • Rekisteröi tilitoimistosi
    Hanki palveluja
    • Löydä kumppani
    • Löydä kirjanpitäjä
    • Varaa asiantuntijatapaaminen
    • Implementaatiopalvelut
    • Asiakasreferenssit
    • Tuki
    • Versionkorotukset
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Varaa demo
  • Hinnoittelu
  • Asiakaspalvelu

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

  • CRM
  • e-Commerce
  • Kirjanpito
  • Varastointi
  • PoS
  • Projekti
  • MRP
All apps
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Apua

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

Tilaa

Saat ilmoituksen, kun tähän viestiin ilmaantuu aktiviteettia

Tämä kysymys on merkitty
createormmethodoverride
1 Vastaa
6854 Näkymät
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
Hylkää
Avatar
Axel Mendoza
Paras vastaus

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
Hylkää
TEIMI Yassine
Tekijä

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
Tekijä

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
Tekijä

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
Tekijä

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
Tekijä

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.

Nautitko keskustelusta? Älä vain lue, vaan osallistu!

Luo tili jo tänään nauttiaksesi yksinoikeusominaisuuksista ja osallistuaksesi mahtavaan yhteisöömme!

Rekisteröidy
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
Modify ORM create method behavior two times using inheritance [Old API]
create orm method override
Avatar
0
marrask. 15
13
Where can I find CRUD source code?
create method unlink override
Avatar
Avatar
1
tammik. 22
4535
How to override an overrided method Ratkaistu
create method override if Odoo13
Avatar
Avatar
Avatar
Avatar
3
syysk. 22
14971
Record does not exist or have been deleted
create method
Avatar
Avatar
1
tammik. 19
12117
one create method 2 separate models
create method
Avatar
Avatar
1
lokak. 17
4089
Yhteisö
  • Kurssit
  • Dokumentaatio
  • Foorumi
Avoin lähdekoodi
  • Lataa
  • Github
  • Runbot
  • Käännökset
Palvelut
  • Odoo.sh hosting
  • Tuki
  • Versionkorotus
  • Räätälöidyt kehitykset
  • Koulutus
  • Löydä kirjanpitäjä
  • Löydä kumppani
  • Ryhdy kumppaniksi
Meistä
  • Yrityksemme
  • Tavaramerkki
  • Ota yhteyttä
  • Työpaikat
  • Tapahtumat
  • Podcast
  • Blogi
  • Asiakkaat
  • Oikeudellinen ilmoitus • Yksityisyys
  • Tietoturva
الْعَرَبيّة 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 on kokoelma avoimen lähdekoodin yrityssovelluksia, jotka kattavat kaikki yrityksesi tarpeet: asiakkuudenhallinta eli CRM, verkkokauppa, kirjanpito, varastointi, kassajärjestelmä, projektinhallinta, jne.

Odoon uniikki arvolupaus on olla samanaikaisesti erittäin helppokäyttöinen ja täysin integroitu.

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