Last active
September 20, 2023 04:56
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<odoo> | |
<record model="res.groups" id="group_archive"> | |
<field name="name">Archive Product & Partner</field> | |
</record> | |
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}); | |
} | |
}, | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
Thanks for this. This button was creating a big error for one of my custom modules.
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') {
...
}
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!!!
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',
],
},
Can you handle it with odoo16 version?
This seems not to work again in v.16
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
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