Browse Source

fixup! fixup! fixup! fixup! [ADD] new module module_analysis

12.0
Sylvain LE GAL 5 years ago
committed by OCA-git-bot
parent
commit
6fa3d047c9
  1. 19
      module_analysis/__init__.py
  2. 2
      module_analysis/__manifest__.py
  3. 15
      module_analysis/models/ir_module_author.py
  4. 6
      module_analysis/models/ir_module_module.py
  5. 3
      module_analysis/models/ir_module_type.py
  6. 13
      module_analysis/post_init_hook.py
  7. 1
      module_analysis/tests/__init__.py
  8. 31
      module_analysis/tests/test_module.py
  9. 2
      module_analysis/views/view_ir_module_author.xml

19
module_analysis/__init__.py

@ -1,19 +1,2 @@
from . import models from . import models
# Copyright 2016-2018 Akretion France
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, SUPERUSER_ID
def post_init_hook(cr, registry):
"""This post_install script is required because, when the module
is installed, Odoo creates the column in the DB and compute the field
and THEN it loads the file data/res_country_department_data.yml...
So, when it computes the field on module installation, the
departments are not available in the DB, so the department_id field
on res.partner stays null. This post_install script fixes this."""
print("=====================")
print("=====================")
print("=====================")
from . post_init_hook import analyse_installed_modules

2
module_analysis/__manifest__.py

@ -29,6 +29,6 @@
'external_dependencies': { 'external_dependencies': {
'lib': ['cloc'], 'lib': ['cloc'],
}, },
'post_init_hook': 'post_init_hook',
'post_init_hook': 'analyse_installed_modules',
'installable': True, 'installable': True,
} }

15
module_analysis/models/ir_module_author.py

@ -12,15 +12,12 @@ class IrModuleAuthor(models.Model):
name = fields.Char(string='Name', required=True) name = fields.Char(string='Name', required=True)
module_ids = fields.Many2many( module_ids = fields.Many2many(
string='Modules', comodel_name='ir.module.module')
module_qty = fields.Integer(
string="Modules Quantity",
compute='_compute_modules', store=True)
string='Modules', comodel_name='ir.module.module',
relation='ir_module_module_author_rel')
installed_module_qty = fields.Integer( installed_module_qty = fields.Integer(
string="Installed Modules Quantity", string="Installed Modules Quantity",
compute='_compute_modules', store=True)
compute='_compute_installed_module_qty', store=True)
_sql_constraints = [ _sql_constraints = [
('name_uniq', 'unique(name)', ('name_uniq', 'unique(name)',
@ -29,11 +26,9 @@ class IrModuleAuthor(models.Model):
@api.multi @api.multi
@api.depends('module_ids') @api.depends('module_ids')
def _compute_modules(self):
def _compute_installed_module_qty(self):
for author in self: for author in self:
author.module_qty = len(author.module_ids)
author.installed_module_qty = len(
author.module_ids.filtered(lambda x: x.state == 'installed'))
author.installed_module_qty = len(author.module_ids)
@api.model @api.model
def _get_or_create(self, name): def _get_or_create(self, name):

6
module_analysis/models/ir_module_module.py

@ -18,7 +18,8 @@ class IrModuleModule(models.Model):
_inherit = 'ir.module.module' _inherit = 'ir.module.module'
author_ids = fields.Many2many( author_ids = fields.Many2many(
string='Authors', comodel_name='ir.module.author', readonly=True)
string='Authors', comodel_name='ir.module.author', readonly=True,
relation='ir_module_module_author_rel')
module_type_id = fields.Many2one( module_type_id = fields.Many2one(
string='Module Type', comodel_name='ir.module.type', readonly=True) string='Module Type', comodel_name='ir.module.type', readonly=True)
@ -43,7 +44,8 @@ class IrModuleModule(models.Model):
res = super(IrModuleModule, self).write(vals) res = super(IrModuleModule, self).write(vals)
if vals.get('state', False) == 'installed': if vals.get('state', False) == 'installed':
self.button_analyze_code() self.button_analyze_code()
elif vals.get('state', False) == 'uninstalled':
elif vals.get('state', False) == 'uninstalled'\
and 'module_analysis' not in [x.name for x in self]:
self.write({ self.write({
'author_ids': [6, 0, []], 'author_ids': [6, 0, []],
'module_type_id': False, 'module_type_id': False,

3
module_analysis/models/ir_module_type.py

@ -8,9 +8,12 @@ from odoo import api, fields, models
class IrModuleType(models.Model): class IrModuleType(models.Model):
_name = 'ir.module.type' _name = 'ir.module.type'
_description = 'Modules Types' _description = 'Modules Types'
_order = 'sequence'
name = fields.Char(string='Name', required=True) name = fields.Char(string='Name', required=True)
sequence = fields.Integer(string='Sequence')
module_ids = fields.One2many( module_ids = fields.One2many(
string='Modules', comodel_name='ir.module.module', string='Modules', comodel_name='ir.module.module',
inverse_name='module_type_id') inverse_name='module_type_id')

13
module_analysis/post_init_hook.py

@ -0,0 +1,13 @@
# Copyright (C) 2019-Today: GRAP (<http://www.grap.coop/>)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, SUPERUSER_ID
def analyse_installed_modules(cr, registry):
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
installed_modules = env['ir.module.module'].search(
[('state', '=', 'installed')])
installed_modules.button_analyze_code()

1
module_analysis/tests/__init__.py

@ -0,0 +1 @@
from . import test_module

31
module_analysis/tests/test_module.py

@ -0,0 +1,31 @@
# Copyright (C) 2019-Today: GRAP (<http://www.grap.coop/>)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase, post_install
@post_install(True)
class TestModule(TransactionCase):
def setUp(self):
super(TestModule, self).setUp()
self.IrModuleModule = self.env['ir.module.module']
def test_installed_modules(self):
installed_modules = self.IrModuleModule.search(
[('state', '=', 'installed')])
for module in installed_modules:
self.assertTrue(
module.python_lines_qty > 0,
"module '%s' doesn't have python lines defined, whereas it is"
" installed.")
def test_uninstalled_modules(self):
uninstalled_modules = self.IrModuleModule.search(
[('state', '!=', 'installed')])
for module in uninstalled_modules:
self.assertTrue(
module.python_lines_qty == 0,
"module '%s' has python lines defined, whereas it is"
" not installed.")

2
module_analysis/views/view_ir_module_author.xml

@ -18,7 +18,6 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
</div> </div>
<group> <group>
<field name="installed_module_qty"/> <field name="installed_module_qty"/>
<field name="module_qty"/>
</group> </group>
</sheet> </sheet>
</form> </form>
@ -32,7 +31,6 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<tree> <tree>
<field name="name"/> <field name="name"/>
<field name="installed_module_qty"/> <field name="installed_module_qty"/>
<field name="module_qty"/>
</tree> </tree>
</field> </field>
</record> </record>

Loading…
Cancel
Save