我努力创建名称onchange事件以匹配project_id
我的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()
我的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"/>
我总是得到AttributeError:&#39; notebook_project&#39;对象没有属性&#39; project_id&#39; ,任何帮助表示赞赏:D
答案 0 :(得分:1)
试试这个:
在xml中:
<field name="project_id" on_change="onchange_project_id(project_id)"/>
在py:
def onchange_project_id(self, cr, uid, ids, project_id, context=None):
if project_id:
prod = self.pool.get('project.project').browse(cr, uid, project_id, context=context)
return {'value': {'name': prod.name}}
return {'value':{}}
进行这些更改后,请更新模块并进行测试。它应该工作。