Skip to Content
Meniu
Această întrebare a fost marcată
2 Răspunsuri
1065 Vizualizări

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

Imagine profil
Abandonează
Autor Cel mai bun răspuns

What about xml, how can display it 

Imagine profil
Abandonează

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

Cel mai bun răspuns

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()

Imagine profil
Abandonează