how to remove Attachment for specific model in openrp?

梦想的初衷 提交于 2019-12-12 02:03:58

问题


I'm developing my own model. I installed Document model. This model is giving attachment button on top of the form. but i want this attachment button in only my module. I want to hide other that button in other form (other model). so I'm getting following code for removing "create and save" for specific model. but this coding is not working my side. please tell me how to use attachment button for specific model? and how to hide other models?.

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;
        },
    });

};

回答1:


This question is older, but I had the same problem and figured it out. Its most likely not the best solution, but it works. I assume you know how to write a custom module, so just add a dependency to "document" and create an own javascript (e.g. static/src/js/document.js, don't forget to include it in your openerp.py) with the following content:

   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'] = [];
            },
        });
    };

In this example the "Attachment" button will be hidden in the res.partner form view.

Maybe someone else knows a better way to look for the current model compared to my solution to look for the string in window.location.href



来源:https://stackoverflow.com/questions/24733796/how-to-remove-attachment-for-specific-model-in-openrp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!