Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check attribute without translation parameter (OCA#104) #105

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pylint_odoo/checkers/modules_odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,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 @@ -811,3 +816,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 @@ -385,7 +385,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 @@ -398,9 +398,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 @@ -58,6 +58,7 @@
'xml-syntax-error': 2,
'renamed-field-parameter': 2,
'attribute-string-redundant': 33,
'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