我在onchange函数下面尝试了下面的代码,但是返回了一些不可读的代码
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 :(得分:2)
在onchange上,odoo会为你创建一个虚拟记录。 为了获得id,odoo传递origin属性中的记录。
self._origin.id. # keep in mind in create id is instance of NewId object Not integer
我不确定这是不是自我。 _origin或者self.origin,但我确信它是原产地,因为我之前使用过它。希望它能帮到你
答案 1 :(得分:0)
感谢您的建议,然后最终获得此页面的解决方案How to pass value with onchange one2many variable in odoo?如果我的问题值得,请向我投票我的问题