我有一个按钮,我想使用create方法更新几个字段的值。 您想帮助我创建此功能吗? 此刻,当我单击按钮时,它将替换我的记录,并创建另一个具有空值的记录。为什么?谢谢 这不是一个真正的向导!
class StudentWizard(models.Model):
_name = 'student.wizard'
def _get_default_students(self):
return self.env['ecole.partner.school'].browse(self.env.context.get('active_ids'))
student_ids = fields.Many2many('ecole.partner.school', String="Student", default=_get_default_students)
school_name = fields.Many2one(comodel_name="horanet.school.establishment",
string="Etablissement Scolaire",
required=True)
school_year = fields.Many2one(string='Période',
ondelete='SET NULL',
comodel_name="ecole.partner.school.years",
required=True)
school_level = fields.Many2one(comodel_name="horanet.school.grade",
string="Niveau Scolaire",
required=True)
#level = fields.Char('Level')
api.multi
def set_student_level(self):
for record in self:
if record.student_ids:
for student in record.student_ids:
update_student = self.env['ecole.partner.school']
# partner_id = update_student.partner_id
# school_year = update_student.school_year
# school_name = update_student.school_name
# half_pension = update_student.half_pension
# nursery = update_student.nursery
student.school_year = update_student.school_year
student.school_level = update_student.school_level
#student.school_name = update_student.school_name
vals = {'school_year': student.school_year, 'school_level': student.school_level}
res = update_student.create(vals)
return res
我的XML:
<record id="student_wizard_view" model="ir.ui.view">
<field name="name">student Marks Views</field>
<field name="model">student.wizard</field>
<field name="arch" type="xml">
<form>
<group>
<field name="student_ids" widget="many2many_list"/>
<field name="school_name"/>
<field name="school_year"/>
<field name="school_level"/>
</group>
<footer>
<button name="set_student_level" string="Passage au niveau suivant" class="oe_right oe_highlight"
type="object"/>
<button string="Cancel" class="oe_right" special="cancel"/>
</footer>
</form>
</field>
</record>
我的结果: My records are empty and erase the field values of the selected record