Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
3681 Tampilan

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
Buang
Jawaban Terbai

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

if not rec.rang:

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
2
Des 22
23944
1
Des 20
18705
1
Okt 19
5670
3
Nov 23
17274
0
Nov 23
2225