如何在 odoo 10 中使用 onchange for one2many 获取当前记录 ID?

how to get current record id using onchange for one2many in odoo 10?

我已经尝试了下面的 onchange 函数代码,但是 return 一些不可读的代码

class sales_targets(models.Model):
    _name = 'sale.target'

    category = fields.Selection([
        ('normal', 'Product'), ('cloud', 'Cloud EYE'), ('tech', 'Technical Support Group'), ('db', 'Database'),
        ('odoo', 'Odoo'), ('can', 'CAN'), ('tod', 'TOD'), ('rental', 'Rental'), ('tec', 'TEC'), ('top', 'TOP'),
        ('tor', 'TOR'), ('tos', 'TOS'),
        ('aws', 'AWS')], 'Category', default='normal',
        help="A category of the view type is a virtual category that can be used as the parent of another category to create a hierarchical structure.")
    team_ids=fields.Many2many('crm.team','team_target_rel','target_ids','team_id','Sales Team')
    from_date=fields.Date('Budget From Date')
    to_date = fields.Date('Budget To Date')
    no_call=fields.Float('No of Calls')
    target_line=fields.One2many('target.line','target_id','Target Line', copy=True)




    @api.multi
    @api.onchange('team_ids')
    def _onchange_tem_salesperson(self):
        print ".....",self.id,self._origin

上面的代码 onchange 函数结果是

...... <odoo.models.NewId object at 0x7f72aff2b290> sale.target()

在 onchange 事件中,odoo 为您创建一个虚拟记录。 为了得到id,odoo传递了origin属性中的记录。

   self._origin.id. # keep in mind in create id is instance of NewId object Not integer

不知道是不是自己。 _origin 或 self.origin 但我确定它是原始的,因为我以前使用过它。希望对你有帮助

感谢您的建议,然后终于找到了此页面的解决方案How to pass value with onchange one2many variable in odoo?如果我的问题值得,请投票给我的问题