Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
1060 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

What about xml, how can display it 

Ảnh đại diện
Huỷ bỏ

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ