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.

73 lines
3.0 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Module - Parent Dependencies module for Odoo
  5. # Copyright (C) 2014 GRAP (http://www.grap.coop)
  6. # @author Sylvain LE GAL (https://twitter.com/legalsylvain)
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp.osv.orm import Model
  23. from openerp.osv import fields
  24. class module(Model):
  25. _inherit = 'ir.module.module'
  26. # Field function Section
  27. def _get_all_installed_parent_ids(
  28. self, cr, uid, ids, field_name, arg, context=None):
  29. res = self._get_direct_installed_parent_ids(
  30. cr, uid, ids, field_name, arg, context=context)
  31. for id in ids:
  32. parent_ids = list(res[id])
  33. undirect_parent_ids = self._get_all_installed_parent_ids(
  34. cr, uid, res[id], field_name, arg, context=context)
  35. for parent_id in parent_ids:
  36. res[id] += undirect_parent_ids[parent_id]
  37. res[id] = list(set(res[id]))
  38. return res
  39. def _get_direct_installed_parent_ids(
  40. self, cr, uid, ids, field_name, arg, context=None):
  41. res = {}
  42. imd_obj = self.pool['ir.module.module.dependency']
  43. for imm in self.browse(cr, uid, ids, context=context):
  44. imd_ids = imd_obj.search(
  45. cr, uid, [('name', '=', imm.name)], context=context)
  46. tmp = imd_obj.read(
  47. cr, uid, imd_ids, ['module_id'], context=context)
  48. imm_ids = [x['module_id'][0] for x in tmp]
  49. # Select only non uninstalled module
  50. imm_ids = self.search(
  51. cr, uid, [
  52. ('id', 'in', imm_ids),
  53. ('state', 'not in', ['uninstalled', 'uninstallable'])],
  54. context=context)
  55. res[imm.id] = imm_ids
  56. return res
  57. # Column Section
  58. _columns = {
  59. 'direct_installed_parent_ids': fields.function(
  60. _get_direct_installed_parent_ids, type='many2many',
  61. relation='ir.module.module',
  62. string='Direct Parent Installed Modules'),
  63. 'all_installed_parent_ids': fields.function(
  64. _get_all_installed_parent_ids, type='many2many',
  65. relation='ir.module.module',
  66. string='Direct and Indirect Parent Installed Modules'),
  67. }