首页 > 解决方案 > Odoo11 TypeError:this.pos 未定义由按钮操作触发的屏幕小部件

问题描述

创建一个从屏幕小部件扩展的屏幕“自定义屏幕”,使用模板显示一段 lorem 并返回屏幕小部件的对象,以便可以从其他小部件调用它。

这个屏幕我想从一个按钮触发这个屏幕小部件。屏幕显示,但单击按钮时出现此错误“this.pos is undefined”

类型错误:this.pos 未定义

TypeError: this.pos is undefined
http://localhost:8069/web/content/1394-95d31f5/point_of_sale.assets.js:337
Traceback:
show@http://localhost:8069/web/content/1394-95d31f5/point_of_sale.assets.js:337:1
show_screen@http://localhost:8069/web/content/1394-95d31f5/point_of_sale.assets.js:316:28
button_click@http://localhost:8069/web/content/1394-95d31f5/point_of_sale.assets.js:572:385
renderElement/<@http://localhost:8069/web/content/1394-95d31f5/point_of_sale.assets.js:362:203
dispatch@http://localhost:8069/web/content/941-9a091d9/web.assets_common.js:892:378
$event.dispatch@http://localhost:8069/web/content/1394-95d31f5/point_of_sale.assets.js:480:8
add/elemData.handle@http://localhost:8069/web/content/941-9a091d9/web.assets_common.js:865:151

在此处输入图像描述

__mainfest__.py

{
    'name': "custom-screen",

    'summary': """
        Short (1 phrase/line) summary of the module's purpose, used as
        subtitle on modules listing or apps.openerp.com""",

    'description': """
        Long description of module's purpose
    """,

    'author': "My Company",
    'website': "http://www.yourcompany.com",


    'category': 'Uncategorized',
    'version': '0.1',

    # any module necessary for this one to work correctly
    'depends': ['base'],

    # always loaded
    'data': [
        'views/templates.xml',
    ],

    'demo': [
        'demo/demo.xml',
    ],
    'qweb': [
        'static/src/xml/custom-screen.xml',

    ],
}

视图/模板

<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <template id="assets" inherit_id="point_of_sale.assets">
        <xpath expr="." position="inside">
            <script type="text/javascript" src="/custom-screen/static/src/js/custom.js"></script>

        </xpath>
    </template>

</odoo>

> custom.js

    odoo.define('custom-screen.custom-screen', function (require) {
        "use strict";


        var screens = require('point_of_sale.screens');
        var gui = require('point_of_sale.gui');

        var Button = screens.ActionButtonWidget.extend({
            template: 'Button',

            button_click: function () {
                var self = this;
                console.log('Button Clicked');
                self.gui.show_screen('custom-screen');

            },

        });

        screens.define_action_button({
            'name': 'button',
            'widget': Button,
        });

        var CustomScreenWidget = screens.ScreenWidget.extend({
            template: 'CustomScreenWidget',

            init: function () {
                console.log("Initialize the custom screen");
            }
        });

        gui.define_screen({
            'name': 'custom-screen',
            'widget': CustomScreenWidget,
        });

        return {
            Button: Button,
            CustomScreenWidget: CustomScreenWidget
        };

    });

静态/src/xml/custom-screen.xml

<t t-name="Button">
    <span class="control-button">
        <!--<i class="fa fa-print"></i>-->
        Open Custom Screen
    </span>
</t>

<t t-name="CustomScreenWidget">
    <div>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus alias, aliquid cupiditate dignissimos, doloribus, enim error eum fugiat id nisi odit quibusdam quo repellat repellendus sed vitae voluptatem. Distinctio, nemo.</p>
    </div>
</t>

标签: odoopoint-of-saleqweb

解决方案


你能在这里提供错误堆栈的完整回溯吗?此外,由于您尝试访问“pos”对象的当前值但未定义该值,因此引发了此错误,因此引发了此错误。


推荐阅读