تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
3280 أدوات العرض

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


الصورة الرمزية
إهمال
أفضل إجابة

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

if not rec.rang:

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
2
ديسمبر 22
23420
1
ديسمبر 20
17877
1
أكتوبر 19
5297
3
نوفمبر 23
16519
0
نوفمبر 23
1573