You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # License and authorship info in:
  3. # __openerp__.py file at the root folder of this module.
  4. from openerp import api
  5. from openerp.models import BaseModel
  6. import logging
  7. _logger = logging.getLogger(__name__)
  8. base_load = BaseModel.load
  9. @api.model
  10. def load_import_optional(self, fields=None, data=None):
  11. '''Overriding this method we only allow its execution if the current
  12. user belongs to the group allowed for CSV data import.
  13. An exception is raised otherwise, and the import attempt is logged.
  14. This method is monkeypatched and will also affect other databases on the
  15. same Odoo instance. Therefore, check if the group actually exist as
  16. evidence that this module is installed.
  17. '''
  18. group_ref = 'base_import_security_group.group_import_csv'
  19. group = self.env.ref(group_ref, raise_if_not_found=False)
  20. if not group or self.env.user.has_group(group_ref):
  21. return base_load(self, fields=fields, data=data)
  22. msg = 'User (ID: %s) is not allowed to import data in model %s.' % (
  23. self.env.uid, self._name)
  24. _logger.info(msg)
  25. return {'ids': False, 'messages': [{
  26. 'type': 'error',
  27. 'message': msg,
  28. 'moreinfo': False}]}
  29. def post_load():
  30. BaseModel.load = load_import_optional