Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
3235 Vistas

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
Descartar
Mejor respuesta

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

if not rec.rang:

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
dic 22
23385
1
dic 20
17822
1
oct 19
5249
3
nov 23
16445
0
nov 23
1527