[英]how to make odoo computed relation field caculate itself while importing?
i'am added four fields in a view start,end,ignore and range range field is computed from start and end field and sometimes using ignore to pop up a record the method is working well but while importing data into a mode from excel sheet range field isn't computed this the whole code我在视图中添加了四个字段开始,结束,忽略和范围范围字段是从开始和结束字段计算的,有时使用忽略来弹出记录该方法运行良好,但同时将数据从 Excel 工作表范围导入模式整个代码都没有计算字段
class relate(models.Model):
_name = 'relate'
_rec_name = 'car'
@api.multi
@api.onchange('start', 'end', 'ignore')
def years_rang(self):
for rec in self:
if rec.start and rec.end:
record = [int(x) for x in range(int(rec.start), int(rec.end) + 1)]
list = []
if rec.ignore:
try:
record.remove(int(self.ignore))
list = []
except ValueError:
return {'warning': {'title': 'Warning!', 'message': "the Ignored year doesn't in range"}}
for item in record:
range_id = self.env['yearrange'].create({'name': str(item)})
list.append(range_id.id)
rec.rang = [(4, x, None) for x in list]
pass
start = fields.Char(string="", required=False, )
end = fields.Char(string="", required=False, )
rang = fields.One2many(comodel_name="yearrange", inverse_name="product_id",store=True, string="Years" ,)
ignore = fields.Char(string="Ignore", required=False, )
class yearrange(models.Model):
_name = 'yearrange'
_rec_name = 'name'
name = fields.Char()
product_id = fields.Many2one(comodel_name="relate")
Your field rang
is not computed, because you never told it to be.你的字段
rang
没有被计算,因为你从来没有告诉过它。 Just add compute
parameter on field definition:只需在字段定义上添加
compute
参数:
rang = fields.One2many(
comodel_name="yearrange", inverse_name="product_id",
compute="years_rang", store=True, string="Years" ,)
And you should use api.depends
on the computation method instead of api.onchange
:你应该根据计算方法使用
api.depends
而不是api.onchange
:
@api.multi
@api.depends('start', 'end', 'ignore')
def years_rang(self):
# ...
On client side you will see, that api.depends
will have the same outcome like api.onchange
.在客户端,您会看到
api.depends
将具有与api.onchange
相同的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.