Skip to content

Commit

Permalink
[FIX+IMP] module_analysis : remove analysis when updating modules, be…
Browse files Browse the repository at this point in the history
…cause the analysis is partial (it also make the update slower) ; Add instead a cron task that is executed nightly to update analysis automatically
  • Loading branch information
legalsylvain committed Mar 30, 2021
1 parent 9c3677e commit 7413749
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
3 changes: 2 additions & 1 deletion module_analysis/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'version': '12.0.1.0.2',
'license': 'AGPL-3',
'depends': [
'base',
'base_automation',
],
'data': [
'security/ir.model.access.csv',
Expand All @@ -22,6 +22,7 @@
'views/view_ir_module_type.xml',
'views/view_ir_module_type_rule.xml',
'views/view_ir_module_module.xml',
'data/ir_cron.xml',
'data/ir_config_parameter.xml',
'data/ir_module_type.xml',
'data/ir_module_type_rule.xml',
Expand Down
21 changes: 21 additions & 0 deletions module_analysis/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2021-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).
-->

<odoo noupdate="1">
<record id="cron_module_analysis" model="ir.cron">
<field name="name">Update Module Analysis</field>
<field name="active" eval="True"/>
<field name="model_id" ref="base.model_ir_module_module"/>
<field name="state">code</field>
<field name="code">model.cron_analyse_code()</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="nextcall" eval="(DateTime.today()).strftime('%Y-%m-%d')"/>
<field name="numbercall">-1</field>
<field name="user_id" ref="base.user_root"/>
</record>
</odoo>
16 changes: 11 additions & 5 deletions module_analysis/models/ir_module_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,29 @@ def _get_module_encoding(self, file_ext):
def update_list(self):
res = super().update_list()
if self.env.context.get('analyse_installed_modules', False):
self.search([('state', '=', 'installed')]).button_analyse_code()
self.search([('state', '=', 'installed')])._analyse_code()
return res

@api.multi
def write(self, vals):
res = super().write(vals)
if vals.get('state', False) == 'installed':
self.button_analyse_code()
elif vals.get('state', False) == 'uninstalled'\
if vals.get('state', False) == 'uninstalled'\
and 'module_analysis' not in [x.name for x in self]:
self.write(self._get_clean_analyse_values())
return res

# Public Section
@api.multi
def button_analyse_code(self):
self._analyse_code()

@api.model
def cron_analyse_code(self):
self.search([('state', '=', 'installed')])._analyse_code()

# Custom Section
@api.multi
def _analyse_code(self):
IrModuleAuthor = self.env['ir.module.author']
IrModuleTypeRule = self.env['ir.module.type.rule']
rules = IrModuleTypeRule.search([])
Expand Down Expand Up @@ -158,7 +165,6 @@ def button_analyse_code(self):
values[v['field']] = v['value']
module.write(values)

# Custom Section
@api.model
def _get_files_to_analyse(
self, path, file_extensions, exclude_directories, exclude_files):
Expand Down
5 changes: 3 additions & 2 deletions module_analysis/post_init_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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 = env['ir.module.module'].search([
'|', ('state', '=', 'installed'), ('name', '=', 'module_analysis')
])
installed_modules.button_analyse_code()
8 changes: 7 additions & 1 deletion module_analysis/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ developped for exemple,
.. image:: ../static/description/add_module_type_rules.png


to update the data, you have to :
to update the data manually, you have to :

* Go to 'Apps' / 'Update Apps List'

Expand All @@ -24,6 +24,12 @@ to update the data, you have to :

This will update analysis of your installed modules.

to update the data automatically, you have to :

* Go to 'Settings' / 'Technical' / 'Scheduled Actions'

* Configure the action 'Update Module Analysis'. (By default, the analysis will be done nightly)


Adding Extra data
~~~~~~~~~~~~~~~~~
Expand Down
3 changes: 2 additions & 1 deletion module_analysis/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# @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
from odoo.tests.common import TransactionCase, at_install, post_install


@at_install(False)
@post_install(True)
class TestModule(TransactionCase):

Expand Down

0 comments on commit 7413749

Please sign in to comment.