From 73282b799a1a43f02efc4e1245039794168630be Mon Sep 17 00:00:00 2001 From: Bertrand Chenal Date: Thu, 18 Dec 2008 23:22:32 +0100 Subject: [PATCH] Improve indentation for sql queries --- product.py | 117 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 49 deletions(-) diff --git a/product.py b/product.py index 37fc0f90ef..d9e9833766 100644 --- a/product.py +++ b/product.py @@ -134,6 +134,8 @@ class Product(OSV): location_obj = self.pool.get('stock.location') date_obj = self.pool.get('ir.date') + today = date_obj.today(cursor, user, context=context) + if not location_ids: return [] if context is None: @@ -162,16 +164,19 @@ class Product(OSV): context['stock_date_end'] = datetime.date.max # date end in the past or today: filter on state done - if context['stock_date_end'] < date_obj.today(cursor, user, - context=context) or \ - (context['stock_date_end'] == \ - date_obj.today(cursor, user, context=context) \ - and not context.get('forecast')): - state_date_clause = '((state in (%s, %s)) AND ('\ - '(effective_date IS NULL '\ - 'AND ( planned_date <= %s)) '\ - 'OR effective_date <= %s'\ - '))' + if context['stock_date_end'] < today or \ + (context['stock_date_end'] == today \ + and not context.get('forecast')): + state_date_clause = \ + '('\ + '(state in (%s, %s)) '\ + 'AND ('\ + '(effective_date IS NULL '\ + 'AND ( planned_date <= %s) '\ + ')'\ + 'OR effective_date <= %s'\ + ')'\ + ')' state_date_vals = ["done", context.get('stock_assign') and 'assigned' or 'done', context['stock_date_end'], @@ -185,21 +190,27 @@ class Product(OSV): # before today, or on all state and date between today and # date_end. else: - state_date_clause = '((' + \ - '(state in (%s, %s)) AND ('\ - '(effective_date IS NULL '\ - 'AND ( planned_date <= %s )) '\ - 'OR effective_date <= %s)' \ - + \ - ') OR (' + \ - '(state in (%s, %s, %s)) AND ('\ - '(effective_date IS NULL '\ - 'AND ( planned_date <= %s AND planned_date >= %s '\ - ')) '\ - 'OR (effective_date <= %s AND effective_date >= %s)'\ - ')'\ - '))' - today = date_obj.today(cursor, user, context=context) + state_date_clause = \ + '((' + \ + '(state in (%s, %s)) '\ + 'AND ('\ + '(effective_date IS NULL '\ + 'AND (planned_date <= %s ) '\ + ')'\ + 'OR effective_date <= %s' \ + ')'\ + ')'\ + 'OR (' + \ + '(state in (%s, %s, %s)) '\ + 'AND ('\ + '(effective_date IS NULL '\ + 'AND (planned_date <= %s AND planned_date >= %s) '\ + ') '\ + 'OR (effective_date <= %s AND effective_date >= %s)'\ + ')'\ + ')'\ + ') ' + state_date_vals = [ 'done', 'assigned', today, today, 'done', 'assigned', 'draft', @@ -208,35 +219,43 @@ class Product(OSV): ] if context.get('stock_date_start'): - if context['stock_date_start'] > date_obj.today(cursor, user, - context=context): - state_date_clause += ' AND ((state in (%s, %s, %s)) AND ('\ - '(effective_date IS NULL '\ - 'AND ( planned_date >= %s OR planned_date IS NULL)) '\ - 'OR effective_date >= %s'\ - '))' + if context['stock_date_start'] > today: + state_date_clause += \ + 'AND ((state in (%s, %s, %s)) '\ + 'AND ('\ + '(effective_date IS NULL '\ + 'AND (planned_date >= %s OR planned_date IS NULL)'\ + ') '\ + 'OR effective_date >= %s'\ + ')'\ + ') ' state_date_vals.extend( ['done', 'assigned', 'draft', context['stock_date_start'], context['stock_date_start']]) else: - tmp_clause = '(state in (%s, %s, %s)) AND ('\ - '(effective_date IS NULL '\ - 'AND ( planned_date >= %s OR planned_date IS NULL)) '\ - 'OR effective_date >= %s'\ - ')' - today = date_obj.today(cursor, user, context=context) - state_date_vals.extend( - ['done', 'assigned', 'draft', today, today]) + state_date_clause += \ + 'AND ((' \ + '(state in (%s, %s, %s)) '\ + 'AND ('\ + '(effective_date IS NULL '\ + 'AND (planned_date >= %s OR planned_date IS NULL) '\ + ')'\ + 'OR effective_date >= %s'\ + ')'\ + ') '\ + 'OR (' + \ + '(state in (%s, %s)) AND '\ + '('\ + '(effective_date IS NULL '\ + 'AND (( planned_date >= %s AND planned_date < %s ) '\ + 'OR planned_date IS NULL)) '\ + 'OR (effective_date >= %s AND effective_date < %s)'\ + ')'\ + ')'\ + ') ' - state_date_clause += ' AND ((' + tmp_clause + \ - ') OR (' + \ - '(state in (%s, %s)) AND ('\ - '(effective_date IS NULL '\ - 'AND (( planned_date >= %s AND planned_date < %s ) '\ - 'OR planned_date IS NULL)) '\ - 'OR (effective_date >= %s AND effective_date < %s)'\ - ')'\ - '))' + state_date_vals.extend( + ['done', 'assigned', 'draft', today, today]) state_date_vals.extend([ 'done', context.get('stock_assign') and 'assigned' or 'done',