diff --git a/module_parent_dependencies/__init__.py b/module_parent_dependencies/__init__.py new file mode 100644 index 000000000..ff4216998 --- /dev/null +++ b/module_parent_dependencies/__init__.py @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Module - Parent Dependencies module for Odoo +# Copyright (C) 2014 GRAP (http://www.grap.coop) +# @author Sylvain LE GAL (https://twitter.com/legalsylvain) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import model diff --git a/module_parent_dependencies/__openerp__.py b/module_parent_dependencies/__openerp__.py new file mode 100644 index 000000000..da628ca3e --- /dev/null +++ b/module_parent_dependencies/__openerp__.py @@ -0,0 +1,54 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Module - Parent Dependencies module for Odoo +# Copyright (C) 2014 GRAP (http://www.grap.coop) +# @author Sylvain LE GAL (https://twitter.com/legalsylvain) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +{ + 'name': 'Parent Dependencies of Modules', + 'version': '0.1', + 'summary': 'Display the parent dependencies of a module', + 'category': 'Tools', + 'description': """ +Display the parent dependencies of a module +=========================================== + +Functionality: +-------------- + * This module display to the admin user, the possibility to see the list""" + """ of the modules that depends (directly or indirectly) on a module. + +Copyright, Authors and Licence: +------------------------------- + * Copyright: 2014, GRAP: Groupement Régional Alimentaire de Proximité; + * Author: Sylvain LE GAL (https://twitter.com/legalsylvain); + * Licence: AGPL-3 (http://www.gnu.org/licenses/);""", + 'author': 'GRAP', + 'website': 'http://www.grap.coop', + 'license': 'AGPL-3', + 'depends': [ + 'base', + ], + 'data': [ + 'view/view.xml', + ], + 'images': [ + 'static/src/img/screenshots/dependencies_list.jpg' + ], +} diff --git a/module_parent_dependencies/i18n/fr.po b/module_parent_dependencies/i18n/fr.po new file mode 100644 index 000000000..1649b2a64 --- /dev/null +++ b/module_parent_dependencies/i18n/fr.po @@ -0,0 +1,41 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * module_parent_dependencies +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-07-09 15:55+0000\n" +"PO-Revision-Date: 2014-07-09 15:55+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: module_parent_dependencies +#: view:ir.module.module:0 +#: field:ir.module.module,direct_parent_ids:0 +msgid "Direct Parent Modules" +msgstr "Modules Parents Directs" + +#. module: module_parent_dependencies +#: view:ir.module.module:0 +#: field:ir.module.module,all_parent_ids:0 +msgid "Direct and Indirect Parent Modules" +msgstr "Modules Parents Directs et Indirectes" + +#. module: module_parent_dependencies +#: code:_description:0 +#: model:ir.model,name:module_parent_dependencies.model_ir_module_module +#, python-format +msgid "Module" +msgstr "Module" + +#. module: module_parent_dependencies +#: view:ir.module.module:0 +msgid "Parent informations" +msgstr "Informations relatives aux modules parents" + diff --git a/module_parent_dependencies/model/__init__.py b/module_parent_dependencies/model/__init__.py new file mode 100644 index 000000000..9522bfc7e --- /dev/null +++ b/module_parent_dependencies/model/__init__.py @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Module - Parent Dependencies module for Odoo +# Copyright (C) 2014 GRAP (http://www.grap.coop) +# @author Sylvain LE GAL (https://twitter.com/legalsylvain) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import ir_module_module diff --git a/module_parent_dependencies/model/ir_module_module.py b/module_parent_dependencies/model/ir_module_module.py new file mode 100755 index 000000000..c3a6e1941 --- /dev/null +++ b/module_parent_dependencies/model/ir_module_module.py @@ -0,0 +1,72 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Module - Parent Dependencies module for Odoo +# Copyright (C) 2014 GRAP (http://www.grap.coop) +# @author Sylvain LE GAL (https://twitter.com/legalsylvain) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.osv.orm import Model +from openerp.osv import fields + + +class module(Model): + _inherit = 'ir.module.module' + + # Field function Section + def _get_all_parent_ids( + self, cr, uid, ids, field_name, arg, context=None): + res = self._get_direct_parent_ids( + cr, uid, ids, field_name, arg, context=context) + for id in ids: + parent_ids = list(res[id]) + undirect_parent_ids = self._get_all_parent_ids( + cr, uid, res[id], field_name, arg, context=context) + for parent_id in parent_ids: + res[id] += undirect_parent_ids[parent_id] + res[id] = list(set(res[id])) + return res + + def _get_direct_parent_ids( + self, cr, uid, ids, field_name, arg, context=None): + res = {} + imd_obj = self.pool['ir.module.module.dependency'] + for imm in self.browse(cr, uid, ids, context=context): + imd_ids = imd_obj.search( + cr, uid, [('name', '=', imm.name)], context=context) + tmp = imd_obj.read( + cr, uid, imd_ids, ['module_id'], context=context) + imm_ids = [x['module_id'][0] for x in tmp] + # Select only non uninstalled module + imm_ids = self.search( + cr, uid, [ + ('id', 'in', imm_ids), + ('state', 'not in', ['uninstalled', 'uninstallable'])], + context=context) + res[imm.id] = imm_ids + return res + + # Column Section + _columns = { + 'direct_parent_ids': fields.function( + _get_direct_parent_ids, type='many2many', + relation='ir.module.module', string='Direct Parent Modules'), + 'all_parent_ids': fields.function( + _get_all_parent_ids, type='many2many', + relation='ir.module.module', + string='Direct and Indirect Parent Modules'), + } diff --git a/module_parent_dependencies/static/src/img/icon.png b/module_parent_dependencies/static/src/img/icon.png new file mode 100644 index 000000000..ee9cbdfa6 Binary files /dev/null and b/module_parent_dependencies/static/src/img/icon.png differ diff --git a/module_parent_dependencies/static/src/img/screenshots/dependencies_list.jpg b/module_parent_dependencies/static/src/img/screenshots/dependencies_list.jpg new file mode 100644 index 000000000..a7ed83f86 Binary files /dev/null and b/module_parent_dependencies/static/src/img/screenshots/dependencies_list.jpg differ diff --git a/module_parent_dependencies/tests/__init__.py b/module_parent_dependencies/tests/__init__.py new file mode 100644 index 000000000..f62e1c07b --- /dev/null +++ b/module_parent_dependencies/tests/__init__.py @@ -0,0 +1,24 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Module - Parent Dependencies module for OpenERP +# Copyright (C) 2014 GRAP (http://www.grap.coop) +# @author Sylvain LE GAL (https://twitter.com/legalsylvain) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + + +from . import test_module_parent_dependencies diff --git a/module_parent_dependencies/tests/test_module_parent_dependencies.py b/module_parent_dependencies/tests/test_module_parent_dependencies.py new file mode 100644 index 000000000..830eae660 --- /dev/null +++ b/module_parent_dependencies/tests/test_module_parent_dependencies.py @@ -0,0 +1,65 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Database Integrity module for OpenERP +# Copyright (C) 2014 GRAP (http://www.grap.coop) +# @author Sylvain LE GAL (https://twitter.com/legalsylvain) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.tests.common import TransactionCase + + +class TestmoduleParentDependencies(TransactionCase): + """Tests for 'DataBase Integrity' Module""" + + def setUp(self): + super(TestmoduleParentDependencies, self).setUp() + self.im_obj = self.registry('ir.module.module') + + # Test Section + def test_01_direct_parent(self): + """Test if the compute of the field direct_parent_ids is correct.""" + cr, uid = self.cr, self.uid + # compute expected values + cr.execute("""SELECT module_id + FROM ir_module_module_dependency immd + INNER JOIN ir_module_module imm on imm.id = immd.module_id + WHERE immd.name='base' + AND imm.state not in ('uninstalled', 'uninstallable')""") + expected_parent_ids = [x[0] for x in cr.fetchall()] + + # Get values + base_id = self.im_obj.search(cr, uid, [('name', '=', 'base')]) + tmp = self.im_obj.browse( + cr, uid, base_id) + parent_ids = [x.id for x in tmp[0].direct_parent_ids] + + self.assertEqual( + sorted(parent_ids), sorted(expected_parent_ids), + "Incorrect computation of 'direct_parent_id's fields.") + + def test_02_all_parent(self): + """Test if the compute of the field direct_parent_ids doesn't crash.""" + cr, uid = self.cr, self.uid + base_id = self.im_obj.search(cr, uid, [('name', '=', 'base')]) + tmp = self.im_obj.browse( + cr, uid, base_id) + parent_ids = [x.id for x in tmp[0].all_parent_ids] + + self.assertNotEqual( + sorted(parent_ids), [], + "Incorrect computation of 'direct_parent_id's fields.") diff --git a/module_parent_dependencies/view/view.xml b/module_parent_dependencies/view/view.xml new file mode 100644 index 000000000..533dc0bf1 --- /dev/null +++ b/module_parent_dependencies/view/view.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + ir.module.module.form + ir.module.module + + + + + + + + + + + + + + +