Odoo11 TypeError:未通过按钮操作触发的屏幕小部件定义this.pos

时间:2018-08-12 08:12:44

标签: odoo point-of-sale qweb

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

此屏幕我想通过一个按钮触发此屏幕小部件。屏幕显示出来,但是单击按钮时出现了此错误“ this.pos未定义”

TypeError: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

enter image description here

  

__ 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
        };

    });
  

static / 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>

1 个答案:

答案 0 :(得分:1)

您可以在此处提供错误堆栈的完整回溯吗?此外,还会引发此错误,因为您尝试访问“ pos”对象的当前值,但未定义该值,因此会引发此错误。