Skip to content

Commit

Permalink
Merge 7a98bbd into 27ad80e
Browse files Browse the repository at this point in the history
  • Loading branch information
moylop260 committed Sep 10, 2021
2 parents 27ad80e + 7a98bbd commit e35f3d9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
34 changes: 34 additions & 0 deletions pylint_odoo/checkers/modules_odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
'dangerous-view-replace-wo-priority',
settings.DESC_DFLT
),
'W%d41' % settings.BASE_OMODULE_ID: (
'%s Dangerous use of "replace" from view '
'with priority %s < %s',
'dangerous-qweb-replace-wo-priority',
settings.DESC_DFLT
),
'W%d30' % settings.BASE_OMODULE_ID: (
'%s not used from manifest',
'file-not-used',
Expand Down Expand Up @@ -867,6 +873,34 @@ def _check_dangerous_view_replace_wo_priority(self):
return False
return True

def _check_dangerous_qweb_replace_wo_priority(self):
"""Check dangerous qweb view defined with low priority
:return: False if exists errors and
add list of errors in self.msg_args
"""
self.msg_args = []
xml_files = self.filter_files_ext('xml')
for xml_file in self._skip_files_ext('.xml', xml_files):
xml_file_path = os.path.join(self.module_path, xml_file)

# view template
xml_doc = self.parse_xml(xml_file_path)
for template in xml_doc.xpath("/odoo//template|/openerp//template"):
try:
priority = int(template.get('priority'))
except (ValueError, TypeError):
priority = 0
for child in template.iterchildren():
if (child.get('position') == 'replace' and
priority < self.config.min_priority):
self.msg_args.append((
"%s:%s" % (xml_file, template.sourceline), priority,
self.config.min_priority))
break
if self.msg_args:
return False
return True

def _check_create_user_wo_reset_password(self):
"""Check xml records of user without the context
'context="{'no_reset_password': True}"'
Expand Down
1 change: 1 addition & 0 deletions pylint_odoo/test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'create-user-wo-reset-password': 1,
'dangerous-filter-wo-user': 1,
'dangerous-view-replace-wo-priority': 6,
'dangerous-qweb-replace-wo-priority': 2,
'deprecated-openerp-xml-node': 5,
'development-status-allowed': 1,
'duplicate-id-csv': 2,
Expand Down
3 changes: 2 additions & 1 deletion pylint_odoo/test_repo/broken_module/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
'skip_xml_check.xml',
'skip_xml_check_2.xml',
'skip_xml_check_3.xml',
'report.xml'
'report.xml',
'template1.xml',
],
'demo': ['demo/duplicated_id_demo.xml', 'file_no_exist.xml'],
'test': ['file_no_exist.yml'],
Expand Down
28 changes: 28 additions & 0 deletions pylint_odoo/test_repo/broken_module/template1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="my_template1" inherit_id="module.template">
<xpath expr="//div[@role='search']" position="replace">
<form/>
</xpath>
<xpath expr="//div[@role='search']" position="replace"/>
</template>

<template id="my_template2" inherit_id="module.template" priority="110">
<xpath expr="//div[@role='search']" position="replace">
<form/>
</xpath>
<xpath expr="//div[@role='search']" position="replace"/>
</template>

<template id="my_template3" inherit_id="module.template">
<t t-set="address" position="replace"/>
</template>

<template id="my_template4" inherit_id="module.template" priority="110">
<t t-set="address" position="replace"/>
</template>

<template id="my_template5" inherit_id="module.template">
<t t-set="address"/>
</template>
</odoo>

0 comments on commit e35f3d9

Please sign in to comment.