【问题标题】:how to remove Attachment for specific model in openrp?如何在openrp中删除特定模型的附件?
【发布时间】:2015-06-26 16:19:11
【问题描述】:

我正在开发自己的模型。我安装了文档模型。该模型在表单顶部提供附件按钮。但我只希望我的模块中有这个附件按钮。我想以其他形式(其他模型)隐藏其他按钮。 所以我得到以下代码来删除特定模型的“创建和保存”。但是这种编码对我不起作用。请告诉我如何使用特定型号的附件按钮?以及如何隐藏其他模型?

openerp.web_smile_hide_buttons = function(openerp) {

    // Models for which we'll hide create and duplicate buttons
    var MODELS_TO_HIDE = ['kit.lab'];

    // Hide the create button on all list views, which affect tree views and many2one pop-up search view
    openerp.web.ListView.include({
        start: function() {
            var self = this;
            var ret = this._super.apply(this, arguments);
            var res_model = this.dataset.model;
            if ($.inArray(res_model, MODELS_TO_HIDE) != -1) {
                self.options.addable = false;
            };
            return ret;
        },
    });

    // Hide the save button on form views
    openerp.web.FormView.include({
        on_loaded: function(data) {
            var self = this;
            var ret = this._super.apply(this, arguments);
            var res_model = this.dataset.model;
            // if ($.inArray(res_model, MODELS_TO_HIDE) != -1) {
            this.$element.find('button.oe_dropdown_toggle.oe_dropdown_arrow').remove();
            this.$element.find('button.oe_form_button_save').remove();
            //};
            return ret;
        },
    });

    // Hide the create and duplicate button on all page views (i.e. read-only form views)
    openerp.web.PageView.include({
        on_loaded: function(data) {
            var self = this;
            var ret = this._super.apply(this, arguments);
            var res_model = this.dataset.model;
            if ($.inArray(res_model, MODELS_TO_HIDE) != -1) {
                this.$element.find('button.oe_form_button_create').remove();
                this.$element.find('button.oe_form_button_duplicate').remove();
            };
            return ret;
        },
    });

};

【问题讨论】:

    标签: python-2.7 attachment openerp-7


    【解决方案1】:

    这个问题比较老,但我遇到了同样的问题并想通了。它很可能不是最好的解决方案,但它确实有效。我假设您知道如何编写自定义模块,因此只需将依赖项添加到“文档”并创建自己的 javascript(例如 static/src/js/document.js,不要忘记将其包含在您的 openerp .py),内容如下:

       openerp.document = function (instance) {
            _t = instance.web._t;
            instance.web.Sidebar.include({
                init : function(){
                    this._super.apply(this, arguments);
                    if (window.location.href.indexOf('&model=res.partner') === -1)
                        this.sections.splice(1, 0, { 'name' : 'files', 'label' : _t('Attachment(s)'), });
                    this.items['files'] = [];
                },
            });
        };
    

    在本例中,“附件”按钮将隐藏在 res.partner 表单视图中。

    与我在 window.location.href 中查找字符串的解决方案相比,也许其他人知道查找当前模型的更好方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-17
      • 1970-01-01
      • 1970-01-01
      • 2015-06-30
      • 1970-01-01
      • 1970-01-01
      • 2015-08-06
      • 1970-01-01
      相关资源
      最近更新 更多