From 464af881bf9915514f21cbc03f0537ab7355a0e6 Mon Sep 17 00:00:00 2001 From: Vo Minh Thu Date: Mon, 25 Mar 2013 14:12:45 +0100 Subject: [PATCH] [IMP] netsvc: LocalService deprecation now guarded via openerp.conf.deprecation. bzr revid: vmt@openerp.com-20130325131245-9o5uizn6v4r8irc3 --- openerp/conf/deprecation.py | 12 ++++++++++++ openerp/netsvc.py | 3 ++- openerp/report/report_sxw.py | 11 +++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/openerp/conf/deprecation.py b/openerp/conf/deprecation.py index 11399bef4fb..fec2fbbf224 100644 --- a/openerp/conf/deprecation.py +++ b/openerp/conf/deprecation.py @@ -26,6 +26,8 @@ additional code is needed throughout the core library. This module keeps track of those specific measures by providing variables that can be unset by the user to check if her code is future proof. +In a perfect world, all these variables are set to False, the corresponding +code removed, and thus these variables made unnecessary. """ # If True, the Python modules inside the openerp namespace are made available @@ -35,4 +37,14 @@ by the user to check if her code is future proof. # Change to False around 2013.02. open_openerp_namespace = False +# If True, openerp.netsvc.LocalService() can be used to lookup reports or to +# access openerp.workflow. +# Introduced around 2013.03. +# Among the related code: +# - The openerp.netsvc.LocalService() function. +# - The openerp.report.interface.report_int._reports dictionary. +# - The register attribute in openerp.report.report_sxw (and in its inheriting +# classes). +allow_local_service = True + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/openerp/netsvc.py b/openerp/netsvc.py index 4ad2d24ddb2..799fd74158b 100644 --- a/openerp/netsvc.py +++ b/openerp/netsvc.py @@ -52,7 +52,8 @@ def LocalService(name): openerp.report.render_report() should be used (methods on the Model should be provided too in the future). """ - _logger.warning("LocalService('%s') is deprecated." % name) + assert openerp.conf.deprecation.allow_local_service + _logger.warning("LocalService() is deprecated since march 2013 (it was called with '%s')." % name) if name == 'workflow': return openerp.workflow diff --git a/openerp/report/report_sxw.py b/openerp/report/report_sxw.py index 0e2a7e18edd..b0fb70513bb 100644 --- a/openerp/report/report_sxw.py +++ b/openerp/report/report_sxw.py @@ -388,6 +388,17 @@ class rml_parse(object): self.setCompany(objects[0].company_id) class report_sxw(report_rml, preprocess.report): + """ + The register=True kwarg has been added to help remove the + openerp.netsvc.LocalService() indirection and the related + openerp.report.interface.report_int._reports dictionary: + report_sxw registered in XML with auto=False are also registered in Python. + In that case, they are registered in the above dictionary. Since + registration is automatically done upon instanciation, and that + instanciation is needed before rendering, a way was needed to + instanciate-without-register a report. In the future, no report + should be registered in the above dictionary and it will be dropped. + """ def __init__(self, name, table, rml=False, parser=rml_parse, header='external', store=False, register=True): report_rml.__init__(self, name, table, rml, '', register=register) self.name = name