[FIX+IMP] module_analysis : remove analysis when updating modules, because the analysis is partial (it also make the update slower) ; Add instead a cron task that is executed nightly to update analysis automatically

pull/2608/head
Sylvain LE GAL 2021-03-30 11:32:04 +02:00 committed by Florian da Costa
parent acdd3c2773
commit deabde4b8f
6 changed files with 50 additions and 13 deletions

View File

@ -20,11 +20,14 @@
"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",
],
"external_dependencies": {"python": ["pygount"]},
"external_dependencies": {
"python": ["pygount"],
},
"post_init_hook": "analyse_installed_modules",
"installable": True,
}

View File

@ -0,0 +1,20 @@
<?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>

View File

@ -79,14 +79,12 @@ class IrModuleModule(models.Model):
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
def write(self, vals):
res = super().write(vals)
if vals.get("state", False) == "installed":
self.button_analyse_code()
elif vals.get("state", False) == "uninstalled" and "module_analysis" not in [
if vals.get("state", False) == "uninstalled" and "module_analysis" not in [
x.name for x in self
]:
self.write(self._get_clean_analyse_values())
@ -94,6 +92,14 @@ class IrModuleModule(models.Model):
# Public Section
def button_analyse_code(self):
self._analyse_code()
@api.model
def cron_analyse_code(self):
self.search([("state", "=", "installed")])._analyse_code()
# Custom Section
def _analyse_code(self):
IrModuleAuthor = self.env["ir.module.author"]
IrModuleTypeRule = self.env["ir.module.type.rule"]
rules = IrModuleTypeRule.search([])
@ -150,7 +156,6 @@ class IrModuleModule(models.Model):
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

View File

@ -6,6 +6,9 @@ from odoo import SUPERUSER_ID, api
def analyse_installed_modules(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
installed_modules = env["ir.module.module"].search([("state", "=", "installed")])
installed_modules.button_analyse_code()
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
installed_modules = env["ir.module.module"].search(
["|", ("state", "=", "installed"), ("name", "=", "module_analysis")]
)
installed_modules.button_analyse_code()

View File

@ -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'
@ -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
~~~~~~~~~~~~~~~~~

View File

@ -2,11 +2,11 @@
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests import tagged
from odoo.tests.common import TransactionCase
from odoo.tests.common import TransactionCase, at_install, post_install
@tagged("post_install", "-at_install")
@at_install(False)
@post_install(True)
class TestModule(TransactionCase):
def setUp(self):
super().setUp()