Skip to content

Commit

Permalink
Merge 3bfc05f into 1ee7a91
Browse files Browse the repository at this point in the history
  • Loading branch information
moylop260 committed Sep 9, 2021
2 parents 1ee7a91 + 3bfc05f commit 2bdb81a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
21 changes: 18 additions & 3 deletions pylint_odoo/checkers/modules_odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,16 +853,31 @@ def _check_dangerous_view_replace_wo_priority(self):
"""
self.msg_args = []
xml_files = self.filter_files_ext('xml')
for xml_file in xml_files:
views = self.get_xml_records(
os.path.join(self.module_path, xml_file), model='ir.ui.view')
for xml_file in self._skip_files_ext('.xml', xml_files):
xml_file_path = os.path.join(self.module_path, xml_file)
views = self.get_xml_records(xml_file_path, model='ir.ui.view')
for view in views:
priority = self._get_priority(view)
is_replaced_field = self._is_replaced_field(view)
if is_replaced_field and priority < self.config.min_priority:
self.msg_args.append((
"%s:%s" % (xml_file, view.sourceline), priority,
self.config.min_priority))

# 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
Expand Down
2 changes: 1 addition & 1 deletion pylint_odoo/test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
'copy-wo-api-one': 2,
'create-user-wo-reset-password': 1,
'dangerous-filter-wo-user': 1,
'dangerous-view-replace-wo-priority': 6,
'dangerous-view-replace-wo-priority': 8,
'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 2bdb81a

Please sign in to comment.