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

Onchange event to return activity name by searching activity code?

Iscriviti

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

La domanda è stata contrassegnata
pythonon_changeonchange
2 Risposte
5770 Visualizzazioni
Avatar
Suthan

Hi, I'm having some problem with my onchange method which is supposed to return the activity name once activity code is entered (it looks for the activity code and returns the activity name that matches the code )

im getting this error, AttributeError: 'NoneType' object has no attribute 'search'

Below is my code..please help

my xml form

 <record id="activitysummary_form" model="ir.ui.view">
          <field name="name">budget.activity_summary.form</field>
          <field name="model">budget.activity_summary</field>
         <field name="arch" type="xml">
               <form string="Activity Master Template" version="7.0">
                      <group col="4">
                               <field name="activity_summarycode" string="Activity Code" 
                                on_change="onchange_activity_name(activity_summarycode)"/>
                                 <field name="activity_name"/>
                          <field name="region_id"/>
                    </group>
               </form>
        </field>
    </record>

my class with the onchange method

class activity_summary(osv.osv):
   _name = "budget.activity_summary"
   _description = "Activity Summary"
   _rec_name = "activity_summarycode"
   _columns = {
      'activity_summarycode' : fields.many2one("budget.activity_year", "Activity Summary Code", on delete = "no action", required=True  ),   
      'activity_name' : fields.char("Activity Name" size = 128),
      'region_id' : fields.char("Region ID", size=64, required=True),
         }
    _sql_constraints = [
     ('activity_summarycode_unique', 'UNIQUE(activity_summarycode)', 'Each Activity year code is unique.'),
         ]

   def onchange_activity_name(self, cr, uid, ids, activity_summarycode, context = None):
    activity = self.pool.get('budget.activity_yearcode').search(cr, uid,[('activity_yearcode', '=', activity_summarycode)], 
      context=context)   

    if activity:
        activityname = self.pool.get('budget.activity_yearcode').browse(cr, uid, activity, context=context)
        return {'activity_name' : activityname.activity_name}
    return {'activity_name':{}}

the class im trying to search code and retrieve name

class activity_year(osv.osv):
  _name = "budget.activity_year"
  _description = "Activity year"
  _rec_name = "activity_yearcode"
  _columns = {
    'activity_yearcode' : fields.char("Activity Code", size=64, required=True),
    'activity_name' : fields.char("Activity Name", size=128),
    'act_status' : fields.selection([
                ('1', 'All'),
                ('2', 'Active'),
                ('3', 'Inactive'),
                ], 'Status'),
    }
  _sql_constraints = [
    ('activity_yearcode_unique', 'UNIQUE(activity_yearcode)', 'Each activity code is unique.'),
]
1
Avatar
Abbandona
Avatar
René Schuster
Risposta migliore

Small typo I guess:

activity = self.pool.get('budget.activity_yearcode').search(cr, uid,[('activity_yearcode', '=', activity_summarycode)], 
  context=context)

Your model is called 'budget.activity_year'.

self.pool.get('budget.activity_year')

Regards.

2
Avatar
Abbandona
Suthan
Autore

thank you!...that was the problem.

Avatar
Sudhir Arya (ERP Harbor Consulting Services)
Risposta migliore

Hi Suthan,

The error has appeared because you have given wrong object name while creating object in your code.

You have given self.pool.get('budget.activity_yearcode') but it must be self.pool.get('budget.activity_summary').

You should change the object name:

  1. activity = self.pool.get('budget.activity_summary').search(cr, uid,[('activity_yearcode', '=', activity_summarycode)],
  2. activityname = self.pool.get('budget.activity_summary').browse(cr, uid, activity, context=context)
3
Avatar
Abbandona
Suthan
Autore

hi, i fixed it, as you said i changed the object name, but the field values i was trying the get was from the budget.activity_year model. anyway thank you, i appreciate your help.

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à
onchage function
python onchange
Avatar
Avatar
1
feb 22
3346
How does api.onchange works while create a record from trigger
on_change onchange compute
Avatar
Avatar
1
mag 24
3595
method onchange couldn't be defined by openerp
python onchange openerp7
Avatar
0
ago 15
4425
How can we trigger act_window action from on_change function?
action python onchange
Avatar
Avatar
1
mar 15
5735
Is it possible to capture both original and new values in an on_change method?
views on_change onchange
Avatar
Avatar
1
mar 15
10566
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