Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Onchange name event Attribute Error

By
Nanda Kanoko
on 7/16/13, 7:46 AM 2,195 views

I'm struggling to make name onchange event to match the project_id

My py :

class notebook_project(osv.osv):
    _name = "notebook.project"
    _description = "Notebook Project ID"
    _columns = {
        'name' : fields.char('Name', size=64),
        'project_id' : fields.many2one('project.project', 'Project'),
        'notebook_project_lines' : fields.one2many('notebook.project', 'notebook_project_id', 'Members Lines'),
        'notebook_project_id': fields.many2one('notebook.project', ondelete='cascade', select=True),
        'project_member' : fields.many2one('hr.employee', 'Members'),

        }

def onchange_project_id(self, cr, uid, ids, project_id, name, context=None):

    if project_id:
        prod = self.pool.get('project.project').browse(cr, uid, project_id, context=context)
        return {'value': {'name': prod.name}}
    return {}

notebook_project()

My XML

<record model="ir.ui.view" id="notebook_project_tree_view">
<field name="name">notebook.project.tree</field>
<field name="model">notebook.project</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Project">
<field name="name"/> 
<field name="notebook_project_lines"/>
</tree>
</field>
</record>

<record model="ir.ui.view" id="notebook_project_form_view">
<field name="name">notebook.project.form</field>
<field name="model">notebook.project</field>
<field name="type">form</field>
<field name="arch" type="xml">

<form string="Notebook Project"> 
<field name="project_id" on_change="project_id(project_id, name, context)"/>
<field name="name"/>

I always get AttributeError: 'notebook_project' object has no attribute 'project_id' , any help appreciated :D

0
ainur rofiq
On 7/16/13, 1:26 PM

The error message is very clear. Please check again, your method between class definition and xml is not match . It should be <field name="project_id" on_change="onchange_project_id(project_id, name, context)"/>

Thanks for reply , i've tried it but still got an attribute error ...

Nanda Kanoko
on 7/16/13, 11:17 PM

have you re-start openerp server after update your code?

KAM, ainur rofiq
on 7/17/13, 1:35 AM

of course ...

Nanda Kanoko
on 7/17/13, 3:04 AM

kok aneh ya mas bro...

KAM, ainur rofiq
on 7/17/13, 5:07 AM

udah kelar kok bro , ternyata masalah tab function aja kok . Thanks bantuannya :D

Nanda Kanoko
on 7/17/13, 5:09 AM

mas bro tolong dibantu : http://help.openerp.com/question/24804/how-to-import-one2many-field-record-from-one-model-to-one2many-field-in-another-model/

Nanda Kanoko
on 7/17/13, 6:20 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 7/16/13, 7:46 AM
Seen: 2195 times
Last updated: 3/16/15, 8:10 AM