Skip to content

Commit

Permalink
[ADD] xml-attribute-translatable: Check XML attribute without transla…
Browse files Browse the repository at this point in the history
…tion parameter (#105)

Close #104
  • Loading branch information
Jesus Zapata authored and moylop260 committed Jan 26, 2017
1 parent 7c28b0b commit 58dc5ae
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
20 changes: 20 additions & 0 deletions pylint_odoo/checkers/modules_odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
'missing-manifest-dependency',
settings.DESC_DFLT
),
'W%d37' % settings.BASE_OMODULE_ID: (
'%s The xml attribute is missing the translation="off" tag %s',
'xml-attribute-translatable',
settings.DESC_DFLT
),
}


Expand Down Expand Up @@ -706,3 +711,18 @@ def _check_file_not_used(self):
if self.msg_args:
return False
return True

def _check_xml_attribute_translatable(self):
"""The xml attribute is missing the translation="off" tag
Example <attribute name="groups">sale.group</attribute>
"""
self.msg_args = []
for xml_file in self.filter_files_ext('xml', relpath=True):
for record in self.get_xml_records(
os.path.join(self.module_path, xml_file), None,
'//attribute[not(@translation)]'):
self.msg_args.append(
("%s:%d" % (xml_file, record.sourceline), 'xml_id'))
if self.msg_args:
return False
return True
10 changes: 7 additions & 3 deletions pylint_odoo/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def parse_xml(self, xml_file):
return xmlsyntax_error_exception.message
return doc

def get_xml_records(self, xml_file, model=None):
def get_xml_records(self, xml_file, model=None, more=None):
"""Get tag `record` of a openerp xml file.
:param xml_file: Path of file xml
:param model: String with record model to filter.
Expand All @@ -282,9 +282,13 @@ def get_xml_records(self, xml_file, model=None):
model_filter = ''
else:
model_filter = "[@model='{model}']".format(model=model)
if more is None:
more_filter = ''
else:
more_filter = more
doc = self.parse_xml(xml_file)
return doc.xpath("/openerp//record" + model_filter) + \
doc.xpath("/odoo//record" + model_filter) \
return doc.xpath("/openerp//record" + model_filter + more_filter) + \
doc.xpath("/odoo//record" + model_filter + more_filter) \
if not isinstance(doc, basestring) else []

def get_field_csv(self, csv_file, field='id'):
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 @@ -55,6 +55,7 @@
'wrong-tabs-instead-of-spaces': 2,
'eval-referenced': 5,
'xml-syntax-error': 2,
'xml-attribute-translatable': 1,
}


Expand Down
4 changes: 4 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 @@ -25,6 +25,10 @@
<field name="partner_id"/>
<field name="user_id"/>
</xpath>
<xpath expr="//field[@name='description']" position="attributes">
<attribute name="colors">red</attribute>
<attribute name="colors" translation="off">red</attribute>
</xpath>
</field>
</record>

Expand Down

0 comments on commit 58dc5ae

Please sign in to comment.