Odoo Help

Welcome!

This community 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.

0

[Solved] Error: ValueError: invalid literal for int() with base 10: '/'

By
Siobhan
on 6/5/15, 6:23 AM 4,144 views

Hello

Trying to use code to increment a number for my helpdesk module and got this error:


Traceback (most recent call last):

File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 530, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 567, in dispatch

result = self._call_function(**self.params)

File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 303, in _call_function

return checked_call(self.db, *args, **kwargs)

File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper

return f(dbname, *args, **kwargs)

File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 300, in checked_call

return self.endpoint(*a, **kw)

File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 796, in __call__

return self.method(*args, **kw)

File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 396, in response_wrap

response = f(*args, **kw)

File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 936, in call_kw

return self._call_kw(model, method, args, kwargs)

File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 928, in _call_kw

return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)

File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper

return old_api(self, *args, **kwargs)

File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 336, in old_api

result = method(recs, *args, **kwargs)

File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 1325, in default_get

defaults[name] = field.default(self)

File "/usr/lib/python2.7/dist-packages/openerp/fields.py", line 433, in <lambda>

func(recs), recs, validate=False,

File "/usr/lib/python2.7/dist-packages/openerp/fields.py", line 1025, in convert_to_cache

return int(value or 0)

ValueError: invalid literal for int() with base 10: '/'


.py code:


class helpdesk(models.Model):

_name = 'helpdesk.ticket'

name = fields.Char("Subject", size=128)

ticketnumber = fields.Integer("Tkt Num", readonly=True)


def create(self, cr, uid, vals, context=None):

vals['ticketnumber'] = self.pool.get('ir.sequence').get(cr, uid, 'helpdesk.ticket')

return super(helpdesk.ticketnumber, self).create(cr, uid, vals, context=context)

_defaults = {

'ticketnumber': lambda obj, cr, uid, context: '/'

}


XML code:


<data noupdate="1">

<record id="seq__responsible_code_inh1" model="ir.sequence.type">

<field name="name">ticketnumber</field>

<field name="code">helpdesk.ticket</field>

</record>

<record id="seq_cloan_code_inh2" model="ir.sequence">

<field name="name">ticketnumber</field>

<field name="code">helpdesk.ticket</field>

<field name="prefix"></field>

<field name="padding">3</field>

</record>

</data>


When I change Ticketnumber from Integer to a Char I get this error:


return super(helpdesk.ticketnumber, self).create(cr, uid, vals, context=context)

TypeError: must be type, not Char


Any advice here?



New error message after change code to int: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 530, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 567, in dispatch result = self._call_function(**self.params) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 303, in _call_function return checked_call(self.db, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper return f(dbname, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 300, in checked_call return self.endpoint(*a, **kw) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 796, in __call__ return self.method(*args, **kw) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 396, in response_wrap response = f(*args, **kw) File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 936, in call_kw return self._call_kw(model, method, args, kwargs) File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 928, in _call_kw return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper return old_api(self, *args, **kwargs) File "/home/vagrant/addons/helpdesk/helpdesk.py", line 27, in create return super(helpdesk.ticketnumber, self).create(cr, uid, vals, context=context) TypeError: must be type, not Integer

Siobhan
on 6/8/15, 2:09 AM
1
Turkesh Patel
On 6/5/15, 7:17 AM

in create method convert value of ticketnumber to integer as it is char and field type is integer.

def create(self, cr, uid, vals, context=None):

    vals['ticketnumber'] = int(self.pool.get('ir.sequence').get(cr, uid, 'helpdesk.ticket'))

    return super(helpdesk.ticketnumber, self).create(cr, uid, vals, context=context)

add code above: def create(self, cr, uid, vals, context=None): vals['ticketnumber'] = int(self.pool.get('ir.sequence').get(cr, uid, 'helpdesk.ticket')) return super(helpdesk.ticketnumber, self).create(cr, uid, vals, context=context) _defaults = { 'ticketnumber': lambda obj, cr, uid, context: '/' } still same error

Siobhan
on 6/8/15, 1:47 AM
0
Siobhan
On 6/8/15, 2:52 AM

Works with this code:


def create(self, cr, uid, vals, context=None):

vals['ticketnumber'] = self.pool.get('ir.sequence').get(cr, uid, 'helpdesk.ticket')

return super(helpdesk, self).create(cr, uid, vals, context=context)

_defaults = {

'ticketnumber': lambda obj, cr, uid, context: 0 (problem was here)

}

I had a char for context not an int

If anyone knows how to get the numbering to start at a number higher than one and increment from there that would be great.

so for example start counting at 20151000 and then next create is 20151001

you can set increment no whatever you want (1,2,3,4,...) ticketnumber helpdesk.ticket 32 #set increment no whatever you want

Turkesh Patel
on 6/8/15, 5:11 AM

If you want to set starting number you can set number_next_actual in sequence data.

Turkesh Patel
on 6/8/15, 5:14 AM
0
Tom
On 6/5/15, 1:40 PM

I think you can try:

return int(value) or 0 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/5/15, 6:23 AM
Seen: 4144 times
Last updated: 6/8/15, 4:18 AM