Skip to content

Commit 58dc5ae

Browse files
Jesus Zapatamoylop260
authored andcommitted
[ADD] xml-attribute-translatable: Check XML attribute without translation parameter (#105)
Close #104
1 parent 7c28b0b commit 58dc5ae

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

pylint_odoo/checkers/modules_odoo.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@
117117
'missing-manifest-dependency',
118118
settings.DESC_DFLT
119119
),
120+
'W%d37' % settings.BASE_OMODULE_ID: (
121+
'%s The xml attribute is missing the translation="off" tag %s',
122+
'xml-attribute-translatable',
123+
settings.DESC_DFLT
124+
),
120125
}
121126

122127

@@ -706,3 +711,18 @@ def _check_file_not_used(self):
706711
if self.msg_args:
707712
return False
708713
return True
714+
715+
def _check_xml_attribute_translatable(self):
716+
"""The xml attribute is missing the translation="off" tag
717+
Example <attribute name="groups">sale.group</attribute>
718+
"""
719+
self.msg_args = []
720+
for xml_file in self.filter_files_ext('xml', relpath=True):
721+
for record in self.get_xml_records(
722+
os.path.join(self.module_path, xml_file), None,
723+
'//attribute[not(@translation)]'):
724+
self.msg_args.append(
725+
("%s:%d" % (xml_file, record.sourceline), 'xml_id'))
726+
if self.msg_args:
727+
return False
728+
return True

pylint_odoo/misc.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def parse_xml(self, xml_file):
269269
return xmlsyntax_error_exception.message
270270
return doc
271271

272-
def get_xml_records(self, xml_file, model=None):
272+
def get_xml_records(self, xml_file, model=None, more=None):
273273
"""Get tag `record` of a openerp xml file.
274274
:param xml_file: Path of file xml
275275
:param model: String with record model to filter.
@@ -282,9 +282,13 @@ def get_xml_records(self, xml_file, model=None):
282282
model_filter = ''
283283
else:
284284
model_filter = "[@model='{model}']".format(model=model)
285+
if more is None:
286+
more_filter = ''
287+
else:
288+
more_filter = more
285289
doc = self.parse_xml(xml_file)
286-
return doc.xpath("/openerp//record" + model_filter) + \
287-
doc.xpath("/odoo//record" + model_filter) \
290+
return doc.xpath("/openerp//record" + model_filter + more_filter) + \
291+
doc.xpath("/odoo//record" + model_filter + more_filter) \
288292
if not isinstance(doc, basestring) else []
289293

290294
def get_field_csv(self, csv_file, field='id'):

pylint_odoo/test/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
'wrong-tabs-instead-of-spaces': 2,
5656
'eval-referenced': 5,
5757
'xml-syntax-error': 2,
58+
'xml-attribute-translatable': 1,
5859
}
5960

6061

pylint_odoo/test_repo/broken_module/model_view_odoo2.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
<field name="partner_id"/>
2626
<field name="user_id"/>
2727
</xpath>
28+
<xpath expr="//field[@name='description']" position="attributes">
29+
<attribute name="colors">red</attribute>
30+
<attribute name="colors" translation="off">red</attribute>
31+
</xpath>
2832
</field>
2933
</record>
3034

0 commit comments

Comments
 (0)