Skip to Content
Menu
This question has been flagged
2 Replies
4092 Views

hello guys, i have a problem hiding action archive/unarchive on specific models. i have tried to make a condition to check for few models.. the code is working but on all of the models

im using odoo 11

here are my JS:


odoo.define("wpd_inventory.BasicView"function(require) {
    "use strict";

    var session = require('web.session');
    var BasicView = require('web.BasicView');

    BasicView.include({
        init: function(viewInfoparams) {
            var self = this;
            this._super.apply(thisarguments);
            var model = self.controllerParams.modelName in ['product.product','product.template'] ? 'True' : 'False';
            if(!model) {
                self.controllerParams.archiveEnabled = 'active' in viewInfo.fields;
            } else {
                session.user_has_group('wpd_inventory.group_archive_data').then(function(has_group) {
                    if(!has_group) {
                        self.controllerParams.archiveEnabled = 'False' in viewInfo.fields;
                    }
                })  
            }
        },
    });
    return BasicView;
});

thank you for your help
Avatar
Discard
Author Best Answer
so this is my code and working fine, but still when we give user right access group then we refresh it, i have to go another model then back to my prohibited models to make the archive/unarchive available

odoo.define("wpd_inventory"function(require) {
    "use strict";

    var core = require("web.core");
    var Sidebar = require('web.Sidebar'); //location of other options {export, archive, unarchive, delete, etc}
    var ListController = require("web.ListController");
    var _t = core._t;
    var session = require('web.session');

    ListController.include({
        renderSidebar: function ($node) {
            if (this.hasSidebar && !this.sidebar) {
                 
                var grant_access = true
                if (this.modelName == "product.template" || this.modelName == 'product.product') {
                    session.user_has_group('wpd_inventory.group_archive_data').then(function(has_group) {
                        if(!has_group) {
                            grant_access = false;
                        }
                    });
                }


                console.log({
                    'current_model': this.modelName,
                    'super_user': session.is_superuser,
                    'grant_access_archive_products': grant_access
                });
                    
                var other = [];
                
                other.push({
                    label: _t("Export"),
                    callback: this._onExportData.bind(this)
                });
                
                if (this.archiveEnabled) {
                     
                    if (grant_access || session.is_superuser) {
                        other.push({
                            label: _t("Archive"),
                            callback: this._onToggleArchiveState.bind(thistrue)
                        });
                        other.push({
                            label: _t("Unarchive"),
                            callback: this._onToggleArchiveState.bind(thisfalse)
                        });
                    }
                }
                
                if (this.is_action_enabled('delete')) {
                    other.push({
                        label: _t('Delete'),
                        callback: this._onDeleteSelectedRecords.bind(this)
                    });
                }

                this.sidebar = new Sidebar(this, {
                    editable: this.is_action_enabled('edit'),
                    env: {
                        context: this.model.get(this.handle, {raw: true}).getContext(),
                        activeIds: this.getSelectedIds(),
                        model: this.modelName,
                    },
                    actions: _.extend(this.toolbarActions, {other: other}),
                });

                this.sidebar.appendTo($node);
                this._toggleSidebar();

            }
        }
    });
});

Avatar
Discard
Best Answer

i use automated action-for specific group allow it. so this not hide, but not allow.

another way what i do-users rights group. making change there. usually archive and default things will be in 'internal user' group.

Avatar
Discard