Odoo Help

0

ValueError: Expected singleton

By
Dominic
on 6/23/16, 10:37 AM 2,151 views

Hello, 

This is my function: 

@api.depends('xidentification')
def _concat_nit(self):

# Executing only for Document Type 31 (NIT)
if self.doctype is 31: # <--------------- THIS IS LINE 147
# First check if entered value is valid
self._check_ident()
self._check_ident_num()
# Instead of showing "False" we put en empty string
if self.xidentification is False:
self.xidentification = ''
self.formatedNit = ''
# Formatting the NIT: xx.xxx.xxx-x
s = str(self.xidentification)[::-1]
newnit = '.'.join(s[i:i+3] for i in range(0, len(s), 3))
newnit = newnit[::-1]
nitList = [
newnit,
# Calling the NIT Function which creates the Verification Code:
self._check_dv(str(self.xidentification))
]
formatedNitList = []
for item in nitList:
if item is not '':
formatedNitList.append(item)
self.formatedNit = '-' .join(formatedNitList)
# Saving Verification digit in a proper field
self.dv = nitList[1]


But I get the following error: 

File "/home/travis/build/OCA/l10n-colombia/l10n_co_res_partner/models/l10n_co_res_partner.py", line 147, in _concat_nit
if self.doctype is 31:
File "/home/travis/odoo-9.0/openerp/fields.py", line 819, in __get__
record.ensure_one()
File "/home/travis/odoo-9.0/openerp/models.py", line 5403, in ensure_one
raise ValueError("Expected singleton: %s" % self)

ValueError: Expected singleton: res.partner(3, 7, 17, 32, 22, 21, 6, 18, 16, 14, 19, 20, 13, 11, 29, 35, 28, 8, 23, 24, 34, 25, 9, 26, 27, 39, 38, 15, 33, 37, 43, 5, 4, 42, 10, 30, 31, 12, 36, 1, 40, 41)

I have no clue why I get this error? Actually the function works in the interface, but Travis is complaining: https://travis-ci.org/OCA/l10n-colombia/jobs/139356438#L645

Any Ideas on how to fix this issue? 



1

Baiju KS

--Baiju KS--
3259
| 5 5 8
Kochi, India
--Baiju KS--
ODOO technical

        I like learning new thing, especially technical thing. I am a quick learner, I can learn technical things very fast. I have good logical skill,  I have immense interest in programming.

e-mail id : baijuks@hotmail.com

Baiju KS
On 6/23/16, 11:58 AM

Hi,

Try giving @api.one decorator for the method.

@api.depends('xidentification')   
@api.one   
     def _concat_nit(self):


This decorator loops automatically on Records of RecordSet for you. Self is redefined as current record:

Or

try iterating with for loop

     for record in self:

        if record.doctype is 31: # <--------------- THIS IS LINE 147
             # First check if entered value is valid
            record._check_ident()


Hopes this solves the problem.

0
Dominic
On 6/23/16, 12:31 PM

Thanks for your answer. Yes, with api.one it works, BUT api.one is deprecated in Odoo9, so I don't want to use it. Any other ideas? 

Checking other resources I see that it might be an issue with a loop?


0

Pawan

--Pawan--
1437
| 4 4 6
Hyderabad, India
--Pawan--


Pawan
On 6/24/16, 1:42 AM

Dominiac,

here in _concat_init you are getting list of res.partner object and when you are trying to access doctype off it, its not able to perform that as it is "list of objects".

So what you can do is,

1) As suggested by Baiju,

2) loop through self and check for each record as:

@api.depends('xidentification')    
    def _concat_nit(self):
         for record in self:
             if record.doctype is 31:
                 # Further code goes here, use record instead of self......


Hope this will help you...


This was it! Thank you :-) fixed the problem

Dominic
on 6/24/16, 10:19 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 6/23/16, 10:37 AM
Seen: 2151 times
Last updated: 5/31/17, 6:17 AM