我有一个向导需要从模块中获取一些字段,但是当我尝试执行此操作时出现此错误:
AttributeError: "Field 'name' does not exist in object 'browse_record(wizard_set_ages, 1)'"
问题是我不知道如何从字段中获取数据。我需要遍历所有选定的记录并执行该操作(将名称写入大写锁定的描述中,例如名称:Atul -> set_description() -> 描述:ATUL)这是wizard.py代码:
from osv import osv, fields
class test_wizard(osv.osv_memory):
_name='wizard_set_ages'
_columns={}
def set_all_age(self, cr, uid, ids, context=None):
mystudents = self.pool.get('student.student')
for student in mystudents.browse(cr, uid, ids, context=context):
my_description = str(student.name).upper()
mystudents.write(cr, uid, student.id, {'notes' : my_description})
"""edit same for set_all_age def set_selected_age(self, cr, uid, ids, context=None):
for prod in self.browse(cr, uid, ids, context=context):
my_details = str(prod.name).upper()
self.write(cr, uid, prod.id, {'notes': my_details }) """
这是 student.py 文件:
from osv import osv, fields
class student_student(osv.osv):
_name = 'student.student'
_columns = {
'name' : fields.char('Student Name', size = 16, required = True, translate = True),
'age' : fields.integer('Age'),
'percentage' : fields.float('Percentage', help = 'This field will add average marks of the students out of 100'),
'gender' : fields.selection([('male', 'Male'), ('female', 'Female')], 'Gender'),
'active' : fields.boolean('Active'),
'notes' : fields.text('Details'),
}
_defaults = {
'name' : 'Atul',
'active' : True,
'age' : 13,
}
def set_age(self, cr, uid, ids, context=None):
for prod in self.browse(cr, uid, ids, context=context):
dict = self.read(cr, uid, ids, ['name'])
my_details = str(prod.name).upper()
self.write(cr, uid, prod.id, {'notes': my_details })
return True
student_student()
编辑:添加了wizard_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- create a view with a unique id -->
<record id="view_set_all_ages_wizard" model="ir.ui.view">
<field name="name">wizard_set_ages_form</field>
<field name="model">wizard_set_ages</field>
<field name="type">form</field>
<field name="arch" type="xml">
<!-- create a normal form view, with the fields you've created on your python file -->
<form string="Set All Student Ages" version="7.0">
<group >
<separator string="TEST" colspan="2"/>
<newline/>
</group>
<div style="text-align:right">
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="gtk-ok" name="set_all_age" string="Set All Details" type="object" />
<button icon="gtk-ok" name="set_selected_age" string="Set Only Selected Details" type="object" />
</div>
</form>
</field>
</record>
<!-- your action window refers to the view_id you've just created -->
<record id="action_set_all_ages" model="ir.actions.act_window">
<field name="name">Set All Ages</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">wizard_set_ages</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_set_all_ages_wizard"/>
<field name="target">new</field>
</record>
<act_window id="action_set_all_ages"
name="Set All Ages"
res_model="wizard_set_ages"
src_model="student.student"
view_mode="form"
target="new"
key2="client_action_multi"
/>
</data>
</openerp>