Odoo Help

0

Iam trying to write qr code for only one employee field called name? How to use slug in barcode_url?

By
savita
on 9/1/16, 2:19 AM 417 views

Hi All,

I'm trying to generate qr code for employee name in my custom module but Iam unable to write the barcode url..and would like to share the code which i have written in my custom module.

class Employee_table(models.Model):

_inherit = 'hr.employee'

def get_image(self, value, width, hight, hr, code='QR'):

""" genrating image for barcode """

options = {}

if width:options['width'] = 150

if hight:options['hight'] = 150

if hr:options['humanReadable'] = True

try:

ret_val = createBarcodeDrawing(code, value=str(value), **options)

except Exception, e:

raise ValueError(e)

return base64.encodestring(ret_val.asString('jpg'))

@api.multi

def _compute_barcode_urll(self):

dom_name = self.env['base.config.settings'].search([], limit=1)

for record in self:

if record.name_related:

if dom_name.alias_domain:

domain_nm = dom_name.alias_domain

else:

domain_nm = 'localhost:8069'

record.barcode_urll = "%s/hr/%s?" % (domain_nm, slug(record.name_related))

image = self.get_image(record.barcode_urll,

code='QR',

width=150, hight=150,

hr=True)

record.write({'qr_image1': image})

barcode_urll = fields.Char(compute='_compute_barcode_urll', string='Related URL')

qr_image1 = fields.Binary('Barcode Image')


but iam getting following error.


Odoo Server Error
Traceback (most recent call last):
  File "/home/autochip/Music/odoo/9.0/openerp/http.py", line 643, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/autochip/Music/odoo/9.0/openerp/http.py", line 680, in dispatch
    result = self._call_function(**self.params)
  File "/home/autochip/Music/odoo/9.0/openerp/http.py", line 316, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/autochip/Music/odoo/9.0/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/autochip/Music/odoo/9.0/openerp/http.py", line 309, in checked_call
    result = self.endpoint(*a, **kw)
  File "/home/autochip/Music/odoo/9.0/openerp/http.py", line 959, in __call__
    return self.method(*args, **kw)
  File "/home/autochip/Music/odoo/9.0/openerp/http.py", line 509, in response_wrap
    response = f(*args, **kw)
  File "/home/autochip/Music/odoo/9.0/addons/web/controllers/main.py", line 892, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/home/autochip/Music/odoo/9.0/addons/web/controllers/main.py", line 884, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/home/autochip/Music/odoo/9.0/openerp/api.py", line 250, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/autochip/Music/odoo/9.0/openerp/models.py", line 3193, in read
    result = BaseModel.read(records, fields, load=load)
  File "/home/autochip/Music/odoo/9.0/openerp/api.py", line 248, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/autochip/Music/odoo/9.0/openerp/models.py", line 3239, in read
    values[name] = field.convert_to_read(record[name], use_name_get)
  File "/home/autochip/Music/odoo/9.0/openerp/models.py", line 5740, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "/home/autochip/Music/odoo/9.0/openerp/fields.py", line 828, in __get__
    self.determine_value(record)
  File "/home/autochip/Music/odoo/9.0/openerp/fields.py", line 935, in determine_value
    self.compute_value(recs)
  File "/home/autochip/Music/odoo/9.0/openerp/fields.py", line 890, in compute_value
    self._compute_value(records)
  File "/home/autochip/Music/odoo/9.0/openerp/fields.py", line 880, in _compute_value
    getattr(records, self.compute)()
  File "/home/autochip/Music/odoo/9.0/openerp/api.py", line 248, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/autochip/Music/odoo/9.0/addons/wms/qrcode.py", line 69, in _compute_barcode_urll
    record.barcode_urll = "%s/hr/%s?" % (domain_nm, slug(record.name_related))
  File "/home/autochip/Music/odoo/9.0/addons/website/models/website.py", line 113, in slug
    id, name = value
ValueError: too many values to unpack

Kindly can anyone help me to correct my code?

0

Hilar

--Hilar--
2245
| 5 3 8
Malappuram, India
--Hilar--
  Blog:-
        https://hilarlive.wordpress.com/
  StackOverflow:
        http://stackoverflow.com/users/7561347/burmese-pythis

Hilar
On 5/24/17, 12:09 AM

Use slugify() function instead of slug(), because usually slug need an id as integer or browsable record, but slugify states that

Transform a string to a slug that can be used in a url path.

This method will first try to do the job with python-slugify if present.
Otherwise it will process string by stripping leading and ending spaces,
converting unicode chars to ascii, lowering all chars and replacing spaces
and underscore with hyphen "-".

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: 9/1/16, 2:19 AM
Seen: 417 times
Last updated: 5/24/17, 12:09 AM