Skip to content

Instantly share code, notes, and snippets.

@goliveirab
Last active September 20, 2023 04:56
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save goliveirab/a3dafb432338d7250d32e548151bfd9c to your computer and use it in GitHub Desktop.
Save goliveirab/a3dafb432338d7250d32e548151bfd9c to your computer and use it in GitHub Desktop.
Remove Archive and Unarchive options from menu 'Action' for users with no access rights - Odoo v11
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="res.groups" id="group_archive">
<field name="name">Archive Product & Partner</field>
</record>
</odoo>
odoo.define('test_modulo.BasicView', function (require) {
"use strict";
var session = require('web.session');
var BasicView = require('web.BasicView');
BasicView.include({
init: function(viewInfo, params) {
var self = this;
this._super.apply(this, arguments);
var model = self.controllerParams.modelName in ['res.partner','product.template'] ? 'True' : 'False';
if(model) {
session.user_has_group('test_modulo.group_archive').then(function(has_group) {
if(!has_group) {
self.controllerParams.archiveEnabled = 'False' in viewInfo.fields;
}
});
}
},
});
});
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="test_modulo_assets_backend" name="test modulo assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/test_modulo/static/src/js/basic_view.js"/>
</xpath>
</template>
</odoo>
@hardikns
Copy link

hardikns commented Dec 31, 2019

Thanks for this its a great help. Recently moved form v8 to 12 and this new menu option is causing confusion and misuse.

one Quick question - what does in viewInfo.fields do in basic_view.js L14

@IronSenior
Copy link

Thanks for this. This button was creating a big error for one of my custom modules.

@PratikTUS
Copy link

PratikTUS commented Feb 12, 2021

Thank you for this, I tried in v13, where L10 returns False every time. So I implement like this:

var model = self.controllerParams.modelName;
if (model == 'res.partner' || model == 'product.template') {
    ...
}

@specks-zz
Copy link

Hi.

This is a good help!! I made a little change to use in Employee View to hide archive action when user has no admin rigths

Thanks goliveirab!!!

@BishalGhimire
Copy link

If you are in version 15, define that js directly on manifest instead of xml,
'assets': {
'web.assets_backend': [
'test_modulo/static/src/js/basic_view.js',
],
},

@sonnvh-aip
Copy link

Can you handle it with odoo16 version?

@onuh
Copy link

onuh commented Aug 11, 2023

This seems not to work again in v.16

@onuh
Copy link

onuh commented Aug 13, 2023

You will need to extend the view controller with js_class to either the tree or form or Kannan view which you want the button hidden in v16. This solution is outdated for v16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment