Skip to Content
Menu
This question has been flagged
3 Replies
33970 Views

Hello,

I'm having so much issues with this code now. Here is my function :

def get_available_view_value(self):

    print ("I am inside method")

     try:

         if self.unavailable: (line 89)

         print ("False commence")

         self.unavailable=False

         Print ("False value")

     else:

         self.unavailable=True

         print ("True Value")

         except Exception as e:

         print ("exception raised")

         error_message = _('Exception in getting available view value. Error Message is: ')+e.message

         _logger.exception(error_message+' error is %s ',e)


Here are my logs :


I am inside method

exception raised

2016-07-13 14:39:54,245 11135 ERROR odoo openerp.addons.wms_stock.models.stock_location: Exception in getting available view value. Error Message is: error is ('ValueError', 'Expected singleton: stock.location(17, 19)')

Traceback (most recent call last):

File "/home/xyz/git/odoo-210/odoo/staples-addons/wms_stock/models/stock_location.py", line 89, in get_available_view_value

if self.unavailable:

File "/home/xyz/git/odoo-210/odoo/openerp/fields.py", line 825, in __get__

record.ensure_one()

File "/home/xyz/git/odoo-210/odoo/openerp/models.py", line 5307, in ensure_one

raise except_orm("ValueError", "Expected singleton: %s" % self)

except_orm: ('ValueError', 'Expected singleton: stock.location(17, 19)')


I have no idea how to solve this. Can anyone help ? Thanks in advance

Avatar
Discard
Author Best Answer

Hey guys, I found the answer myself. we can either do this by replacing self with record or we can use decorator @api.one. worked for me. Thanks :)

Avatar
Discard
Best Answer

Your variable self is not a singleton, it has two. You have to do:


for location in self:
    if location.unavailable:
Avatar
Discard
Best Answer

I have a same problem in odoo 14 with and I fixed by changing the line from self.variable = to 

for rec in self : 

        rec.variable = 

Avatar
Discard
Related Posts Replies Views Activity
3
May 15
3731
3
May 17
21585
1
Jan 24
12287
6
Aug 15
6195
0
Dec 24
37