Merge pull request #161 from anandpdoshi/master

Resolved bug: when account of type 'Bank or Cash' does not exists
This commit is contained in:
Anand Doshi 2011-12-14 06:36:32 -08:00
commit 407ebb9e41

View File

@ -109,7 +109,7 @@ class DocType:
result = {} result = {}
for query in query_dict.keys(): for query in query_dict.keys():
if self.doc.fields[query]: if self.doc.fields[query] and query_dict[query]:
#webnotes.msgprint(query) #webnotes.msgprint(query)
res = webnotes.conn.sql(query_dict[query], as_dict=1) res = webnotes.conn.sql(query_dict[query], as_dict=1)
if query == 'income': if query == 'income':
@ -121,8 +121,7 @@ class DocType:
#webnotes.msgprint(query) #webnotes.msgprint(query)
#webnotes.msgprint(res) #webnotes.msgprint(res)
result[query] = (res and len(res)==1) and res[0] or (res and res or None) result[query] = (res and len(res)==1) and res[0] or (res and res or None)
#webnotes.msgprint(result)
return result return result
@ -149,18 +148,19 @@ class DocType:
elif args['type'] in ['collections', 'payments']: elif args['type'] in ['collections', 'payments']:
args['bc_accounts_regex'] = self.get_bc_accounts_regex() args['bc_accounts_regex'] = self.get_bc_accounts_regex()
query = """ if args['bc_accounts_regex']:
SELECT query = """
IFNULL(SUM(IFNULL(gle.%(field)s, 0)), 0) AS '%(field)s', SELECT
%(common_select)s IFNULL(SUM(IFNULL(gle.%(field)s, 0)), 0) AS '%(field)s',
FROM %(common_select)s
%(common_from)s FROM
WHERE %(common_from)s
%(common_where)s AND WHERE
ac.master_type = '%(master_type)s' AND %(common_where)s AND
gle.against REGEXP '%(bc_accounts_regex)s' AND ac.master_type = '%(master_type)s' AND
%(start_date_condition)s AND gle.against REGEXP '%(bc_accounts_regex)s' AND
%(end_date_condition)s""" % args %(start_date_condition)s AND
%(end_date_condition)s""" % args
elif args['type'] in ['income', 'expenses_booked']: elif args['type'] in ['income', 'expenses_booked']:
query = """ query = """
@ -307,7 +307,8 @@ class DocType:
FROM `tabAccount` FROM `tabAccount`
WHERE account_type = 'Bank or Cash'""", as_list=1) WHERE account_type = 'Bank or Cash'""", as_list=1)
return '(' + '|'.join([ac[0] for ac in bc_account_list]) + ')' if bc_account_list:
return '(' + '|'.join([ac[0] for ac in bc_account_list]) + ')'
def get(self): def get(self):
@ -653,13 +654,17 @@ class DocType:
# Sort these keys depending on idx value # Sort these keys depending on idx value
bd_keys = sorted(body_dict, key=lambda x: body_dict[x]['idx']) bd_keys = sorted(body_dict, key=lambda x: body_dict[x]['idx'])
for k in bd_keys: for k in bd_keys:
if self.doc.fields[k]: if self.doc.fields[k]:
table_list.append(body_dict[k]['table']) if k in result:
table_list.append(body_dict[k]['table'])
elif k in ['collections', 'payments']:
table_list.append(\
"<div style='font-size: 16px; color: grey'>[" + \
k.capitalize() + \
"]<br />Missing: Ledger of type 'Bank or Cash'\
</div>")
result = []
i = 0 i = 0
result = [] result = []
op_len = len(table_list) op_len = len(table_list)