need to get the range between 2 years on a many2many field each year must be a record on the model
i added 2 fields to get the 2 years and and method to get the range between them
class yearrange(models.Model): _name = 'yearrange' _rec_name = 'name' name = fields.Char() class autopart(models.Model): _inherit = 'product.template' @api.multi @api.depends('start', 'end') def years(self): record = [int(x) for x in range(int(self.start), int(self.end))] for rec in self: rec.rang=record start = fields.Char(string="", required=False, ) end = fields.Char(string="", required=False, ) rang = fields.Many2many(comodel_name="yearrange", string="",compute=years )
i get records at the many2many field but all of them are = False
In this article I will show you how to create a many2many field in odoo. I will also show you guys how to filter many2many field using domain. You can also learn how to set default value on many2many field.
Reference: https://learnopenerp.blogspot.com/2018/12/add-domain-on-many2many-field-in-odoo.html
i solve it by this code
class yearrange(models.Model):
_name = 'yearrange'
_rec_name = 'name'
name = fields.Char()
product_id = fields.Many2one(comodel_name="product.template")
@api.multi
@api.onchange('start', 'end')
def years(self):
print('innnnn')
for rec in self:
if rec.start and rec.end:
record = [int(x) for x in range(int(rec.start), int(rec.end) + 1)]
list = []
for item in record:
print(item)
range_id = self.env['yearrange'].create({
'name': str(item)
})
list.append(range_id.id)
rec.rang = [(4, x, None) for x in list]
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="range")