如何在openrp中删除特定型号的附件? [英] how to remove Attachment for specific model in openrp?

查看:91
本文介绍了如何在openrp中删除特定型号的附件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发自己的模型.我安装了文档模型.该模型在表单顶部提供了附件按钮.但我只希望在我的模块中使用此附件按钮.我想以其他形式(其他模型)隐藏其他那个按钮. 因此,我正在获取以下代码,以删除特定模型的创建并保存".但是这种编码在我这边行不通.请告诉我如何针对特定型号使用附件按钮?以及如何隐藏其他模型?

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

};

解决方案

这个问题比较老,但是我遇到了同样的问题,并找到了答案.它最有可能不是最好的解决方案,但它可以工作.我假设您知道如何编写自定义模块,因此只需向"document"添加依赖项并创建自己的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中查找字符串的解决方案相比,也许其他人知道一种查找当前模型的更好方法.

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

};

解决方案

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

这篇关于如何在openrp中删除特定型号的附件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆