Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
3693 Zobrazení

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
Zrušit
Nejlepší odpověď

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

if not rec.rang:

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
pro 22
23964
1
pro 20
18724
1
říj 19
5674
3
lis 23
17294
0
lis 23
2238