Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

};
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
182 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...