简体   繁体   中英

How can I hide Create button from tree view in a specific object. As this object has all the fields readonly

How can I hide Create button from tree view in a specific object? As this object has all the fields readonly.

It depends on which OpenERP version you are working, please mention it if you'd like more specific answers. If you're asking this question you're probably not using 7.0 yet, but it might be useful to know nevertheless.

OpenERP 7.0

As of OpenERP 7.0 the system will automatically do this for you for each of the following possible actions: create, edit, delete : if the current user has no access (based on the Access Rights configuration) the corresponding flag will be added to the root node of the view definition, effectively hiding the option in the UI. These flags correspond respectively to the following access rights: create , write , unlink .

As user1576199 mentioned, this flag could also be set manually in your view definition, but that should only be required when the access rights do not correspond to the options you want to show. You could do it in this manner, in any combination:

<tree create="false" delete="false">
....
</tree>
or
<kanban create="false" edit="false">
....
</kanban>
etc..

OpenERP 6.1 and earlier

There is no option to hide these buttons, so you'll need to customize the OpenERP client(s) if you want to specifically achieve that. simahawk's answer gave you some starting points for the web client 6.1, which is probably what you want to customize.

there's no built-in feature for this. edit/delete/etc buttons are always in place even if you do not have access to the actions behind them, there's no check on permissions

anyway, you can do your javascript hack and do something like $('button.oe_form_button_edit').hide() or whatever. here are some tips on how to start developing web addons.

You can write like this on tree view

<tree string="String" create="false">

Thanks

Another way to do this on v6 is to hide it with CSS (which is easier than @simahawk's suggestion). You can do this by adding CSS to your form view xml, which contains the tree. Eg:

<html>
  <style>
    .openerp button.oe_form_button_edit { display:none }
  </style>
</html>
<tree ...

You can do the same for the delete and edit buttons as needed.

Bit of a hack... I like the v7 functionality - can't wait to upgrade :)

I don't know this solution is correct or not, but I try to put this code below in a javascript in core, and it works actually.

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; /* for create button */
            self.options.deletable= false; /* for delete button */
        };
        return ret;
    },
});

or u can refer to this link: https://github.com/kdeldycke/kevin-deldycke-blog/blob/master/content/posts/openerp-61-web-javascript-hacks-hide-buttons.md

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM