Skip to Content
Menu
This question has been flagged
1 Reply
3659 Views

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")
Avatar
Discard
Best Answer

you written onchange method which trigger while values change in form view. For update field you can write script and after import call that script which will update all values, OR you can directly import data in one2many fields.

Thanks

Avatar
Discard
Related Posts Replies Views Activity
4
Oct 23
10682
1
Oct 23
97
2
Sep 21
2463
1
Jul 20
8388
5
Jun 20
30437