Skip to content

Commit

Permalink
[FIX] duplicate-xml-fields: False red using 2 tree sub-views *2M fiel…
Browse files Browse the repository at this point in the history
…ds (#96)
  • Loading branch information
moylop260 authored and pedrobaeza committed Dec 31, 2016
1 parent 9f1458a commit ab3e078
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
15 changes: 8 additions & 7 deletions pylint_odoo/checkers/modules_odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,13 @@ def _get_duplicate_xml_fields(self, fields):
field_xml = field.attrib.get('name')
if not field_xml:
continue
all_fields.setdefault(field_xml, []).append(field)
# Remove all keys which not duplicated
for key, items in all_fields.items():
if len(items) < 2:
all_fields.pop(key)
return all_fields
all_fields.setdefault(
(field_xml, field.getparent()), []).append(field)
# Remove all keys which not duplicated by excluding them from the
# returning dict
return dict(((field_xml_name, parent_node), nodes) for
(field_xml_name, parent_node), nodes in
all_fields.items() if len(nodes) >= 2)

def _check_duplicate_xml_fields(self):
"""Check duplicate field in all record of xml files of a odoo module.
Expand All @@ -506,7 +507,7 @@ def _check_duplicate_xml_fields(self):
for name, fobjs in self._get_duplicate_xml_fields(
record.xpath(xpath)).items():
self.msg_args.append((
"%s:%d" % (xml_file, fobjs[0].sourceline), name,
"%s:%d" % (xml_file, fobjs[0].sourceline), name[0],
', '.join([str(fobj.sourceline)
for fobj in fobjs[1:]]),
))
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 @@ -21,7 +21,7 @@
'dangerous-view-replace-wo-priority': 5,
'deprecated-openerp-xml-node': 5,
'duplicate-id-csv': 2,
'duplicate-xml-fields': 6,
'duplicate-xml-fields': 8,
'duplicate-xml-record-id': 2,
'file-not-used': 6,
'incoherent-interpreter-exec-perm': 3,
Expand Down
42 changes: 42 additions & 0 deletions pylint_odoo/test_repo/broken_module/model_view_odoo2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,47 @@
</field>
</record>

<!-- duplicate record field "name" in *2M field-->
<record id="view_model_form5" model="ir.ui.view">
<field name="name">view.model.form</field>
<field name="model">test.model</field>
<field name="arch" type="xml">
<form string="Test model6">
<field name="picking_ids">
<tree>
<field name="name"/>
</tree>
</field>
<field name="value_ids">
<tree>
<field name="name"/>
</tree>
</field>
</form>
</field>
</record>

<!-- duplicate record field "name" in *2M field-->
<record id="view_model_form6" model="ir.ui.view">
<field name="name">view.model.form</field>
<field name="model">test.model</field>
<field name="arch" type="xml">
<form string="Test model6">
<field name="picking_ids">
<tree>
<field name="name"/>
<field name="name"/>
</tree>
</field>
<field name="value_ids">
<tree>
<field name="name"/>
<field name="name"/>
</tree>
</field>
</form>
</field>
</record>

</data>
</odoo>

0 comments on commit ab3e078

Please sign in to comment.