Esempio n. 1
0
 def write(self, cr, user, ids, vals, context=None):
     """
     Warn if user does not have rights to modify travel with current number
     of  passengers or to add more than the limit.
     """
     if type(ids) is not list:
         ids = [ids]
     users_pool = self.pool.get('res.users')
     limit = get_basic_passenger_limit(self.pool.get("ir.config_parameter"),
                                       cr, user, context=context)
     if (len(vals.get('passenger_ids', [])) > limit and not
             users_pool.has_group(cr, user, 'travel.group_travel_manager')):
         raise orm.except_orm(
             _('Warning!'),
             _('Only members of the Travel Managers group have the rights '
               'to add more than %d passengers to a travel.') % limit)
     for travel in self.browse(cr, user, ids, context=context):
         if (len(travel.passenger_ids) > limit and not
                 users_pool.has_group(cr, user,
                                      'travel.group_travel_manager')):
             raise orm.except_orm(
                 _('Warning!'),
                 _('Only members of the Travel Managers group have the '
                   'rights to modify a Travel with more than %d passengers '
                   '(%s).') % (limit, travel.name))
     return super(travel_travel, self).write(cr, user, ids, vals,
                                             context=context)
Esempio n. 2
0
 def write(self, cr, user, ids, vals, context=None):
     """
     Warn if user does not have rights to modify travel with current number
     of  passengers or to add more than the limit.
     """
     if type(ids) is not list:
         ids = [ids]
     users_pool = self.pool.get('res.users')
     limit = get_basic_passenger_limit(self.pool.get("ir.config_parameter"),
                                       cr,
                                       user,
                                       context=context)
     if (len(vals.get('passenger_ids', [])) > limit
             and not users_pool.has_group(cr, user,
                                          'travel.group_travel_manager')):
         raise orm.except_orm(
             _('Warning!'),
             _('Only members of the Travel Managers group have the rights '
               'to add more than %d passengers to a travel.') % limit)
     for travel in self.browse(cr, user, ids, context=context):
         if (len(travel.passenger_ids) > limit and not users_pool.has_group(
                 cr, user, 'travel.group_travel_manager')):
             raise orm.except_orm(
                 _('Warning!'),
                 _('Only members of the Travel Managers group have the '
                   'rights to modify a Travel with more than %d passengers '
                   '(%s).') % (limit, travel.name))
     return super(travel_travel, self).write(cr,
                                             user,
                                             ids,
                                             vals,
                                             context=context)
Esempio n. 3
0
 def is_manager_only(self, cr, user, ids, name, args, context=None):
     limit = get_basic_passenger_limit(self.pool.get("ir.config_parameter"),
                                       cr,
                                       user,
                                       context=context)
     return {
         t.id: len(t.passenger_ids) > limit
         for t in self.browse(cr, user, ids, context=context)
     }
Esempio n. 4
0
 def create(self, cr, user, vals, context=None):
     """
     Warn if user tried to create travel with too many passengers for
     according to his security role.
     """
     users_pool = self.pool.get('res.users')
     limit = get_basic_passenger_limit(self.pool.get("ir.config_parameter"),
                                       cr, user, context=context)
     if (len(vals.get('passenger_ids', [])) > limit and not
             users_pool.has_group(cr, user, 'travel.group_travel_manager')):
         raise orm.except_orm(
             _('Warning!'),
             _('Only members of the Travel Managers group have the right '
               'to create a Travel with more than %d passengers.') % limit)
     return super(travel_travel, self).create(
         cr, user, vals, context=context)
Esempio n. 5
0
 def unlink(self, cr, user, ids, context=None):
     """
     Warn if ids being deleted contain a travel which has too many
     passengers for the current user to delete.
     """
     if type(ids) is not list:
         ids = [ids]
     users_pool = self.pool.get('res.users')
     limit = get_basic_passenger_limit(self.pool.get("ir.config_parameter"),
                                       cr, user, context=context)
     for travel in self.browse(cr, user, ids, context=context):
         if (len(travel.passenger_ids) > limit and not
                 users_pool.has_group(cr, user,
                                      'travel.group_travel_manager')):
             raise orm.except_orm(
                 _('Warning!'),
                 _('Only members of the Travel Managers group have the '
                   'rights to delete a Travel with more than %d passengers '
                   '(%s).') % (limit, travel.name))
     return super(travel_travel, self).unlink(
         cr, user, ids, context=context)
Esempio n. 6
0
 def create(self, cr, user, vals, context=None):
     """
     Warn if user tried to create travel with too many passengers for
     according to his security role.
     """
     users_pool = self.pool.get('res.users')
     limit = get_basic_passenger_limit(self.pool.get("ir.config_parameter"),
                                       cr,
                                       user,
                                       context=context)
     if (len(vals.get('passenger_ids', [])) > limit
             and not users_pool.has_group(cr, user,
                                          'travel.group_travel_manager')):
         raise orm.except_orm(
             _('Warning!'),
             _('Only members of the Travel Managers group have the right '
               'to create a Travel with more than %d passengers.') % limit)
     return super(travel_travel, self).create(cr,
                                              user,
                                              vals,
                                              context=context)
Esempio n. 7
0
 def unlink(self, cr, user, ids, context=None):
     """
     Warn if ids being deleted contain a travel which has too many
     passengers for the current user to delete.
     """
     if type(ids) is not list:
         ids = [ids]
     users_pool = self.pool.get('res.users')
     limit = get_basic_passenger_limit(self.pool.get("ir.config_parameter"),
                                       cr,
                                       user,
                                       context=context)
     for travel in self.browse(cr, user, ids, context=context):
         if (len(travel.passenger_ids) > limit and not users_pool.has_group(
                 cr, user, 'travel.group_travel_manager')):
             raise orm.except_orm(
                 _('Warning!'),
                 _('Only members of the Travel Managers group have the '
                   'rights to delete a Travel with more than %d passengers '
                   '(%s).') % (limit, travel.name))
     return super(travel_travel, self).unlink(cr,
                                              user,
                                              ids,
                                              context=context)
Esempio n. 8
0
 def is_manager_only(self, cr, user, ids, name, args, context=None):
     limit = get_basic_passenger_limit(self.pool.get("ir.config_parameter"),
                                       cr, user, context=context)
     return {t.id: len(t.passenger_ids) > limit
             for t in self.browse(cr, user, ids, context=context)}