From 4afe236b0c036f98d97a5d4bf30b630957599ef5 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Mon, 21 Jun 2010 17:36:32 +0300 Subject: [PATCH 001/696] safe_eval: fix wrt whitespace on expressions. Regular eval() would not care about leading whitespace. But, compile() would break if lines start with space. Strip that. Also, allow some exceptions to pass through, so that we can examine the syntax errors etc. bzr revid: p_christ@hol.gr-20100621143632-0hvrck77lterxjtl --- bin/tools/safe_eval.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/tools/safe_eval.py b/bin/tools/safe_eval.py index ef26fbc4cbe..d933c53d574 100644 --- a/bin/tools/safe_eval.py +++ b/bin/tools/safe_eval.py @@ -86,8 +86,14 @@ def test_expr(expr, allowed_codes, mode="eval"): return the compiled code object. Otherwise raise a ValueError. """ try: + if mode == 'eval': + expr = expr.strip() code_obj = compile(expr, "", mode) - except: + except SyntaxError: + raise + except TypeError: + raise + except Exception, e: raise ValueError("%s is not a valid expression" % expr) for code in _get_opcodes(code_obj): if code not in allowed_codes: From 1ee1886dcdd0a9492190cbe55495c66074d32c7d Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Mon, 21 Jun 2010 17:37:01 +0300 Subject: [PATCH 002/696] rml2pdf: Log stray exceptions, use special when expected. If the eval() raises an exception, we should log that. Unless it's the one we expect to see (thus changed to a special type), where we can keep silently ignoring it. Note: the GeneratorExit requires python 2.5 . bzr revid: p_christ@hol.gr-20100621143701-oenf5fp57qs1bxz4 --- bin/report/render/rml2pdf/utils.py | 12 ++++++++++++ bin/report/report_sxw.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bin/report/render/rml2pdf/utils.py b/bin/report/render/rml2pdf/utils.py index be8695e7eb3..9c781d302be 100644 --- a/bin/report/render/rml2pdf/utils.py +++ b/bin/report/render/rml2pdf/utils.py @@ -63,7 +63,10 @@ def _child_get(node, self=None, tagname=None): if n.get('rml_except', False): try: eval(n.get('rml_except'), {}, self.localcontext) + except GeneratorExit: + continue except: + logging.getLogger('report').exception() continue if n.get('rml_tag'): try: @@ -72,7 +75,10 @@ def _child_get(node, self=None, tagname=None): n2.tag = tag n2.attrib.update(attr) yield n2 + except GeneratorExit: + yield n except: + logging.getLogger('report').exception() yield n else: yield n @@ -81,7 +87,10 @@ def _child_get(node, self=None, tagname=None): if self and self.localcontext and n.get('rml_except'): try: eval(n.get('rml_except'), {}, self.localcontext) + except GeneratorExit: + continue except: + logging.getLogger('report').exception() continue if self and self.localcontext and n.get('rml_tag'): try: @@ -91,7 +100,10 @@ def _child_get(node, self=None, tagname=None): n2.attrib.update(attr or {}) yield n2 tagname = '' + except GeneratorExit: + pass except: + logging.getLogger('report').exception() pass if (tagname is None) or (n.tag==tagname): yield n diff --git a/bin/report/report_sxw.py b/bin/report/report_sxw.py index 9d2fb97362c..32857044cdd 100644 --- a/bin/report/report_sxw.py +++ b/bin/report/report_sxw.py @@ -192,7 +192,7 @@ class rml_parse(object): return text.strip() def removeParentNode(self, tag=None): - raise Exception('Skip') + raise GeneratorExit('Skip') def set_html_image(self,id,model=None,field=None,context=None): if not id : From 70e97c3e8b57bf942125b0c70490a76e42d00d39 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 22 Jun 2010 12:19:33 +0300 Subject: [PATCH 003/696] Base: remove ref to non-existent test file. bzr revid: p_christ@hol.gr-20100622091933-ngaqht6yzflb96fw --- bin/addons/base/__openerp__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/addons/base/__openerp__.py b/bin/addons/base/__openerp__.py index e595436d63f..8c8ed31cc36 100644 --- a/bin/addons/base/__openerp__.py +++ b/bin/addons/base/__openerp__.py @@ -76,7 +76,6 @@ 'test/base_test.xml', #'test/base_test.yml' 'test/test_context.xml', - 'bug_lp541545.xml', ], 'installable': True, 'active': True, From 1f16353c114c2abd2076107481d8e98bb85c7985 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 22 Jun 2010 12:19:58 +0300 Subject: [PATCH 004/696] HTTP lib: When authentication cannot proceed, issue 403 The http protocol states that 401 should only be used when further authentication would be possible bzr revid: p_christ@hol.gr-20100622091958-vkpa8wf3lbrt38s9 --- bin/service/websrv_lib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/service/websrv_lib.py b/bin/service/websrv_lib.py index c9576dc1701..5b346fd8853 100644 --- a/bin/service/websrv_lib.py +++ b/bin/service/websrv_lib.py @@ -208,7 +208,7 @@ class MultiHTTPHandler(FixSendError,BaseHTTPRequestHandler): except AuthRequiredExc,ae: if self.request_version != 'HTTP/1.1': self.log_error("Cannot require auth at %s",self.request_version) - self.send_error(401) + self.send_error(403) return self._get_ignore_body(fore) # consume any body that came, not loose sync with input self.send_response(401,'Authorization required') @@ -221,7 +221,7 @@ class MultiHTTPHandler(FixSendError,BaseHTTPRequestHandler): return except AuthRejectedExc,e: self.log_error("Rejected auth: %s" % e.args[0]) - self.send_error(401,e.args[0]) + self.send_error(403,e.args[0]) self.close_connection = 1 return mname = 'do_' + fore.command From 3c3833e824aa6fa0584c28df03c18db04de12c1f Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 22 Jun 2010 12:29:20 +0300 Subject: [PATCH 005/696] Logging: don't debug db, by default. bzr revid: p_christ@hol.gr-20100622092920-4q7eh8bp2vbg85b3 --- bin/netsvc.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/netsvc.py b/bin/netsvc.py index f0fe4687417..d2b6c564111 100644 --- a/bin/netsvc.py +++ b/bin/netsvc.py @@ -213,6 +213,11 @@ def init_logger(): # add the handler to the root logger logger.addHandler(handler) logger.setLevel(int(tools.config['log_level'] or '0')) + + # By default, don't log db connections, even at debug. + if int(tools.config['log_level'] or '0') <= logging.DEBUG: + logging.getLogger('db.connection').setLevel(logging.INFO) + logging.getLogger('db.connection_pool').setLevel(logging.INFO) From 285e307f256bfef4ccb198586fd9df32eb4e6d5f Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 22 Jun 2010 12:35:47 +0300 Subject: [PATCH 006/696] Logging: Allow rpc to set individual log levels. bzr revid: p_christ@hol.gr-20100622093547-jax4vg7vp0o6zfz2 --- bin/netsvc.py | 7 +++++-- bin/service/web_services.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bin/netsvc.py b/bin/netsvc.py index d2b6c564111..f3f86e958ed 100644 --- a/bin/netsvc.py +++ b/bin/netsvc.py @@ -268,8 +268,11 @@ class Logger(object): # better ignore the exception and carry on.. pass - def set_loglevel(self, level): - log = logging.getLogger() + def set_loglevel(self, level, *args): + if args and args[0]: + log = logging.getLogger(str(args[0])) + else: + log = logging.getLogger() log.setLevel(logging.INFO) # make sure next msg is printed log.info("Log level changed to %s" % logging.getLevelName(level)) log.setLevel(level) diff --git a/bin/service/web_services.py b/bin/service/web_services.py index 19b178c7caa..76f656d029c 100644 --- a/bin/service/web_services.py +++ b/bin/service/web_services.py @@ -556,9 +556,9 @@ GNU Public Licence. def exp_login_message(self): return tools.config.get('login_message', False) - def exp_set_loglevel(self,loglevel): + def exp_set_loglevel(self, loglevel, *args): l = netsvc.Logger() - l.set_loglevel(int(loglevel)) + l.set_loglevel(int(loglevel), *args) return True def exp_get_stats(self): From 09db16f52798562f02306c265102773a0222af29 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 22 Jun 2010 14:15:49 +0300 Subject: [PATCH 007/696] Logger: use optional kwargs instead of positional args. bzr revid: p_christ@hol.gr-20100622111549-sff9q43ahcihgq91 --- bin/netsvc.py | 6 +++--- bin/service/web_services.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/netsvc.py b/bin/netsvc.py index f3f86e958ed..97d94058df5 100644 --- a/bin/netsvc.py +++ b/bin/netsvc.py @@ -268,9 +268,9 @@ class Logger(object): # better ignore the exception and carry on.. pass - def set_loglevel(self, level, *args): - if args and args[0]: - log = logging.getLogger(str(args[0])) + def set_loglevel(self, level, logger=None): + if logger is not None: + log = logging.getLogger(str(logger)) else: log = logging.getLogger() log.setLevel(logging.INFO) # make sure next msg is printed diff --git a/bin/service/web_services.py b/bin/service/web_services.py index 76f656d029c..3536cf6bb5f 100644 --- a/bin/service/web_services.py +++ b/bin/service/web_services.py @@ -556,9 +556,9 @@ GNU Public Licence. def exp_login_message(self): return tools.config.get('login_message', False) - def exp_set_loglevel(self, loglevel, *args): + def exp_set_loglevel(self, loglevel, logger=None): l = netsvc.Logger() - l.set_loglevel(int(loglevel), *args) + l.set_loglevel(int(loglevel), logger) return True def exp_get_stats(self): From 6a14d2c377d078b537e1149bade27da972dcb69e Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Thu, 24 Jun 2010 18:58:50 +0530 Subject: [PATCH 008/696] [REF] just remove _get_comapny default from common report wizard bzr revid: mra@mra-laptop-20100624132850-80y3py2ti7m1rzm3 --- .../account/wizard/account_common_report.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/addons/account/wizard/account_common_report.py b/addons/account/wizard/account_common_report.py index d38adf1cbcd..d87956b77a9 100644 --- a/addons/account/wizard/account_common_report.py +++ b/addons/account/wizard/account_common_report.py @@ -36,7 +36,7 @@ class account_common_report(osv.osv_memory): 'period_from': fields.many2one('account.period', 'Start period'), 'period_to': fields.many2one('account.period', 'End period'), - #not used. Do we really need it? 'period_ids': fields.many2many('account.period', 'ledger_period_rel', 'ledger_id', 'period_id', 'Periods'), + #not used. Do we really need it? 'period_ids': fields.many2many('account.period', 'ledger_period_rel', 'ledger_id', 'period_id', 'Periods'), 'journal_ids': fields.many2many('account.journal', 'account_common_journal_rel', 'account_id', 'journal_id', 'Journals', required=True), @@ -53,16 +53,16 @@ class account_common_report(osv.osv_memory): #'company_id': fields.many2one('res.company', 'Company', required=True), } - def _get_company(self, cr, uid, context=None): - user_obj = self.pool.get('res.users') - company_obj = self.pool.get('res.company') - if context is None: - context = {} - user = user_obj.browse(cr, uid, uid, context=context) - if user.company_id: - return user.company_id.id - else: - return company_obj.search(cr, uid, [('parent_id', '=', False)])[0] +# def _get_company(self, cr, uid, context=None): +# user_obj = self.pool.get('res.users') +# company_obj = self.pool.get('res.company') +# if context is None: +# context = {} +# user = user_obj.browse(cr, uid, uid, context=context) +# if user.company_id: +# return user.company_id.id +# else: +# return company_obj.search(cr, uid, [('parent_id', '=', False)])[0] def _get_account(self, cr, uid, context=None): tmp = self.pool.get('account.account').search(cr, uid, [], limit=1 ) From 41255ffacfd1eb78d16a18981694ad4842de21df Mon Sep 17 00:00:00 2001 From: "qdp-launchpad@tinyerp.com" <> Date: Thu, 24 Jun 2010 16:45:51 +0200 Subject: [PATCH 009/696] [IMP] account: bugfixed the use of period_from and period_to bzr revid: qdp-launchpad@tinyerp.com-20100624144551-e8o1uzhg2psbw9mw --- addons/account/wizard/account_common_report.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/account/wizard/account_common_report.py b/addons/account/wizard/account_common_report.py index d87956b77a9..ef02308dc48 100644 --- a/addons/account/wizard/account_common_report.py +++ b/addons/account/wizard/account_common_report.py @@ -102,8 +102,9 @@ class account_common_report(osv.osv_memory): result['date_from'] = data['form']['date_from'] result['date_to'] = data['form']['date_to'] elif data['form']['filter'] == 'filter_period': - period_date_start = period_obj.read(cr, uid, data['form']['period_from'], ['date_start'])[0]['date_start'] - period_date_stop = period_obj.read(cr, uid, data['form']['period_to'], ['date_stop'])[0]['date_stop'] + period_obj = self.pool.get('account.period') + period_date_start = period_obj.read(cr, uid, data['form']['period_from'], ['date_start'])['date_start'] + period_date_stop = period_obj.read(cr, uid, data['form']['period_to'], ['date_stop'])['date_stop'] cr.execute('SELECT id FROM account_period WHERE date_start >= %s AND date_stop <= %s', (period_date_start, period_date_stop)) result['periods'] = lambda x: x[0], cr.fetchall() return result @@ -118,8 +119,7 @@ class account_common_report(osv.osv_memory): data['model'] = context.get('active_model', 'ir.ui.menu') data['form'] = self.read(cr, uid, ids, ['date_from', 'date_to', 'fiscalyear_id', 'journal_ids', 'period_from', 'period_to', 'filter', 'chart_account_id'])[0] used_context = self._build_context(cr, uid, ids, data, context) - query_line = obj_acc_move_line._query_get(cr, uid, - obj='l', context=used_context) + query_line = obj_acc_move_line._query_get(cr, uid, obj='l', context=used_context) return self._print_report(cr, uid, ids, data, query_line, context) account_common_report() From 0c66d23915da2732dfd420e37c8ae81343db04e7 Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Fri, 25 Jun 2010 16:52:16 +0530 Subject: [PATCH 010/696] [FIX] account: report with warning if the start and end period is not given in wizard bzr revid: mra@mra-laptop-20100625112216-bxuecavghwb7j364 --- addons/account/wizard/account_common_report.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/account/wizard/account_common_report.py b/addons/account/wizard/account_common_report.py index d87956b77a9..8ef94c5dfba 100644 --- a/addons/account/wizard/account_common_report.py +++ b/addons/account/wizard/account_common_report.py @@ -102,6 +102,8 @@ class account_common_report(osv.osv_memory): result['date_from'] = data['form']['date_from'] result['date_to'] = data['form']['date_to'] elif data['form']['filter'] == 'filter_period': + if data['form']['period_from'] == False or data['form']['period_to'] == False: + raise osv.except_osv(_('Error'),_('Select Start period and End period')) period_date_start = period_obj.read(cr, uid, data['form']['period_from'], ['date_start'])[0]['date_start'] period_date_stop = period_obj.read(cr, uid, data['form']['period_to'], ['date_stop'])[0]['date_stop'] cr.execute('SELECT id FROM account_period WHERE date_start >= %s AND date_stop <= %s', (period_date_start, period_date_stop)) From bc752eeb6ba75ccffd13114288eb8a75ae2f78dd Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Fri, 25 Jun 2010 17:16:06 +0530 Subject: [PATCH 011/696] [FIX] account: report small fix on common report bzr revid: mra@mra-laptop-20100625114606-lm2q5ly8wgy9cjqj --- addons/account/wizard/account_common_report.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account/wizard/account_common_report.py b/addons/account/wizard/account_common_report.py index 8ef94c5dfba..333e8a897b8 100644 --- a/addons/account/wizard/account_common_report.py +++ b/addons/account/wizard/account_common_report.py @@ -104,8 +104,8 @@ class account_common_report(osv.osv_memory): elif data['form']['filter'] == 'filter_period': if data['form']['period_from'] == False or data['form']['period_to'] == False: raise osv.except_osv(_('Error'),_('Select Start period and End period')) - period_date_start = period_obj.read(cr, uid, data['form']['period_from'], ['date_start'])[0]['date_start'] - period_date_stop = period_obj.read(cr, uid, data['form']['period_to'], ['date_stop'])[0]['date_stop'] + period_date_start = period_obj.read(cr, uid, data['form']['period_from'], ['date_start'])['date_start'] + period_date_stop = period_obj.read(cr, uid, data['form']['period_to'], ['date_stop'])['date_stop'] cr.execute('SELECT id FROM account_period WHERE date_start >= %s AND date_stop <= %s', (period_date_start, period_date_stop)) result['periods'] = lambda x: x[0], cr.fetchall() return result From 2d0b2663440cf4b03d15a9e953b1a599510791d4 Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Fri, 25 Jun 2010 17:28:36 +0530 Subject: [PATCH 012/696] [IMP] clean commont report class bzr revid: mra@mra-laptop-20100625115836-w9n3o6s9di3wfh2c --- .../account/wizard/account_common_report.py | 36 +++++++++---------- .../account/wizard/account_common_report.xml | 9 ++--- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/addons/account/wizard/account_common_report.py b/addons/account/wizard/account_common_report.py index 333e8a897b8..52c682500a2 100644 --- a/addons/account/wizard/account_common_report.py +++ b/addons/account/wizard/account_common_report.py @@ -26,22 +26,18 @@ import tools class account_common_report(osv.osv_memory): _name = "account.common.report" - _description = "Common Report" + _description = "Account Common Report" _columns = { - 'chart_account_id': fields.many2one('account.account', 'Chart of account', required=True, domain = [('parent_id','=',False)]), + 'chart_account_id': fields.many2one('account.account', 'Chart of account', help='Select Charts of Accounts', required=True, domain = [('parent_id','=',False)]), 'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal year', help='Keep empty for all open fiscal year'), - - 'filter': fields.selection([('filter_no','No filters'), ('filter_date','Date'), ('filter_period','Periods')],"Filter by:", required=True), - + 'filter': fields.selection([('filter_no', 'No filters'), ('filter_date', 'Date'), ('filter_period', 'Periods')], "Filter by:", required=True), 'period_from': fields.many2one('account.period', 'Start period'), 'period_to': fields.many2one('account.period', 'End period'), #not used. Do we really need it? 'period_ids': fields.many2many('account.period', 'ledger_period_rel', 'ledger_id', 'period_id', 'Periods'), - 'journal_ids': fields.many2many('account.journal', 'account_common_journal_rel', 'account_id', 'journal_id', 'Journals', required=True), - - 'date_from': fields.date("Start date"), - 'date_to': fields.date("End date"), + 'date_from': fields.date("Start Date"), + 'date_to': fields.date("End Date"), #'display_account': fields.selection([('bal_mouvement','With movements'), ('bal_all','All'), ('bal_solde','With balance is not equal to 0')],"Display accounts"), #'landscape': fields.boolean("Landscape Mode"), @@ -95,7 +91,9 @@ class account_common_report(osv.osv_memory): 'chart_account_id': _get_account, } - def _build_context(self, cr, uid, ids, data, context = None): + def _build_context(self, cr, uid, ids, data, context=None): + if context is None: + context = {} result = {} result['fiscalyear'] = data['form']['fiscalyear_id'] and data['form']['fiscalyear_id'] or False if data['form']['filter'] == 'filter_date': @@ -110,20 +108,22 @@ class account_common_report(osv.osv_memory): result['periods'] = lambda x: x[0], cr.fetchall() return result - def _print_report(self, cr, uid, ids, data, query_line, context): + def _print_report(self, cr, uid, ids, data, query_line, context=None): raise (_('Error'), _('not implemented')) def check_report(self, cr, uid, ids, context=None): - obj_acc_move_line = self.pool.get('account.move.line') + if context is None: + context = {} data = {} - data['ids'] = context.get('active_ids',[]) + data['ids'] = context.get('active_ids', []) data['model'] = context.get('active_model', 'ir.ui.menu') data['form'] = self.read(cr, uid, ids, ['date_from', 'date_to', 'fiscalyear_id', 'journal_ids', 'period_from', 'period_to', 'filter', 'chart_account_id'])[0] used_context = self._build_context(cr, uid, ids, data, context) - query_line = obj_acc_move_line._query_get(cr, uid, - obj='l', context=used_context) - return self._print_report(cr, uid, ids, data, query_line, context) + if used_context.get('periods', False): + data['form']['periods'] = used_context['periods'] + query_line = self.pool.get('account.move.line')._query_get(cr, uid, obj='l', context=used_context) + return self._print_report(cr, uid, ids, data, query_line, context=context) + account_common_report() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/account/wizard/account_common_report.xml b/addons/account/wizard/account_common_report.xml index d138c8ec2de..ddbc1c365d2 100644 --- a/addons/account/wizard/account_common_report.xml +++ b/addons/account/wizard/account_common_report.xml @@ -1,19 +1,19 @@ + + Common Report account.common.report form
- - @@ -27,7 +27,6 @@ - - - - + \ No newline at end of file From 307d40f4b13c2f814468a460299a4412c9d501be Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Fri, 25 Jun 2010 17:53:07 +0530 Subject: [PATCH 013/696] [FIX] account common report bzr revid: mra@mra-laptop-20100625122307-95j5i6eon5m2s9pb --- addons/account/wizard/account_common_report.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/account/wizard/account_common_report.py b/addons/account/wizard/account_common_report.py index 52c682500a2..45f966c672d 100644 --- a/addons/account/wizard/account_common_report.py +++ b/addons/account/wizard/account_common_report.py @@ -100,8 +100,10 @@ class account_common_report(osv.osv_memory): result['date_from'] = data['form']['date_from'] result['date_to'] = data['form']['date_to'] elif data['form']['filter'] == 'filter_period': - if data['form']['period_from'] == False or data['form']['period_to'] == False: + if not data['form']['period_from'] or not data['form']['period_to']: raise osv.except_osv(_('Error'),_('Select Start period and End period')) + elif (data['form']['period_from'] > data['form']['period_to']): + raise osv.except_osv(_('Error'),_('Start period should be smaller then End period')) period_date_start = period_obj.read(cr, uid, data['form']['period_from'], ['date_start'])['date_start'] period_date_stop = period_obj.read(cr, uid, data['form']['period_to'], ['date_stop'])['date_stop'] cr.execute('SELECT id FROM account_period WHERE date_start >= %s AND date_stop <= %s', (period_date_start, period_date_stop)) From ffc09cf64da22df04fa159a44337cefcf6850d1b Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Fri, 25 Jun 2010 17:53:59 +0530 Subject: [PATCH 014/696] [IMP] account: General journal report update with osv memory (ref: PSI) bzr revid: mra@mra-laptop-20100625122359-ivvogx5pco2ov50n --- addons/account/report/general_journal.py | 11 +++-- .../account/report/wizard_general_journal.rml | 10 ++--- .../account/wizard/account_general_journal.py | 43 +++++++++++-------- .../wizard/account_general_journal_view.xml | 27 +++++++----- 4 files changed, 51 insertions(+), 40 deletions(-) diff --git a/addons/account/report/general_journal.py b/addons/account/report/general_journal.py index 631930ce3a7..781e2301171 100644 --- a/addons/account/report/general_journal.py +++ b/addons/account/report/general_journal.py @@ -36,14 +36,14 @@ class journal_print(report_sxw.rml_parse): 'sum_debit_period': self._sum_debit_period, 'sum_credit_period': self._sum_credit_period, 'sum_debit': self._sum_debit, - 'sum_credit': self._sum_credit + 'sum_credit': self._sum_credit, }) - def set_context(self, objects, data, ids, report_type = None): + def set_context(self, objects, data, ids, report_type=None): super(journal_print, self).set_context(objects, data, ids, report_type) self.cr.execute('SELECT period_id, journal_id ' - 'FROM account_journal_period ' - 'WHERE id IN %s', + 'FROM account_journal_period ' + 'WHERE id IN %s', (tuple(ids),)) res = self.cr.fetchall() self.period_ids, self.journal_ids = zip(*res) @@ -91,7 +91,6 @@ class journal_print(report_sxw.rml_parse): return lines_data if not self.journal_ids: return [] - self.cr.execute('SELECT j.code, j.name, ' 'SUM(l.debit) AS debit, SUM(l.credit) AS credit ' 'FROM account_move_line l ' @@ -146,7 +145,7 @@ class journal_print(report_sxw.rml_parse): 'AND state<>\'draft\'', (tuple(periods), tuple(journals))) return self.cr.fetchone()[0] or 0.0 -report_sxw.report_sxw('report.account.general.journal', 'account.journal.period', 'addons/account/report/general_journal.rml', parser=journal_print) +report_sxw.report_sxw('report.account.general.journal', 'account.journal.period', 'addons/account/report/general_journal.rml', parser=journal_print, header=False) report_sxw.report_sxw('report.account.general.journal.wiz', 'account.journal.period', 'addons/account/report/wizard_general_journal.rml', parser=journal_print, header=False) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account/report/wizard_general_journal.rml b/addons/account/report/wizard_general_journal.rml index aba1ad9c98c..cf0d058147f 100644 --- a/addons/account/report/wizard_general_journal.rml +++ b/addons/account/report/wizard_general_journal.rml @@ -178,10 +178,10 @@ - [[ formatLang(sum_debit(data['form']['period_id'][0][2],data['form']['journal_id'][0][2])) ]] + [[ formatLang(sum_debit(data['form']['periods'],data['form']['journal_ids'])) ]] - [[ formatLang(sum_credit(data['form']['period_id'][0][2],data['form']['journal_id'][0][2])) ]] + [[ formatLang(sum_credit(data['form']['periods'],data['form']['journal_ids'])) ]] @@ -191,7 +191,7 @@ - [[ repeatIn( lines( data['form']['period_id'][0][2], data['form']['journal_id'][0][2] ),'line')]] + [[ repeatIn( lines( data['form']['periods'], data['form']['journal_ids'] ),'line')]] @@ -208,10 +208,10 @@ - [[ formatLang(sum_debit_period( line[0]['pid'],data['form']['journal_id'][0][2])) ]] + [[ formatLang(sum_debit_period( line[0]['pid'],data['form']['journal_ids'])) ]] - [[ formatLang(sum_credit_period(line[0]['pid'],data['form']['journal_id'][0][2])) ]] + [[ formatLang(sum_credit_period(line[0]['pid'],data['form']['journal_ids'])) ]] diff --git a/addons/account/wizard/account_general_journal.py b/addons/account/wizard/account_general_journal.py index 8bd2913ae62..f50ab0b737f 100644 --- a/addons/account/wizard/account_general_journal.py +++ b/addons/account/wizard/account_general_journal.py @@ -22,23 +22,29 @@ from osv import osv, fields from tools.translate import _ class account_general_journal(osv.osv_memory): + _inherit = "account.common.report" _name = 'account.general.journal' _description = 'Account General Journal' - _columns = { - 'journal_id': fields.many2many('account.journal', 'account_journal_rel', 'account_id', 'journal_id', 'Journals', required=True), - 'period_id': fields.many2many('account.period', 'account_period_rel', 'account_id', 'period_id', 'Periods', required=True), - } + def _build_context(self, cr, uid, ids, data, context=None): + period_obj = self.pool.get('account.period') + result = super(account_general_journal, self)._build_context(cr, uid, ids, data, context=context) + if not data['form']['period_from'] or not data['form']['period_to']: + raise osv.except_osv(_('Error'),_('Select Start period and End period')) + elif (data['form']['period_from'] > data['form']['period_to']): + raise osv.except_osv(_('Error'),_('Start period should be smaller then End period')) + period_date_start = period_obj.read(cr, uid, data['form']['period_from'], ['date_start'])['date_start'] + period_date_stop = period_obj.read(cr, uid, data['form']['period_to'], ['date_stop'])['date_stop'] + cr.execute('SELECT id FROM account_period WHERE date_start >= %s AND date_stop <= %s', (period_date_start, period_date_stop)) + result.update({'periods': map(lambda x: x[0], cr.fetchall())}) + return result - def check_data(self, cr, uid, ids, context=None): + def _print_report(self, cr, uid, ids, data, query_line, context=None): + if context is None: + context = {} obj_jperiod = self.pool.get('account.journal.period') - datas = {} - datas['ids'] = [] - datas['model'] = 'account.journal.period' - datas['form'] = self.read(cr, uid, ids)[0] - period_id = datas['form']['period_id'] - journal_id = datas['form']['journal_id'] - + period_id = data['form']['periods'] + journal_id = data['form']['journal_ids'] if type(period_id)==type([]): ids_final = [] for journal in journal_id: @@ -48,12 +54,13 @@ class account_general_journal(osv.osv_memory): ids_final.append(ids_journal_period) if not ids_final: raise osv.except_osv(_('No Data Available'), _('No records found for your selection!')) - return { - 'type': 'ir.actions.report.xml', - 'report_name': 'account.general.journal', - 'datas': datas, - 'nodestroy':True, - } + data['ids'] = [] + data['form']['query_get'] = query_line + if data['model'] == 'ir.ui.menu': + return {'type': 'ir.actions.report.xml', 'report_name': 'account.general.journal.wiz', 'datas': data, 'nodestroy':True, } + else: + return {'type': 'ir.actions.report.xml', 'report_name': 'account.general.journal', 'datas': data, 'nodestroy':True, } account_general_journal() + #vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/account/wizard/account_general_journal_view.xml b/addons/account/wizard/account_general_journal_view.xml index fc39300d390..0fd994ec707 100644 --- a/addons/account/wizard/account_general_journal_view.xml +++ b/addons/account/wizard/account_general_journal_view.xml @@ -7,17 +7,22 @@ account.general.journal form - - - - - - - -