Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

Attribute error in onchange method

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
functionpythonfieldonchange
2 Răspunsuri
8873 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Imagine profil
Jagdish Panchal
Cel mai bun răspuns

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
Imagine profil
Abandonează
Suthan
Autor

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
Autor

@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
Autor

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

Jagdish Panchal

ok got it and update answer

Suthan
Autor

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
Autor

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
Autor

@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

Imagine profil
Prakash
Cel mai bun răspuns

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
Imagine profil
Abandonează
Suthan
Autor

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
Autor

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

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
onchage function
python onchange
Imagine profil
Imagine profil
1
feb. 22
3350
How to get current user name into field ?(Problem Solved) Rezolvat
function python onchange odoo odoov10
Imagine profil
Imagine profil
Imagine profil
10
iun. 20
26756
Function Onchange Odoo Community Version 12
function python urgent onchange odooV12
Imagine profil
0
apr. 19
4401
How to set automatically a value field from another field
field onchange
Imagine profil
Imagine profil
1
mar. 19
5811
Can you check a code of my module : filed. function
function field
Imagine profil
Imagine profil
2
mar. 15
5348
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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