【问题标题】:Put a link on a specific One2many object and call a Python function将链接放在特定的 One2many 对象上并调用 Python 函数
【发布时间】:2017-08-04 09:26:32
【问题描述】:

我必须在 OdooV8 的 One2Many 记录中做一个类似 Add an Item 的功能链接。这是我的 JavaScript 代码:

openerp.my_module = function (instance) {
instance.web.form.One2ManyList.include({
    pad_table_to: function (count){
        var self = this;
        var res = this._super(count);
        this.$current.find('.oe_form_field_one2many_list_row_add').append(
            $('<a>', {href: '#'}).text(_t("    Add in Configuration"))
                .mousedown(function () {
                    if (self.view.editor.is_editing()) {
                        self.view.__ignore_blur = true;
                    }
                })
                .click(function (e) {
                    e.preventDefault();
                    e.stopPropagation();
                    if (self.view.editor.form.__blur_timeout) {
                        clearTimeout(self.view.editor.form.__blur_timeout);
                        self.view.editor.form.__blur_timeout = false;
                    }
                    self.view.ensure_saved().done(function () {
                        //run your js code here
                    });
                })
            );
        }
})

};

这是采购订单行中的结果:

Purchase Order Line

现在我的问题是:

  1. 我只想将链接放在特定的 One2Many 对象中,因为它出现在所有 One2Many 视图中。例如,仅在采购订单行中。
  2. 我想调用一个python函数。一旦点击Add in Configuration,它应该调用一个返回弹出表单的函数。如何 在 JavaScript 中执行此操作?

我仍然不熟悉 JavaScript,有人帮助我完成第一部分。如果您知道如何执行此操作,请帮助我。谢谢。

【问题讨论】:

    标签: javascript function openerp odoo-8


    【解决方案1】:

    为某些模型设置条件

    //Example
    var models = ['your.model1', 'your.model2']; // Array of your models
    if(models.includes(this.dataset.model)){
                // Your code
    }
    

    这只会出现在那些模型中。

    【讨论】:

    • 我不熟悉 JavaScript 先生,我怎样才能把链接只放在声明的模型上?
    【解决方案2】:

    您应该创建一个小部件。这样您就可以使用它来控制在 One2many 上使用哪个小部件。

    <field name="my_one_too_many" widget="special_o2m_with_configuration"/>
    

    要打开一个弹出表单,您必须从客户端调用一个动作,其目标设置为new。像这样的一个动作。或者,如果数据库中有操作,则直接通过其 ID 调用操作。

        {
            'type': 'ir.actions.act_window',
            'view_mode': 'form',
            'view_type': 'form',
            'target': 'new',
            'res_model': 'some.model',
            'res_id': some_id  # Or no ID if you want a new record
        }
    

    【讨论】:

    • widget="special_o2m_with_configuration" 是自定义小部件吗?
    • 是的,它是“你的”自定义小部件。您将创建的小部件。
    猜你喜欢
    • 2014-06-05
    • 1970-01-01
    • 1970-01-01
    • 2010-09-14
    • 1970-01-01
    • 2023-04-02
    • 2020-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多