From bfb9de411468fc917007fa550b74dfb8545df139 Mon Sep 17 00:00:00 2001 From: JesusZapata Date: Fri, 13 Jan 2017 19:23:12 +0000 Subject: [PATCH] [IMP] pylint-odoo: Check attribute without translation parameter (OCA#104) [FIX] pylint-odoo: Fix pep8 [FIX] pylint-odoo: Improving conditions and optimizing [FIX] pylint-odoo: Delete unnecessary test method [IMP] pylint-odoo: New parameter to method get_xml_records [FIX] pylint-odoo: Fix pep8 standar --- pylint_odoo/checkers/modules_odoo.py | 20 +++++++++++++++++++ pylint_odoo/misc.py | 10 +++++++--- pylint_odoo/test/main.py | 1 + .../broken_module/model_view_odoo2.xml | 4 ++++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/pylint_odoo/checkers/modules_odoo.py b/pylint_odoo/checkers/modules_odoo.py index 0dd127b7..709b6dbd 100644 --- a/pylint_odoo/checkers/modules_odoo.py +++ b/pylint_odoo/checkers/modules_odoo.py @@ -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 + ), } @@ -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 sale.group + """ + 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 diff --git a/pylint_odoo/misc.py b/pylint_odoo/misc.py index af1b6c40..5c905834 100644 --- a/pylint_odoo/misc.py +++ b/pylint_odoo/misc.py @@ -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. @@ -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'): diff --git a/pylint_odoo/test/main.py b/pylint_odoo/test/main.py index 04d4f297..01b512df 100644 --- a/pylint_odoo/test/main.py +++ b/pylint_odoo/test/main.py @@ -58,6 +58,7 @@ 'xml-syntax-error': 2, 'renamed-field-parameter': 2, 'attribute-string-redundant': 33, + 'xml-attribute-translatable': 1, } diff --git a/pylint_odoo/test_repo/broken_module/model_view_odoo2.xml b/pylint_odoo/test_repo/broken_module/model_view_odoo2.xml index 31d9e57e..49fd0191 100644 --- a/pylint_odoo/test_repo/broken_module/model_view_odoo2.xml +++ b/pylint_odoo/test_repo/broken_module/model_view_odoo2.xml @@ -25,6 +25,10 @@ + + red + red +