Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
3854 Vistas

The below code was written to enable archive button for a particular user group

odoo.define('hr_idc.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 = ['hr.employee'].includes(self.controllerParams.modelName) ? 'True' : 'False';
​​if (model) {
          session.user_has_group(['hr_idc.group_hr_itadmin']).then(function(has_group) {
            if (!has_group) {
              self.controllerParams.archiveEnabled = 'False' in viewInfo.fields;
            }
          });
        }
      },
    });
  }); 


now, I want to enable it for another user group
I have tried this
 session.user_has_group(['hr_idc.group_hr_itadmin', 'hr_idc.group_hr_hradmin']).then(function(has_group) {

it enables the archive button for 'hr_idc.group_hr_hradmin'. but whenever I go to that page the below error appears

File "C:\Users\hp\odoo15\server\odoo\addons\base\models\res_users.py", line 841, in has_group
    return self._has_group(group_ext_id)
  File "", line 2, in _has_group
  File "C:\Users\hp\odoo15\server\odoo\tools\cache.py", line 95, in lookup
    return self.method(*args, **kwargs)
  File "C:\Users\hp\odoo15\server\odoo\addons\base\models\res_users.py", line 854, in _has_group
    assert group_ext_id and '.' in group_ext_id, "External ID '%s' must be fully qualified" % group_ext_id
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\hp\odoo15\server\odoo\http.py", line 654, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "C:\Users\hp\odoo15\server\odoo\http.py", line 301, in _handle_exception
    raise exception.with_traceback(None) from new_cause
AssertionError: External ID '['hr_idc.group_hr_itadmin', 'hr_idc.group_hr_hradmin']' must be fully qualified


how to do this for multiple group. or how can i avoid this error

 

Avatar
Descartar
Mejor respuesta

Hi Imran,

Try

BasicView.include({
init: function (viewInfo, params) {
this._super.apply(this, arguments);
var self = this;
var modelName = self.controllerParams.modelName;

if (modelName === 'hr.employee') {
Promise.all([
session.user_has_group('hr_idc.group_hr_hradmin'),
session.user_has_group('hr_idc.group_hr_itadmin'),
]).then(function (results) {
var hasHRAdminGroup = results[0];
var hasHRITGroup = results[1];
if (!(hasHRAdminGroup || hasHRITGroup)) {
self.controllerParams.archiveEnabled = 'False' in viewInfo.fields;
}
});
}
},
});


Hope it helps,
Kiran K

Avatar
Descartar
Autor

Thank you

Publicaciones relacionadas Respuestas Vistas Actividad
0
oct 19
12
1
may 23
1348
0
nov 24
9253
0
mar 24
1103
1
may 16
4874