我有三个模型。
class student(models.Model):
_name = 'student.info'
_description = 'Students\' Information'
name = fields.Char('Name', required=True)
age = fields.Integer('Age', compute='_compute_age', store=True)
date_of_birth = fields.Date('Date of Birth', required=True)
teacher_id = fields.Many2one('teacher.info', 'Teacher')
class teacher(models.Model):
_name = 'teacher.info'
_description = 'Teachers\' Information'
name = fields.Char('Name', required=True)
position = fields.Char('Position')
section_id = fields.Many2one('stu.section', 'Section')
student_ids = fields.Many2many('student.info', 'student_teacher_rel', 'teacher_id', 'student_id', 'Students')
class section(models.Model):
_name = 'stu.section'
_description = 'Students\' Sections'
name = fields.Char('Name', required=True)
student_ids = fields.Many2many('student.info', 'student_section_rel', 'section_id', 'student_id')
两个动作,
<record id="action_student_to_class" model="ir.actions.act_window">
<field name="name">Class</field>
<field name="res_model">stu.section</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="context">{'default_student_ids' : [(4, active_id)]}</field>
</record>
<record id="action_class_to_teacher" model="ir.actions.act_window">
<field name="name">Class</field>
<field name="res_model">teacher.info</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="context">{
'default_student_ids' : active_id.student_ids,
'default_section_id' : active_id,
}</field>
</record>
和两个按钮。一个在学生表单视图中,另一个在分区表单视图中。
<button name="%(action_student_to_class)d"
type="action"
string="To Class"
class="oe_highlight"/>
<button name="%(action_student_to_class)d"
type="action"
string="To Class"
class="oe_highlight"/>
当从学生表单中单击“上课”按钮时,该操作将在student_ids部分中更新当前学生。但是,当从部分表格中单击“ To Teacher”按钮时,我想更新教师表格中该部分的当前部分和student_id。我是通过从python返回操作来完成此操作的,但是我想从xml执行此操作?我该如何实现?谢谢。
我已经找到解决方法。
如果我们不为按钮添加实际操作,这没关系。我们可以在[]等按钮中添加上下文
<button name="%(action_student_to_class)d"
type="action"
string="To Class"
class="oe_highlight"
context="{'default_student_ids' : student_ids, 'default_section_id' : active_id}"/>