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)
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)
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) }
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)
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)
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)
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)
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)}