Odoo Javascript & Widget

定义一个OdooClass

odoo.define('addon_name.service', function (require) {
    "use strict";
    var utils = require('web.utils');
    var Model = require('web.Model');

    // do things with utils and Model
    var something_useful = 15;
    return  {
        something_useful: something_useful,
    };
});

重写记录打开方式

odoo.define('combined_statements.working_papers', function(require) {
	"use strict";
	var core = require('web.core');
	var ListView = require('web.ListView');
	var utils = require('web.utils');
	var web_client = require('web.web_client');
	var Model = require('web.Model');

	var QWeb = core.qweb;
	var _t = core._t;

	/**
	 * 打开工作底稿创建向导页面
	 */
	function open_wording_papers_wizard_action() {
		web_client.action_manager.do_action({
			name: "底稿定义",
			type: "ir.actions.act_window",
			res_model: "working.papers.define.wizard",
			target: 'new',
			xml_id: 'combined_statements.working_papers_define_wizard_form',
			views: [[false, 'form']]
		});
	}

	ListView.include({
                // 为增加按钮绑定点击事件
		render_buttons: function($node) {
			let add_button = false;
			if (!this.$buttons) {
				add_button = true;
			}

			this._super.apply(this, arguments);

			if (add_button) {
				this.$buttons.on('click', '.o_button_open', open_wording_papers_wizard_action.bind(this));
			}
		},

		// 重写Tree视图点击行打开记录的方式
		do_activate_record: function(index, id, dataset, view) {
			if (this.model === 'combined.statements.working.paper') {
				let record = this.records.get(id);
				this.do_action({
					type: "ir.actions.client",
					tag: 'working.papers',
					params: record,
				});
			}else {
				this._super.apply(this, arguments);
			}
		}
	});

});

There are no comment yet.

HTML tag cannot be used in this comment.