Reputation: 526
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
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")
Upvotes: 1
Views: 349
Reputation: 14768
Your field rang
is not computed, because you never told it to be. Just add compute
parameter on field definition:
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.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
.
Upvotes: 1