Skip to Content
Menu
This question has been flagged
6 Replies
4532 Views

I looked at different forum posts but I don't see a fix. I have 2 custom models that are in a relation One2many. One the many side I have a few related fields just for displaying the data in the view. Now if I change a value on the One side model that is related to the many side model I get the Expected singleton: my_custom_model_many(id1, id2, id3).

How can I fix this? I tough to make create and  write methods @api.multi and then iterate with "for rec in self:" but they have return statements so the methods would finish in the first iteration. 

If anyone has any suggestions with maybe a code example, that would be very appreciated!  


class my_custom_module_one(models.Model):
	_name = 'my.custom.one'
	month = fields.Char()
	date_from = fields.Date()
	date_to = fields.Date()

	many_ids = fields.One2many('my.custom.many', 'one_id')

class my_custom_module_many(models.Model):
	_name = 'my.custom.many'
	one_month = fields.Char(related='one_id.month')
	one_date_form = fields.Date(related='one_id.date_from')
	one_date_to = fields.Date(related='one_id.date_to')

	one_id = fields.Many2one('my.custom.one')
Avatar
Discard

Can you update the question with your code and with the error message

Author

Can't update the question... get only 403 forbidden page.

I have updated the question with what you have put as answer, by with this code there will not be any issues, I think you may have written some other functions in it

Best Answer

Dear Samo Arko

I think you must use @api.multi instead of @api.one  on specific function and make for loop in your function:

@api.multi

def your_function_name(self):

      for rec in self:

                     ......................



I Hope I helped you..

Avatar
Discard
Author

ok... I've removed the api.one method decorators. I've used them only a few for returning values of calculations. Didn't know that they are deprecated or I wouldn't even use them. But I'm still getting the error. A line before the "Except singleton" is "odoo models.py", line 4820, in ensure_one"

Author

Thanks for getting me on the right path! can't up vote your answer else I would!

Author Best Answer

Thank all you guys for the help. Aymans answer got me on the right path. I all ready changed the @api.one to @api.multi decorators. After I changed all and still got the error I looked on those that I changed before. And there was the problem. In one of the methods I forgot to change self to rec when I added the for rec in self. 

Avatar
Discard
Related Posts Replies Views Activity
1
May 24
751
1
Sep 22
1012
4
May 18
9450
0
Mar 23
3773
1
Jul 20
6756