我有一個嚮導,需要從模塊中獲取一些字段,但是當我嘗試執行此操作時出來這個錯誤:Openerp 7:AttributeError:「Field'name'在對象'browse_record(wizard_set_ages,1)'中不存在''
AttributeError: "Field 'name' does not exist in object 'browse_record(wizard_set_ages, 1)'"
問題是,我不知道如何把數據形式的領域。我需要遍歷所有選定的記錄並執行該操作(將名稱寫入大寫鎖定的描述中,如名稱:Atul - > set_description() - > 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>
把你的XML代碼也在這裏 – senthilnathang
在嚮導添加self.write(CR,UID,prod.id,{ '註釋':my_details}),但有在嚮導中沒有字段(wizard_set_ages),你需要使用myobj.write(cr,uid,prod.id,{'notes':my_details})而不是那個 – senthilnathang
添加嚮導xml文件 – barbaanto