Skip to Content
Menu
This question has been flagged
5 Replies
73322 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?



Avatar
Discard
Author

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

Author Best Answer

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

Avatar
Discard

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

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

Best Answer

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)

Avatar
Discard
Author

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

Best Answer

I think you can try:

return int(value) or 0 

Avatar
Discard
Related Posts Replies Views Activity
0
Jul 16
2776
1
Jan 16
39240
0
Dec 15
2462
0
Apr 24
396
4
Nov 23
4242