簡體   English   中英

odoo 11中的小部件創建錯誤(js升級到odoo 11的問題)

[英]Widget creation error in odoo 11 (problem with js upgradation to odoo 11)

我正在嘗試向我的項目后端添加房間預訂摘要,我在odoo 10中使用了以下代碼,但遇到了錯誤Uncaught TypeError:Widget不是 odoo11中的構造函數 。我嘗試了不同的解決方案,但沒有解決了我的問題。謝謝。

我正在嘗試這樣顯示

這是我對應的js代碼

odoo.define('hotel_reservation.hotel_room_summary', function (require) {

var core = require('web.core');
var data = require('web.data');
var ActionManager = require('web.ActionManager');
var form_common = require('web.form_common');
var time = require('web.time');
var _t = core._t;
var QWeb = core.qweb;

var RoomSummary = form_common.FormWidget.extend(form_common.ReinitializeWidgetMixin, {
        display_name: _t('Form'),
        view_type: "form",
        init: function() {
            this._super.apply(this, arguments);
            if(this.field_manager.model == "room.reservation.summary")
            {
                $(".oe_view_manager_buttons").hide();
                $(".oe_view_manager_header").hide();
               }
            this.set({
                date_to: false,
                date_from: false,
                summary_header: false,
                room_summary: false,
            });
            this.summary_header = [];
            this.room_summary = [];
            this.field_manager.on("field_changed:date_from", this, function() {
                this.set({"date_from": time.str_to_datetime(this.field_manager.get_field_value("date_from"))});
            });
            this.field_manager.on("field_changed:date_to", this, function() {
                this.set({"date_to": time.str_to_datetime(this.field_manager.get_field_value("date_to"))});
            });

            this.field_manager.on("field_changed:summary_header", this, function() {
                this.set({"summary_header": this.field_manager.get_field_value("summary_header")});
            });
            this.field_manager.on("field_changed:room_summary", this, function() {
                this.set({"room_summary":this.field_manager.get_field_value("room_summary")});
            });
        },

        initialize_field: function() {

            form_common.ReinitializeWidgetMixin.initialize_field.call(this);
            var self = this;
            self.on("change:summary_header", self, self.initialize_content);
            self.on("change:room_summary", self, self.initialize_content);
        },

      initialize_content: function() {
           var self = this;
           if (self.setting)
               return;

           if (!this.summary_header || !this.room_summary)
                  return
           // don't render anything until we have summary_header and room_summary

           this.destroy_content();

           if (this.get("summary_header")) {
            this.summary_header = py.eval(this.get("summary_header"));
           }
           if (this.get("room_summary")) {
            this.room_summary = py.eval(this.get("room_summary"));
           }

           this.renderElement();
           this.view_loading();
        },

        view_loading: function(r) {
            return this.load_form(r);
        },

        load_form: function(data) {
            self.action_manager = new ActionManager(self);
        },

        renderElement: function() {
             this.destroy_content();
             this.$el.html(QWeb.render("summaryDetails", {widget: this}));
        }     
    });

core.form_custom_registry.add('Room_Reservation', RoomSummary);
});

xml是

<!-- Form view of room reservation summary -->
<record id="room_reservation_summary_form_view" model="ir.ui.view">
    <field name="name">room.reservation.summary.form</field>
    <field name="model">room.reservation.summary</field>
    <field name="arch" type="xml">
        <form string="Reservation Summary">
            <sheet>
                <group colspan="4" col="4">
                    <div>
                        <label for="date_from" string="Summary Period" />
                        <field name="date_from" class="oe_inline" />
                        to
                        <field name="date_to" class="oe_inline" />
                    </div>
                </group>
                <notebook>
                    <page string="Room Summary">
                        <field name="summary_header" colspan="4" invisible="1" />
                        <field name="room_summary" colspan="4" invisible="1" />
                        <widget type="Room_Reservation"></widget>
                    </page>
                </notebook>
            </sheet>
        </form>
    </field>
</record>

似乎在v11中已更改。 嘗試這樣做:

注冊自定義窗口小部件:

require('web.widget_registry').add('room_reservation', RoomSummary);

像這樣使用它:

<widget name="room_reservation"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM