【发布时间】:2014-12-30 14:17:31
【问题描述】:
请问我在使用新的 odoo 8 api 时遇到了一些问题,我有以下课程
class TypeProcessus(models.Model):
_name = 'atom.promaintenance.type.processus'
name = fields.Char()
id_phases = fields.One2many('atom.promaintenance.phases','id_processus','Liste des Phases')
class Phases(models.Model):
_name = 'atom.promaintenance.phases'
name = fields.Char()
autoriserCommentaire = fields.Boolean()
autoriserPiecesJointes = fields.Boolean()
id_processus = fields.Many2one('atom.promaintenance.type.processus')
parent_id = fields.Many2one('atom.promaintenance.phases','Phase Parent', select=True, ondelete='cascade')
commentaire = fields.Text()
@api.one
@api.onchange('name')
def phases_write(self):
print 'test'
<record model="ir.ui.view" id="atom_promaintenance_type_processus">
<field name="name">atom.promaintenance.type.processus.form</field>
<field name="model">atom.promaintenance.type.processus</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Type Processus" >
<sheet>
<h1>UPDATED</h1>
<field name="name" />
<tree string="note_evaluation_tree" editable="bottom">
<field name="id_phases" />
</tree>
</sheet>
</form>
</field>
</record>
首先我的问题是当创建一个新的进程并添加阶段时,阶段之间存在父子关系,并且父级的下拉列表保持为空,除非您保存进程以使其可用。
我设法将 onChange 事件添加到阶段以将它们保存到数据库中,但我不知道如何使用新的 api 系统保存这些记录,谢谢
【问题讨论】:
-
不能使用onchange方法保存记录。我真的不明白你想在这里做什么。如果您想更改记录的保存/创建方式,您必须覆盖
create和/或write方法,或者如果您需要创建/更新一些相关记录,请在您的方法中调用它们。 -
我找不到你的问题,onChange() 和 store 记录有什么关系?所以你告诉你真正的问题是什么