Add possibility to make an exception on some form views in web_eradicate_duplicate

This commit is contained in:
Alexis de Lattre
2016-01-29 23:42:15 +01:00
parent 90a2f719ef
commit 2ceb626723
2 changed files with 29 additions and 3 deletions

View File

@@ -28,10 +28,12 @@
'license': 'AGPL-3',
'summary': 'Remove More > Duplicate for all users except admin',
'description': '''
Eradicate duplicate
Eradicate Duplicate
===================
This module is inspired by the module *web_hide_duplicate* of Aristobulo Meneses available on https://github.com/menecio/odoo-addons. The main difference is that it will remove the *More > Duplicate* button everywhere (without any change in the XML of the form views) for all users except *admin*.
This module is inspired by the module *web_hide_duplicate* of Aristobulo Meneses available on https://github.com/menecio/odoo-addons. The main difference is that it will remove the *More > Duplicate* button everywhere by default for all users except *admin*.
It is possible to restore the duplicate feature on some form views by adding an attribute **duplicate_eradicate="false"** (you will find an example in a comment at the end of the file static/src/js/eradicate_duplicate.js).
This module has been written by Alexis de Lattre from Akretion
<alexis.delattre@akretion.com>.

View File

@@ -10,7 +10,14 @@ openerp.web_eradicate_duplicate = function (instance) {
load_form: function(data) {
this._super(data);
// Remove More > Duplicate button for all users except admin
if (this.session.uid != 1 && this.sidebar && this.sidebar.items && this.sidebar.items.other) {
// or except if there is an attribute duplicate_eradicate="false"
// in the form view
if (
this.sidebar &&
this.sidebar.items &&
this.sidebar.items.other &&
this.session.uid != 1 &&
this.is_action_enabled('eradicate_duplicate')) {
var new_items_other = _.reject(this.sidebar.items.other, function (item) {
return item.label === _t('Duplicate');
});
@@ -19,3 +26,20 @@ openerp.web_eradicate_duplicate = function (instance) {
}
});
};
/*
EXAMPLE : enable duplicate on account.move :
<record id="view_move_form" model="ir.ui.view">
<field name="name">duplicate_allowed.account_move_form</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<xpath expr="/form" position="attributes">
<attribute name="eradicate_duplicate">false</attribute>
</xpath>
</field>
</record>
*/