在Qweb XML中放QR Code二维码 - xiaohao0576/odoo-doc GitHub Wiki

采用css绝对定位

        <!-- QR Code 容器, 使用 style 属性进行绝对定位 -->
        <t t-set="qrcode" t-value="f'https://lily-fruit-t12.odoo.com/order-delivery?order_id={doc.id}'"/>
        <div style="position: absolute; top: 0px; right: 0px; z-index: 100;">
            <img t-att-src="'/report/barcode/?barcode_type=QR&amp;value=%s&amp;width=500&amp;height=500&amp;quiet=0' % quote_plus(qrcode)"
                 alt="QR Code"
                 style="width: 3cm; height: 3cm;"/>
            <!-- 您也可以在QR Code下方添加一些文本,例如: -->
            <!-- <p style="text-align: center; font-size: 10px; margin-top: 5px;">扫描查看详情</p> -->
        </div>

知识点: 在qWeb xml中,可以直接使用quote_plus函数。 还可以使用以下函数

    def _prepare_environment(self, values):
        """ Prepare the values and context that will sent to the
        compiled and evaluated function.

        :param values: template values to be used for rendering

        :returns self (with new context)
        """
        debug = request and request.session.debug or ''
        values.update(
            true=True,
            false=False,
        )
        if not self.env.context.get('minimal_qcontext'):
            values.setdefault('debug', debug)
            values.setdefault('user_id', self.env.user.with_env(self.env))
            values.setdefault('res_company', self.env.company.sudo())
            values.update(
                request=request,  # might be unbound if we're not in an httprequest context
                test_mode_enabled=config['test_enable'],
                json=qwebJSON,
                quote_plus=werkzeug.urls.url_quote_plus,
                time=safe_eval.time,
                datetime=safe_eval.datetime,
                relativedelta=relativedelta,
                image_data_uri=self._get_converted_image_data_uri,
                # specific 'math' functions to ease rounding in templates and lessen controller marshmalling
                floor=math.floor,
                ceil=math.ceil,
                env=self.env,
                lang=self.env.context.get('lang'),
                keep_query=keep_query,
            )

        context = {'dev_mode': 'qweb' in tools.config['dev_mode']}
        return self.with_context(**context)
⚠️ **GitHub.com Fallback** ⚠️