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

i wanna to make a button to loop in all records and do a method that makes a list from ranges between tow fields and pop another record from the list and but the value in result field

i make it like in the code below and it work well just in the first record and the second record it working but without remove the record form the list and it's important for me to remove it like then it stop working


class relate(models.Model):
_name = 'relate'
_rec_name = 'car'

@api.multi
@api.onchange('start', 'end', 'ignore')
def years_rang(self):
    for rec in self.search([]):
        if not rec.rang:
            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= []
                    print(record)
                except ValueError:
                    return {'warning': {'title': 'Warning!', 'message': "the Ignored year doesn't in range"}}
                else:
                    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]
        else:
            return

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"

any kind of help will be appreciated


Avatar
Discard
Best Answer

May be below code is not allowing to move ahead and gives exit from loop :

if not rec.rang:

Avatar
Discard
Related Posts Replies Views Activity
2
Dec 22
23377
1
Dec 20
17821
1
Oct 19
5247
3
Nov 23
16441
0
Nov 23
1519