2017-09-09 67 views
0

我曾尝试下面的代码为平变化的功能,但还有些不可读代码如何使用onchange for one2many在odoo 10中获取当前记录ID?

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() 
+0

尝试:'self.env.context.get(“active_id”)' – KbiR

+0

它返回**无** – KLN

+0

删除'@ api.multi',再次尝试 – KbiR

回答

1

在onchange事件odoo为你创建一个虚拟的记录。 为了获得id,odoo传递了原始属性中的记录。

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

我不确定它是否是自我。 _origin或self.origin,但我确定它是在原产地,因为我之前使用过它。希望它可以帮助你

为你提供建议
+0

它返回False – KLN

+0

尝试self.env._origin。我在我的手机上,如果你是在调试模式搜索良好,你可以找到这个起源属性只是把一个断点,并检查自己的内容 – Cherif

+0

什么仍然没有我的朋友 – Cherif