Skip to Content
Menu
This question has been flagged

i need to make a computed method to calculate the range of years on fire while importing excel sheet if it onChange without dependence api it work well when i but manually records into fields but also not work while importing data

i trired this code but when i'am importing data or inter record into fields i get an error as a title and below


class relate(models.Model):
_name = 'relate'
_rec_name = 'car'

@api.multi
@api.depends('start', 'end', 'ignore')
def years_rang(self):
    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 = []
            if rec.ignore:
                try:
                    record.remove(int(self.ignore))
                    list = []
                except ValueError:
                    return {'warning': {'title': 'Warning!', 'message': "the Ignored year doesn't in range"}}
            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]
        pass
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" ,compute="years_rang")
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")


maximum recursion depth exceeded while calling a Python object


Avatar
Discard

look into the model that you're inserting if you have any on.change or depends method that changes any of your depends attributes.

Author

what do you mean ?

Your method is triggered when something is written the three fields and in this method you write to another model, check if in the other model isn't a method that is triggered when you create/write to the model. And that method changes one of your three fields, so that your method would be executed again.

Related Posts Replies Views Activity
2
Dec 22
22462
3
Dec 22
2629
2
Nov 22
4363
1
Jun 22
6761
1
Sep 21
2038