Skip to Content
मेन्यू
This question has been flagged
2 Replies
1064 Views

Please how can I display my owen qrcode on receipt in odoo 17

Avatar
Discard
Author Best Answer

What about xml, how can display it 

Avatar
Discard

you can inherit the report/view and add the field to it

Best Answer

You can create a binary field with the compute method, which will help you to generate your QR code. please see the below example.

​qrcode = fields.Binary( attachment=False, store=True, readonly=True, compute='_compute_qrcode', )

​@api.depends('user_id.login', 'user_id.company_id.display_name', 'secret')

​def _compute_qrcode(self):

        # TODO: make "issuer" configurable through config parameter?

        global_issuer = request and request.httprequest.host.split(':', 1)[0]

        for w in self:

            issuer = global_issuer or w.user_id.company_id.display_name

            w.url = url = werkzeug.urls.url_unparse((

                'otpauth', 'totp',

                werkzeug.urls.url_quote(f'{issuer}:{w.user_id.login}', safe=':'),

                werkzeug.urls.url_encode({

                    'secret': compress(w.secret),

                    'issuer': issuer,

                    # apparently a lowercase hash name is anathema to google

                    # authenticator (error) and passlib (no token)

                    'algorithm': ALGORITHM.upper(),

                    'digits': DIGITS,

                    'period': TIMESTEP,

                }), ''

            ))


            data = io.BytesIO()

            qrcode.make(url.encode(), box_size=4).save(data, optimise=True, format='PNG')

            w.qrcode = base64.b64encode(data.getvalue()).decode()

Avatar
Discard