Accounts Payable report improved: some query written outside the for-loop

Supplier: supplier_status field has been deleted, not used by anyone except janak
index patch modified
This commit is contained in:
nabinhait
2011-07-19 18:09:26 +05:30
parent 5f1d9962c6
commit e6526369f3
5 changed files with 128 additions and 127 deletions

View File

@@ -66,32 +66,43 @@ if len(res) > 600 and from_export == 0:
# main loop starts here # main loop starts here
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# get supplier type
supp_type_dict = {}
for each in sql("select t2.name, t1.supplier_type from tabSupplier t1, tabAccount t2 where t1.name = t2.account_name group by t2.name"):
supp_type_dict[each[0]] = each[1]
# get due_date, bill_no, bill_date from PV
pv_dict = {}
for t in sql("select name, due_date, bill_no, bill_date from `tabPayable Voucher` group by name"):
pv_dict[t[0]] = [cstr(t[1]), t[2], cstr(t[3])]
# pv outside this period
pv_outside_period = [d[0] for d in sql("select distinct name from `tabPayable Voucher` where (posting_date < '%s' or posting_date > '%s') and docstatus = 1" % (from_date, to_date))]
out = [] out = []
total_booking_amt, total_outstanding_amt = 0,0 total_booking_amt, total_outstanding_amt = 0,0
for r in res: for r in res:
# get supplier type outstanding_amt, due_date, bill_no, bill_date, cond = 0, '','','', ''
supplier_type = sql("select t1.supplier_type from tabSupplier t1, tabAccount t2 where t1.name = t2.account_name and t2.name = '%s'" % r[col_idx['Account']]) booking_amt = r.pop(8)
r.append(supplier_type and cstr(supplier_type[0][0]) or '')
outstanding_amt, booking_amt, due_date, bill_no, bill_date, cond = 0,0, '','','', '' # supplier type
r.append(supp_type_dict.get(r[col_idx['Account']], ''))
# if entry against Payable Voucher # if entry against Payable Voucher
if r[col_idx['Against Voucher']] and r[col_idx['Voucher Type']] == 'Payable Voucher': if r[col_idx['Against Voucher']] and r[col_idx['Voucher Type']] == 'Payable Voucher':
due_date, bill_no, bill_date = [cstr(t) for t in sql("select due_date,bill_no,bill_date from `tabPayable Voucher` where name = %s", r[col_idx['Voucher No']])[0]] r += pv_dict.get(r[col_idx['Voucher No']], ['', '', ''])
cond = " and ifnull(against_voucher, '') = '%s'" % r[col_idx['Against Voucher']]
# get opening
booking_amt = sql("select credit from `tabGL Entry` where account = %s and voucher_no = %s and is_cancelled = 'No'", (r[col_idx['Account']], r[col_idx['Voucher No']]))
booking_amt = booking_amt and flt(booking_amt[0][0]) or 0
cond = " and against_voucher = '%s' and against_voucher is not null" % r[col_idx['Against Voucher']]
# if entry against JV & and not adjusted within period # if entry against JV & and not adjusted within period
elif r[col_idx['Against Voucher Type']] == 'Payable Voucher' and sql("select name from `tabPayable Voucher` where name = '%s' and (posting_date < '%s' or posting_date > '%s') and docstatus = 1" % (r[col_idx['Against Voucher']], from_date, to_date)): elif r[col_idx['Against Voucher Type']] == 'Payable Voucher' and r[col_idx['Against Voucher']] in pv_outside_period:
booking_amt = 0
cond = " and voucher_no = '%s' and ifnull(against_voucher, '') = '%s'" % (r[col_idx['Voucher No']], r[col_idx['Against Voucher']]) cond = " and voucher_no = '%s' and ifnull(against_voucher, '') = '%s'" % (r[col_idx['Voucher No']], r[col_idx['Against Voucher']])
# if un-adjusted # if un-adjusted
elif not r[col_idx['Against Voucher']]: elif not r[col_idx['Against Voucher']]:
booking_amt = 0
cond = " and ((voucher_no = '%s' and ifnull(against_voucher, '') = '') or (ifnull(against_voucher, '') = '%s' and voucher_type = 'Journal Voucher'))" % (r[col_idx['Voucher No']], r[col_idx['Voucher No']]) cond = " and ((voucher_no = '%s' and ifnull(against_voucher, '') = '') or (ifnull(against_voucher, '') = '%s' and voucher_type = 'Journal Voucher'))" % (r[col_idx['Voucher No']], r[col_idx['Voucher No']])
if cond: if cond:
@@ -104,7 +115,7 @@ for r in res:
if outstanding_amt and r[col_idx['Voucher Type']] == 'Payable Voucher' and r[col_idx['Against Voucher']]: if outstanding_amt and r[col_idx['Voucher Type']] == 'Payable Voucher' and r[col_idx['Against Voucher']]:
total_booking_amt += flt(booking_amt) total_booking_amt += flt(booking_amt)
r += [due_date, bill_no, bill_date, booking_amt, outstanding_amt] r += [booking_amt, outstanding_amt]
# split into date ranges # split into date ranges
val_l1 = val_l2 = val_l3 = val_l4 = val_l5_above= 0 val_l1 = val_l2 = val_l3 = val_l4 = val_l5_above= 0

View File

@@ -1,4 +1,4 @@
SELECT DISTINCT `tabGL Entry`.`Aging_date`,`tabGL Entry`.`transaction_date`,`tabGL Entry`.`account`, `tabGL Entry`.`against_voucher_type`, `tabGL Entry`.`against_voucher`,`tabGL Entry`.`voucher_type`,`tabGL Entry`.`voucher_no`, `tabGL Entry`.remarks SELECT DISTINCT `tabGL Entry`.`Aging_date`,`tabGL Entry`.`transaction_date`,`tabGL Entry`.`account`, `tabGL Entry`.`against_voucher_type`, `tabGL Entry`.`against_voucher`,`tabGL Entry`.`voucher_type`,`tabGL Entry`.`voucher_no`, `tabGL Entry`.`remarks`, `tabGL Entry`.`credit`
FROM `tabGL Entry`,`tabAccount` FROM `tabGL Entry`,`tabAccount`
WHERE `tabGL Entry`.`posting_date`>= '%(posting_date)s' WHERE `tabGL Entry`.`posting_date`>= '%(posting_date)s'
AND `tabGL Entry`.`posting_date`<= '%(posting_date1)s' AND `tabGL Entry`.`posting_date`<= '%(posting_date1)s'

View File

@@ -5,7 +5,7 @@
{ {
'creation': '2010-08-08 17:09:26', 'creation': '2010-08-08 17:09:26',
'docstatus': 0, 'docstatus': 0,
'modified': '2011-05-10 17:42:21', 'modified': '2011-07-19 16:18:58',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'owner': 'Administrator' 'owner': 'Administrator'
}, },
@@ -25,7 +25,7 @@
'show_in_menu': 0, 'show_in_menu': 0,
'subject': ' ', 'subject': ' ',
'tag_fields': 'supplier_type', 'tag_fields': 'supplier_type',
'version': 86 'version': 87
}, },
# These values are common for all DocField # These values are common for all DocField
@@ -163,24 +163,11 @@
'permlevel': 0 'permlevel': 0
}, },
# DocField
{
'doctype': 'DocField',
'fieldname': 'supplier_status',
'fieldtype': 'Select',
'idx': 6,
'label': 'Supplier Status',
'oldfieldname': 'supplier_status',
'oldfieldtype': 'Select',
'options': '\nApproved\nUnapproved',
'permlevel': 0
},
# DocField # DocField
{ {
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'Section Break', 'fieldtype': 'Section Break',
'idx': 7, 'idx': 6,
'label': 'Address & Contacts', 'label': 'Address & Contacts',
'oldfieldtype': 'Column Break', 'oldfieldtype': 'Column Break',
'permlevel': 0 'permlevel': 0
@@ -192,7 +179,7 @@
'depends_on': 'eval:doc.__islocal', 'depends_on': 'eval:doc.__islocal',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'HTML', 'fieldtype': 'HTML',
'idx': 8, 'idx': 7,
'label': 'Address Desc', 'label': 'Address Desc',
'options': '<em>Addresses will appear only when you save the supplier</em>', 'options': '<em>Addresses will appear only when you save the supplier</em>',
'permlevel': 0 'permlevel': 0
@@ -203,7 +190,7 @@
'colour': 'White:FFF', 'colour': 'White:FFF',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'HTML', 'fieldtype': 'HTML',
'idx': 9, 'idx': 8,
'label': 'Address HTML', 'label': 'Address HTML',
'permlevel': 1 'permlevel': 1
}, },
@@ -212,7 +199,7 @@
{ {
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'Column Break', 'fieldtype': 'Column Break',
'idx': 10, 'idx': 9,
'permlevel': 0, 'permlevel': 0,
'width': '50%' 'width': '50%'
}, },
@@ -223,7 +210,7 @@
'depends_on': 'eval:doc.__islocal', 'depends_on': 'eval:doc.__islocal',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'HTML', 'fieldtype': 'HTML',
'idx': 11, 'idx': 10,
'label': 'Contact Desc', 'label': 'Contact Desc',
'options': '<em>Contact Details will appear only when you save the supplier</em>', 'options': '<em>Contact Details will appear only when you save the supplier</em>',
'permlevel': 0 'permlevel': 0
@@ -233,7 +220,7 @@
{ {
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'HTML', 'fieldtype': 'HTML',
'idx': 12, 'idx': 11,
'label': 'Contact HTML', 'label': 'Contact HTML',
'permlevel': 1 'permlevel': 1
}, },
@@ -242,7 +229,7 @@
{ {
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'Section Break', 'fieldtype': 'Section Break',
'idx': 13, 'idx': 12,
'label': 'More Info', 'label': 'More Info',
'oldfieldtype': 'Section Break', 'oldfieldtype': 'Section Break',
'permlevel': 0 'permlevel': 0
@@ -255,7 +242,7 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'company', 'fieldname': 'company',
'fieldtype': 'Link', 'fieldtype': 'Link',
'idx': 14, 'idx': 13,
'in_filter': 1, 'in_filter': 1,
'label': 'Company', 'label': 'Company',
'oldfieldname': 'company', 'oldfieldname': 'company',
@@ -273,7 +260,7 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'supplier_details', 'fieldname': 'supplier_details',
'fieldtype': 'Text', 'fieldtype': 'Text',
'idx': 15, 'idx': 14,
'label': 'Supplier Details', 'label': 'Supplier Details',
'oldfieldname': 'supplier_details', 'oldfieldname': 'supplier_details',
'oldfieldtype': 'Code', 'oldfieldtype': 'Code',
@@ -284,7 +271,7 @@
{ {
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'Column Break', 'fieldtype': 'Column Break',
'idx': 16, 'idx': 15,
'permlevel': 0, 'permlevel': 0,
'width': '50%' 'width': '50%'
}, },
@@ -294,7 +281,7 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'credit_days', 'fieldname': 'credit_days',
'fieldtype': 'Int', 'fieldtype': 'Int',
'idx': 17, 'idx': 16,
'label': 'Credit Days', 'label': 'Credit Days',
'permlevel': 0 'permlevel': 0
}, },
@@ -304,7 +291,7 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'website', 'fieldname': 'website',
'fieldtype': 'Data', 'fieldtype': 'Data',
'idx': 18, 'idx': 17,
'label': 'Website', 'label': 'Website',
'oldfieldname': 'website', 'oldfieldname': 'website',
'oldfieldtype': 'Data', 'oldfieldtype': 'Data',
@@ -317,7 +304,7 @@
'depends_on': 'eval:!doc.__islocal', 'depends_on': 'eval:!doc.__islocal',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'Section Break', 'fieldtype': 'Section Break',
'idx': 19, 'idx': 18,
'label': 'Transaction History', 'label': 'Transaction History',
'oldfieldtype': 'Section Break', 'oldfieldtype': 'Section Break',
'permlevel': 0 'permlevel': 0
@@ -329,7 +316,7 @@
'depends_on': 'eval:!doc.__islocal', 'depends_on': 'eval:!doc.__islocal',
'doctype': 'DocField', 'doctype': 'DocField',
'fieldtype': 'HTML', 'fieldtype': 'HTML',
'idx': 20, 'idx': 19,
'label': 'History HTML', 'label': 'History HTML',
'oldfieldtype': 'HTML', 'oldfieldtype': 'HTML',
'permlevel': 0 'permlevel': 0
@@ -340,7 +327,7 @@
'doctype': 'DocField', 'doctype': 'DocField',
'fieldname': 'trash_reason', 'fieldname': 'trash_reason',
'fieldtype': 'Small Text', 'fieldtype': 'Small Text',
'idx': 21, 'idx': 20,
'label': 'Trash Reason', 'label': 'Trash Reason',
'oldfieldname': 'trash_reason', 'oldfieldname': 'trash_reason',
'oldfieldtype': 'Small Text', 'oldfieldtype': 'Small Text',

View File

@@ -102,7 +102,7 @@ def create_proper_index():
'File Group': ['parent_group'], 'File Group': ['parent_group'],
'Maintenance Visit Detail': ['item_code', 'service_person'], 'Maintenance Visit Detail': ['item_code', 'service_person'],
'Support Ticket Response': [], 'Support Ticket Response': [],
'PV Detail': ['item_code', 'purchase_order', 'po_detail', 'purchase_receipt', 'pr_detail', 'expense_head', 'cost_center'], 'PV Detail': ['item_code', 'purchase_order', 'purchase_receipt', 'expense_head', 'cost_center'],
'Timesheet Detail': ['project_name', 'task_id', 'customer_name'], 'Timesheet Detail': ['project_name', 'task_id', 'customer_name'],
'Holiday List Detail': [], 'Holiday List Detail': [],
'Workflow Rule Detail': [], 'Workflow Rule Detail': [],
@@ -125,7 +125,7 @@ def create_proper_index():
'Declaration Detail': [], 'Declaration Detail': [],
'Holiday List': ['fiscal_year'], 'Holiday List': ['fiscal_year'],
'Sales Person': ['lft', 'rgt', 'parent_sales_person'], 'Sales Person': ['lft', 'rgt', 'parent_sales_person'],
'RV Detail': ['item_code', 'sales_order', 'so_detail', 'delivery_note', 'dn_detail', 'cost_center', 'income_account'], 'RV Detail': ['item_code', 'sales_order', 'delivery_note', 'cost_center', 'income_account'],
'Module Def Item': [], 'Module Def Item': [],
'TDS Category': [], 'TDS Category': [],
'DocTrigger': [], 'DocTrigger': [],

View File

@@ -1,7 +1,7 @@
# REMEMBER to update this # REMEMBER to update this
# ======================== # ========================
last_patch = 326 last_patch = 327
#------------------------------------------- #-------------------------------------------
@@ -1298,3 +1298,6 @@ def execute(patch_no):
# load the new billing page # load the new billing page
if cint(webnotes.conn.get_value('Control Panel',None,'sync_with_gateway')): if cint(webnotes.conn.get_value('Control Panel',None,'sync_with_gateway')):
reload_doc('server_tools','page','billing') reload_doc('server_tools','page','billing')
elif patch_no == 327:
if webnotes.conn.get_value('Control Panel', None, 'account_id') != 'axjanak2011':
sql("delete from `tabDocField` where fieldname = 'supplier_status' and parent = 'Supplier'")