【问题标题】:Insert list register with onchange (Odoo)使用 onchange 插入列表寄存器(Odoo)
【发布时间】:2016-11-08 15:56:16
【问题描述】:
class base(models.Model):
    _name = 'base'

    name = fields.Char("Name")
    c_id = fields.Many2one('base.ch')

class base_ch(models.Model):
    _name = 'base.ch'

    name = fields.Char("Name")
    q_ids = fields.One2many("base.q","c_id")


class base_q(models.Model):
    _name = "base.q"

    name = fields.Char("Name")
    c_id = fields.Many2one('base.ch',"Basec")


class base_h(models.Model):
    _name = "base.h"

    name = fields.Char("Name")
    select = fields.Selection([('a', 'A'), ('b', 'B')], "select")
    desc = fields.Char("Desc")

我有这些类,我想在基类中添加树视图格式的 base_h 类的字段。
I need to do an onchange function in the base class that when choosing c_id modify the name field of the added field of the base_h class with the records of c_id.q_ids

我试过了:

@api.onchange('ch_id')
def onchange_ch(self):
    if self.ch_id.q_ids:
        self.one2manyfield.name = [(6, 0, self.ch_id.q_ids)]
        #also with-> self.one2manyfield = [(6, 0, self.ch_id.q_ids)]

但它不起作用

【问题讨论】:

  • 基于 One2many 字段创建 base_h 和 onchange 我尝试了两件事。 1.- (self.one2many_field = self.c_id.q_ids) 和 2.- (self.one2many_field = [(6,0, self.c_id.q_ids)] )

标签: openerp onchange odoo-8


【解决方案1】:

(6, 0, [IDs]) 将获取 id 列表。

试试下面的代码。

@api.onchange('ch_id')
def onchange_ch(self):
    if self.ch_id and self.ch_id.q_ids:
        one2manyfield = [(6, 0, self.cht_id.q_ids.ids)]

【讨论】:

    【解决方案2】:

    这是有效的功能

    @api.onchange('ch_id')
    def onch_ch(self):
        valors = []
        for r in self.ch_id.q_ids:
            register = {'name': r.name}
            valors.append(register)
        self.one2manyfield = valors
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-17
      • 2020-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多