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

Attribute error in onchange method

Iscriviti

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

La domanda è stata contrassegnata
functionpythonfieldonchange
2 Risposte
8875 Visualizzazioni
Avatar
Suthan

Hi,

I have a class with an onchange method which retrieves the activity name from another model. when I run it, im getting an error like this.

AttributeError: 'Field activity_name not found in browse_record(budget.activity_year, 16)'

Can anyone tell why this is happening and how may i fix it?

My class with onchange method

class wpb(osv.osv):
_name = "wpb.wpb"
_description = "Work Program and Budget"
_columns = {
    'activity_id' : fields.many2one("budget.activity_summary", "ID", type="char", size=64, ondelete="no action"),
    'activity_name' : fields.char("Activity Name", type="char", size=64, ondelete="no action" ),
    'region_id' : fields.related("activity_code", "region_id", type="char", string="Management Unit"),
    'service_lvl' : fields.float("Service Level", digits=(4,2)),
    'annual_work' : fields.float("Annual Work", digits=(4,2)),
       }

def onchange_activity_code(self, cr, uid, ids, activity_id, context = None):
    if activity_id:
         names = self.pool.get('budget.activity_year').browse(cr, uid, activity_id, context=context)
    return {'value': {'activity_name': names.activity_name }}
    return {'value':{}}

The xml view

 <record id="wpb_form" model="ir.ui.view">
        <field name="name">wpb.wpb.form</field>
        <field name="model">wpb.wpb</field>
        <field name="arch" type="xml">
            <form string="Work Program and Budget" version="7.0">
                <group col="2">
                    <field name="activity_id" on_change="onchange_activity_code(activity_id)"/>
                    <field name="activity_name"/>
                    <field name="region_id" readonly="1"/>
                    <field name="service_lvl"/>
                    <field name="annual_work"/>
                </group>
            </form>
        </field>
    </record>


<record id="wpb_view" model="ir.ui.view">
        <field name="name">wpb.wpb.view</field>
        <field name="model">wpb.wpb</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree string="Work Program and Budget" editable="top">
                <field name="activity_id" on_change="onchange_activity_code(activity_id)"/>
                <field name="activity_name"/>
                <field name="region_id" readonly="1"/>
                <field name="annual_work"/>
            </tree>
        </field>
    </record>

The class im trying to get the activity name field

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.'),
]
0
Avatar
Abbandona
Avatar
Jagdish Panchal
Risposta migliore

Hi,

Try this code

'activity_id' : fields.many2one("budget.activity_year", "ID", type="char", size=64, ondelete="no action"),

def onchange_activity_code(self, cr, uid, ids, activity_id, context = None):
    if activity_id:
         names = self.pool.get('budget.activity_year').browse(cr, uid, activity_id, context=context)
         return {'value': {'activity_name': names.activity_name }}
    return {'value':{}}
0
Avatar
Abbandona
Suthan
Autore

i tried..im getting this error : AttributeError: 'int' object has no attribute 'id'

Jagdish Panchal

I have update answer Pls check it.

OpenERP Vietnam

object "budget.activity_year" and object "wpb.wpb" is different. Can you post definition of object "budget.activity_year" in here?

Jagdish Panchal

@ OpenERP Vietnam : Means ? I didn't get you

Suthan
Autore

@jack, the answer seems the same. what changes did you make?

OpenERP Vietnam

names = self.pool.get('budget.activity_year').browse(cr, uid, activity_id, context=context) return {'value': {'activity_name': names.activity_name }} in here, you get column activity_name of object "budget.activity_year". Maybe, this object "budget.activity_year" have no column activity_name

Jagdish Panchal

@ Suthan: i have change your many2one field and also return {'value': {'activity_name': names.activity_name }} this line under if condition. This two changes i have done check it.

Suthan
Autore

@ OpenERP Vietnam, it has that column (activity_name), you can see it in my post.

Jagdish Panchal

ok got it and update answer

Suthan
Autore

jack, i can't change my many2one field to budget.activity_year, it has to be related to budget.activity_summary, that's the problem im having.

Jagdish Panchal

You have define ;budget.activity_year' this object and in this object there is field name 'activity_name' ? You try to browse data form 'budget.activity_year' this object but you dont have relation with this object.

Jagdish Panchal

You have define ;budget.activity_year' this object and in this object there is field name 'activity_name' ? You try to browse data form 'budget.activity_year' this object but you dont have relation with this object.

Suthan
Autore

I can change the relationship to budget.activity_year, it works, but i want the get activity_id from activity_summary object, because activity_summary object has other fields that i want to retrieve as well, only the activity_name, i want to get from activity_year. thats the issue. Is there a way to retrieve the activity name in budget.activity_year without changing the 'activity_id's many2one relation?

Jagdish Panchal

Add new many2one field relation with budget.activity_year

Suthan
Autore

@jack, yes..that works after adding new field. Thank you so much for all the help. appreciate it!

Jagdish Panchal

Ok then wht the answer

Avatar
Prakash
Risposta migliore

Try the below code:-

def onchange_activity_code(self, cr, uid, ids, activity_id, context = None):
    v = {}
    if activity_id:
         for val in self.pool.get('budget.activity_year').browse(cr, uid, activity_id, context=context)
            v['activity_name'] = val.activity_name 
    return {'value': v}

If activity_id in list then use for loop otherwise without for loop directly access table with browse method.

0
Avatar
Abbandona
Suthan
Autore

it doesn't work,i'm getting this error : NotImplementedError: Iteration is not allowed on browse_record(budget.activity_year, 16) @ prakash

Prakash

@Suthan: In your code using budget.activity_summary table ID retrieve budget.activity_year table column value so logically wrong If you want budget.activity_year table column value then pass the budget.activity_year table ID

Suthan
Autore

@prakash, yes, i just learned about that. Thank you so much.

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
3353
How to get current user name into field ?(Problem Solved) Risolto
function python onchange odoo odoov10
Avatar
Avatar
Avatar
10
giu 20
26756
Function Onchange Odoo Community Version 12
function python urgent onchange odooV12
Avatar
0
apr 19
4402
How to set automatically a value field from another field
field onchange
Avatar
Avatar
1
mar 19
5811
Can you check a code of my module : filed. function
function field
Avatar
Avatar
2
mar 15
5352
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