Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX]do not delete module version if already exists and just update #30

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion github_connector_odoo/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
'name': 'Github Connector - Odoo',
'summary': 'Analyze Odoo modules information from Github repositories',
'version': '11.0.1.2.0',
'version': '11.0.1.2.1',
'category': 'Connector',
'license': 'AGPL-3',
'author': 'Odoo Community Association (OCA), Sylvain LE GAL, GRAP',
Expand All @@ -28,6 +28,7 @@
'views/view_github_repository_branch.xml',
'data/odoo_licence.xml',
'data/odoo_category_data.xml',
'data/ir_cron.xml',
],
'demo': [
'demo/github_organization.xml',
Expand Down
22 changes: 22 additions & 0 deletions github_connector_odoo/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016-Today: Odoo Community Association (OCA)
@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 model="ir.cron" id="cron_clean_odoo_module_version">
<field name="name">Clean Odoo Module Version</field>
<field name="interval_number">1</field>
<field name="active" eval="False"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="state">code</field>
<field name="model_id" ref="model_odoo_module_version"/>
<field name="code">model.cron_clean_odoo_module_version()</field>
</record>

</odoo>
29 changes: 14 additions & 15 deletions github_connector_odoo/models/github_repository_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ def _set_state_to_analyze(self):
branches = self.search([('state', '=', 'analyzed')])
branches.write({'state': 'to_analyze'})

@api.multi
def _get_module_paths(self):
# Compute path(s) to analyze
self.ensure_one()
if self.module_paths:
paths = []
for path in self.module_paths.split('\n'):
if path.strip():
paths.append(os.path.join(self.local_path, path))
else:
paths = [self.local_path]
return paths

@api.model
def analyze_code_one(self, branch):
# Change log level to avoid warning, when parsing odoo manifests
Expand All @@ -83,21 +96,7 @@ def analyze_code_one(self, branch):
logger2.setLevel(logging.ERROR)

try:
module_version_obj = self.env['odoo.module.version']
# Delete all associated module versions
module_versions = module_version_obj.search([
('repository_branch_id', '=', branch.id)])
module_versions.with_context(
dont_change_repository_branch_state=True).unlink()

# Compute path(s) to analyze
if branch.module_paths:
paths = []
for path in branch.module_paths.split('\n'):
if path.strip():
paths.append(os.path.join(branch.local_path, path))
else:
paths = [branch.local_path]
paths = branch._get_module_paths()

# Scan each path, if exists
for path in paths:
Expand Down
27 changes: 27 additions & 0 deletions github_connector_odoo/models/odoo_module_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,30 @@ def create_or_update_from_manifest(
except Exception as e:
_logger.error(
'Unable to read the OCA icon image, error is %s' % e)

@api.model
def cron_clean_odoo_module_version(self):
module_versions = self.search([])
module_versions.clean_odoo_module_version()

@api.multi
def clean_odoo_module_version(self):
for module_version in self:
# Compute path(s) to analyze
paths = module_version.repository_branch_id._get_module_paths()
found = False
for path in paths:
module_ver_path = os.path.join(
path, module_version.technical_name)
if os.path.exists(module_ver_path):
found = True
continue
if not found:
module_version._process_clean_module_version()
return True

@api.multi
def _process_clean_module_version(self):
for module_version in self:
module_version.unlink()
return True