【问题标题】:ODOO 8 on_changeODOO 8 on_change
【发布时间】: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 记录有什么关系?所以你告诉你真正的问题是什么

标签: onchange odoo


【解决方案1】:

新 API 使用 self 进行所有记录修改。所以在你的情况下,如果你想改变name,这样写:

@api.one
@api.onchange('name')
def onchange_name(self):
    self.name = 'what you want to save'

【讨论】:

    【解决方案2】:

    如果你的意思是我理解的,你需要在 XML 代码中使用小部件 one2many_list,顺便说一下,我认为这是错误的。应该是这样的:

    <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" />
                    <field name="id_phases" widget="one2many_list">
                        <tree string="note_evaluation_tree" editable="bottom">
                            <field name="name"/>
                            <field name="autoriserCommentaire"/>
                            <field name="autoriserPiecesJointes"/>
                            <field name="parent_id"/>
                            <field name="commentaire"/>
                        </tree>
                    </field>
                </sheet>
            </form>
        </field>
    </record>
    

    该小部件将允许您为进程添加阶段然后保存它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多