Merge branch 'master' into slow
This commit is contained in:
		
						commit
						aea0af02aa
					
				| @ -24,7 +24,6 @@ def execute(filters=None): | |||||||
| 	for gle in entries: | 	for gle in entries: | ||||||
| 		if cstr(gle.against_voucher) == gle.voucher_no or not gle.against_voucher \ | 		if cstr(gle.against_voucher) == gle.voucher_no or not gle.against_voucher \ | ||||||
| 				or [gle.against_voucher_type, gle.against_voucher] in entries_after_report_date: | 				or [gle.against_voucher_type, gle.against_voucher] in entries_after_report_date: | ||||||
| 			 |  | ||||||
| 			if gle.voucher_type == "Purchase Invoice": | 			if gle.voucher_type == "Purchase Invoice": | ||||||
| 				pi_info = pi_map.get(gle.voucher_no) | 				pi_info = pi_map.get(gle.voucher_no) | ||||||
| 				due_date = pi_info.get("due_date") | 				due_date = pi_info.get("due_date") | ||||||
| @ -33,12 +32,12 @@ def execute(filters=None): | |||||||
| 			else: | 			else: | ||||||
| 				due_date = bill_no = bill_date = "" | 				due_date = bill_no = bill_date = "" | ||||||
| 		 | 		 | ||||||
| 			invoiced_amount = gle.credit > 0 and gle.credit or 0		 | 			invoiced_amount = gle.credit > 0 and gle.credit or 0 | ||||||
| 			paid_amount = get_paid_amount(gle, filters.get("report_date") or nowdate(),  | 			outstanding_amount = get_outstanding_amount(gle,  | ||||||
| 				entries_after_report_date) | 				filters.get("report_date") or nowdate()) | ||||||
| 			outstanding_amount = invoiced_amount - paid_amount |  | ||||||
| 
 | 
 | ||||||
| 			if abs(flt(outstanding_amount)) > 0.01: | 			if abs(flt(outstanding_amount)) > 0.01: | ||||||
|  | 				paid_amount = invoiced_amount - outstanding_amount | ||||||
| 				row = [gle.posting_date, gle.account, gle.voucher_type, gle.voucher_no,  | 				row = [gle.posting_date, gle.account, gle.voucher_type, gle.voucher_no,  | ||||||
| 					gle.remarks, account_supplier_type_map.get(gle.account), due_date, bill_no,  | 					gle.remarks, account_supplier_type_map.get(gle.account), due_date, bill_no,  | ||||||
| 					bill_date, invoiced_amount, paid_amount, outstanding_amount] | 					bill_date, invoiced_amount, paid_amount, outstanding_amount] | ||||||
| @ -116,17 +115,13 @@ def get_pi_map(): | |||||||
| 		 | 		 | ||||||
| 	return pi_map | 	return pi_map | ||||||
| 
 | 
 | ||||||
| def get_paid_amount(gle, report_date, entries_after_report_date): | def get_outstanding_amount(gle, report_date): | ||||||
| 
 | 	payment_amount = webnotes.conn.sql(""" | ||||||
| 	paid_amount = 0 | 		select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))  | ||||||
| 	if flt(gle.debit) > 0 and (not gle.against_voucher or  | 		from `tabGL Entry`  | ||||||
| 		[gle.against_voucher_type, gle.against_voucher] in entries_after_report_date): | 		where account = %s and posting_date <= %s and against_voucher_type = %s  | ||||||
| 			paid_amount = gle.debit | 		and against_voucher = %s and name != %s and ifnull(is_cancelled, 'No') = 'No'""",  | ||||||
| 	elif flt(gle.credit) > 0: | 		(gle.account, report_date, gle.voucher_type, gle.voucher_no, gle.name))[0][0] | ||||||
| 		paid_amount = webnotes.conn.sql(""" | 		 | ||||||
| 			select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0)) from `tabGL Entry`  | 	outstanding_amount = flt(gle.credit) - flt(gle.debit) - flt(payment_amount) | ||||||
| 			where account = %s and posting_date <= %s and against_voucher_type = %s  | 	return outstanding_amount | ||||||
| 			and against_voucher = %s and name != %s and ifnull(is_cancelled, 'No') = 'No'""",  |  | ||||||
| 			(gle.account, report_date, gle.voucher_type, gle.voucher_no, gle.name))[0][0] |  | ||||||
| 	 |  | ||||||
| 	return flt(paid_amount) |  | ||||||
| @ -27,11 +27,11 @@ def execute(filters=None): | |||||||
| 				and si_due_date_map.get(gle.voucher_no) or "" | 				and si_due_date_map.get(gle.voucher_no) or "" | ||||||
| 		 | 		 | ||||||
| 			invoiced_amount = gle.debit > 0 and gle.debit or 0		 | 			invoiced_amount = gle.debit > 0 and gle.debit or 0		 | ||||||
| 			payment_amount = get_payment_amount(gle, filters.get("report_date") or nowdate(),  | 			outstanding_amount = get_outstanding_amount(gle,  | ||||||
| 				entries_after_report_date) | 				filters.get("report_date") or nowdate()) | ||||||
| 			outstanding_amount = invoiced_amount - payment_amount |  | ||||||
| 		 | 		 | ||||||
| 			if abs(flt(outstanding_amount)) > 0.01: | 			if abs(flt(outstanding_amount)) > 0.01: | ||||||
|  | 				payment_amount = invoiced_amount - outstanding_amount | ||||||
| 				row = [gle.posting_date, gle.account, gle.voucher_type, gle.voucher_no,  | 				row = [gle.posting_date, gle.account, gle.voucher_type, gle.voucher_no,  | ||||||
| 					gle.remarks, due_date, account_territory_map.get(gle.account),  | 					gle.remarks, due_date, account_territory_map.get(gle.account),  | ||||||
| 					invoiced_amount, payment_amount, outstanding_amount] | 					invoiced_amount, payment_amount, outstanding_amount] | ||||||
| @ -104,6 +104,16 @@ def get_si_due_date_map(): | |||||||
| 		 | 		 | ||||||
| 	return si_due_date_map | 	return si_due_date_map | ||||||
| 
 | 
 | ||||||
|  | def get_outstanding_amount(gle, report_date): | ||||||
|  | 	payment_amount = webnotes.conn.sql(""" | ||||||
|  | 		select sum(ifnull(credit, 0)) - sum(ifnull(debit, 0))  | ||||||
|  | 		from `tabGL Entry`  | ||||||
|  | 		where account = %s and posting_date <= %s and against_voucher_type = %s  | ||||||
|  | 		and against_voucher = %s and name != %s and ifnull(is_cancelled, 'No') = 'No'""",  | ||||||
|  | 		(gle.account, report_date, gle.voucher_type, gle.voucher_no, gle.name))[0][0] | ||||||
|  | 		 | ||||||
|  | 	return flt(gle.debit) - flt(gle.credit) - flt(payment_amount) | ||||||
|  | 
 | ||||||
| def get_payment_amount(gle, report_date, entries_after_report_date): | def get_payment_amount(gle, report_date, entries_after_report_date): | ||||||
| 	payment_amount = 0 | 	payment_amount = 0 | ||||||
| 	if flt(gle.credit) > 0 and (not gle.against_voucher or  | 	if flt(gle.credit) > 0 and (not gle.against_voucher or  | ||||||
|  | |||||||
| @ -23,7 +23,7 @@ def execute(filters=None): | |||||||
| 	if not filters: filters = {} | 	if not filters: filters = {} | ||||||
| 
 | 
 | ||||||
| 	invoice_list = get_invoices(filters) | 	invoice_list = get_invoices(filters) | ||||||
| 	columns, expense_accounts, tax_accounts, renamed_columns = get_columns(invoice_list) | 	columns, expense_accounts, tax_accounts = get_columns(invoice_list) | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
| 	if not invoice_list: | 	if not invoice_list: | ||||||
| @ -31,7 +31,7 @@ def execute(filters=None): | |||||||
| 		return columns, invoice_list | 		return columns, invoice_list | ||||||
| 	 | 	 | ||||||
| 	invoice_expense_map = get_invoice_expense_map(invoice_list) | 	invoice_expense_map = get_invoice_expense_map(invoice_list) | ||||||
| 	invoice_tax_map = get_invoice_tax_map(invoice_list, renamed_columns) | 	invoice_expense_map, invoice_tax_map = get_invoice_tax_map(invoice_list, invoice_expense_map) | ||||||
| 	invoice_po_pr_map = get_invoice_po_pr_map(invoice_list) | 	invoice_po_pr_map = get_invoice_po_pr_map(invoice_list) | ||||||
| 	account_map = get_account_details(invoice_list) | 	account_map = get_account_details(invoice_list) | ||||||
| 
 | 
 | ||||||
| @ -47,20 +47,27 @@ def execute(filters=None): | |||||||
| 			inv.remarks, ", ".join(purchase_order), ", ".join(purchase_receipt)] | 			inv.remarks, ", ".join(purchase_order), ", ".join(purchase_receipt)] | ||||||
| 		 | 		 | ||||||
| 		# map expense values | 		# map expense values | ||||||
|  | 		net_total = 0 | ||||||
| 		for expense_acc in expense_accounts: | 		for expense_acc in expense_accounts: | ||||||
| 			row.append(invoice_expense_map.get(inv.name, {}).get(expense_acc)) | 			expense_amount = flt(invoice_expense_map.get(inv.name, {}).get(expense_acc)) | ||||||
|  | 			net_total += expense_amount | ||||||
|  | 			row.append(expense_amount) | ||||||
| 		 | 		 | ||||||
| 		# net total | 		# net total | ||||||
| 		row.append(inv.net_total) | 		row.append(net_total) | ||||||
| 			 | 			 | ||||||
| 		# tax account | 		# tax account | ||||||
|  | 		total_tax = 0 | ||||||
| 		for tax_acc in tax_accounts: | 		for tax_acc in tax_accounts: | ||||||
| 			row.append(invoice_tax_map.get(inv.name, {}).get(tax_acc)) | 			if tax_acc not in expense_accounts: | ||||||
|  | 				tax_amount = flt(invoice_tax_map.get(inv.name, {}).get(tax_acc)) | ||||||
|  | 				total_tax += tax_amount | ||||||
|  | 				row.append(tax_amount) | ||||||
| 
 | 
 | ||||||
| 		# total tax, grand total, outstanding amount & rounded total | 		# total tax, grand total, outstanding amount & rounded total | ||||||
| 		row += [inv.total_tax, inv.grand_total, flt(inv.grand_total, 2), \ | 		row += [total_tax, inv.grand_total, flt(inv.grand_total, 2), inv.outstanding_amount] | ||||||
| 			inv.outstanding_amount] |  | ||||||
| 		data.append(row) | 		data.append(row) | ||||||
|  | 		# raise Exception | ||||||
| 	 | 	 | ||||||
| 	return columns, data | 	return columns, data | ||||||
| 	 | 	 | ||||||
| @ -74,7 +81,6 @@ def get_columns(invoice_list): | |||||||
| 		"Purchase Order:Link/Purchase Order:100", "Purchase Receipt:Link/Purchase Receipt:100" | 		"Purchase Order:Link/Purchase Order:100", "Purchase Receipt:Link/Purchase Receipt:100" | ||||||
| 	] | 	] | ||||||
| 	expense_accounts = tax_accounts = expense_columns = tax_columns = [] | 	expense_accounts = tax_accounts = expense_columns = tax_columns = [] | ||||||
| 	renamed_columns = {} |  | ||||||
| 	 | 	 | ||||||
| 	if invoice_list:	 | 	if invoice_list:	 | ||||||
| 		expense_accounts = webnotes.conn.sql_list("""select distinct expense_head  | 		expense_accounts = webnotes.conn.sql_list("""select distinct expense_head  | ||||||
| @ -91,11 +97,7 @@ def get_columns(invoice_list): | |||||||
| 				 | 				 | ||||||
| 	expense_columns = [(account + ":Currency:120") for account in expense_accounts] | 	expense_columns = [(account + ":Currency:120") for account in expense_accounts] | ||||||
| 	for account in tax_accounts: | 	for account in tax_accounts: | ||||||
| 		if account in expense_accounts: | 		if account not in expense_accounts: | ||||||
| 			new_account = account + " (Tax)" |  | ||||||
| 			renamed_columns[account] = new_account |  | ||||||
| 			tax_columns.append(new_account + ":Currency:120") |  | ||||||
| 		else: |  | ||||||
| 			tax_columns.append(account + ":Currency:120") | 			tax_columns.append(account + ":Currency:120") | ||||||
| 	 | 	 | ||||||
| 	columns = columns + expense_columns + \ | 	columns = columns + expense_columns + \ | ||||||
| @ -103,7 +105,7 @@ def get_columns(invoice_list): | |||||||
| 		["Total Tax:Currency:120"] + ["Grand Total:Currency:120"] + \ | 		["Total Tax:Currency:120"] + ["Grand Total:Currency:120"] + \ | ||||||
| 		["Rounded Total:Currency:120"] + ["Outstanding Amount:Currency:120"] | 		["Rounded Total:Currency:120"] + ["Outstanding Amount:Currency:120"] | ||||||
| 
 | 
 | ||||||
| 	return columns, expense_accounts, tax_accounts, renamed_columns | 	return columns, expense_accounts, tax_accounts | ||||||
| 
 | 
 | ||||||
| def get_conditions(filters): | def get_conditions(filters): | ||||||
| 	conditions = "" | 	conditions = "" | ||||||
| @ -119,7 +121,7 @@ def get_conditions(filters): | |||||||
| def get_invoices(filters): | def get_invoices(filters): | ||||||
| 	conditions = get_conditions(filters) | 	conditions = get_conditions(filters) | ||||||
| 	return webnotes.conn.sql("""select name, posting_date, credit_to, supplier, supplier_name,  | 	return webnotes.conn.sql("""select name, posting_date, credit_to, supplier, supplier_name,  | ||||||
| 		bill_no, bill_date, remarks, net_total, total_tax, grand_total, outstanding_amount  | 		bill_no, bill_date, remarks, grand_total, outstanding_amount  | ||||||
| 		from `tabPurchase Invoice` where docstatus = 1 %s  | 		from `tabPurchase Invoice` where docstatus = 1 %s  | ||||||
| 		order by posting_date desc, name desc""" % conditions, filters, as_dict=1) | 		order by posting_date desc, name desc""" % conditions, filters, as_dict=1) | ||||||
| 	 | 	 | ||||||
| @ -136,18 +138,20 @@ def get_invoice_expense_map(invoice_list): | |||||||
| 	 | 	 | ||||||
| 	return invoice_expense_map | 	return invoice_expense_map | ||||||
| 	 | 	 | ||||||
| def get_invoice_tax_map(invoice_list, renamed_columns): | def get_invoice_tax_map(invoice_list, invoice_expense_map): | ||||||
| 	tax_details = webnotes.conn.sql("""select parent, account_head, sum(tax_amount) as tax_amount | 	tax_details = webnotes.conn.sql("""select parent, account_head, sum(tax_amount) as tax_amount | ||||||
| 		from `tabPurchase Taxes and Charges` where parent in (%s) group by parent, account_head""" %  | 		from `tabPurchase Taxes and Charges` where parent in (%s) group by parent, account_head""" %  | ||||||
| 		', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1) | 		', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1) | ||||||
| 	 | 	 | ||||||
| 	invoice_tax_map = {} | 	invoice_tax_map = {} | ||||||
| 	for d in tax_details: | 	for d in tax_details: | ||||||
| 		account = renamed_columns.get(d.account_head) or d.account_head | 		if d.account_head in invoice_expense_map.get(d.parent): | ||||||
| 		invoice_tax_map.setdefault(d.parent, webnotes._dict()).setdefault(account, []) | 			invoice_expense_map[d.parent][d.account_head] += flt(d.tax_amount) | ||||||
| 		invoice_tax_map[d.parent][account] = flt(d.tax_amount) | 		else: | ||||||
|  | 			invoice_tax_map.setdefault(d.parent, webnotes._dict()).setdefault(d.account_head, []) | ||||||
|  | 			invoice_tax_map[d.parent][d.account_head] = flt(d.tax_amount) | ||||||
| 	 | 	 | ||||||
| 	return invoice_tax_map | 	return invoice_expense_map, invoice_tax_map | ||||||
| 	 | 	 | ||||||
| def get_invoice_po_pr_map(invoice_list): | def get_invoice_po_pr_map(invoice_list): | ||||||
| 	pi_items = webnotes.conn.sql("""select parent, purchase_order, purchase_receipt,  | 	pi_items = webnotes.conn.sql("""select parent, purchase_order, purchase_receipt,  | ||||||
|  | |||||||
| @ -23,14 +23,14 @@ def execute(filters=None): | |||||||
| 	if not filters: filters = {} | 	if not filters: filters = {} | ||||||
| 	 | 	 | ||||||
| 	invoice_list = get_invoices(filters) | 	invoice_list = get_invoices(filters) | ||||||
| 	columns, income_accounts, tax_accounts, renamed_columns = get_columns(invoice_list) | 	columns, income_accounts, tax_accounts = get_columns(invoice_list) | ||||||
| 	 | 	 | ||||||
| 	if not invoice_list: | 	if not invoice_list: | ||||||
| 		msgprint(_("No record found"))		 | 		msgprint(_("No record found")) | ||||||
| 		return columns, invoice_list | 		return columns, invoice_list | ||||||
| 	 | 	 | ||||||
| 	invoice_income_map = get_invoice_income_map(invoice_list) | 	invoice_income_map = get_invoice_income_map(invoice_list) | ||||||
| 	invoice_tax_map = get_invoice_tax_map(invoice_list, renamed_columns) | 	invoice_income_map, invoice_tax_map = get_invoice_tax_map(invoice_list, invoice_income_map) | ||||||
| 	 | 	 | ||||||
| 	invoice_so_dn_map = get_invoice_so_dn_map(invoice_list) | 	invoice_so_dn_map = get_invoice_so_dn_map(invoice_list) | ||||||
| 	customer_map = get_customer_deatils(invoice_list) | 	customer_map = get_customer_deatils(invoice_list) | ||||||
| @ -47,18 +47,25 @@ def execute(filters=None): | |||||||
| 			inv.remarks, ", ".join(sales_order), ", ".join(delivery_note)] | 			inv.remarks, ", ".join(sales_order), ", ".join(delivery_note)] | ||||||
| 		 | 		 | ||||||
| 		# map income values | 		# map income values | ||||||
|  | 		net_total = 0 | ||||||
| 		for income_acc in income_accounts: | 		for income_acc in income_accounts: | ||||||
| 			row.append(invoice_income_map.get(inv.name, {}).get(income_acc)) | 			income_amount = flt(invoice_income_map.get(inv.name, {}).get(income_acc)) | ||||||
|  | 			net_total += income_amount | ||||||
|  | 			row.append(income_amount) | ||||||
| 		 | 		 | ||||||
| 		# net total | 		# net total | ||||||
| 		row.append(inv.net_total) | 		row.append(net_total) | ||||||
| 			 | 			 | ||||||
| 		# tax account | 		# tax account | ||||||
|  | 		total_tax = 0 | ||||||
| 		for tax_acc in tax_accounts: | 		for tax_acc in tax_accounts: | ||||||
| 			row.append(invoice_tax_map.get(inv.name, {}).get(tax_acc)) | 			if tax_acc not in income_accounts: | ||||||
|  | 				tax_amount = flt(invoice_tax_map.get(inv.name, {}).get(tax_acc)) | ||||||
|  | 				total_tax += tax_amount | ||||||
|  | 				row.append(tax_amount) | ||||||
| 
 | 
 | ||||||
| 		# total tax, grand total, outstanding amount & rounded total | 		# total tax, grand total, outstanding amount & rounded total | ||||||
| 		row += [inv.other_charges_total, inv.grand_total, inv.rounded_total, inv.outstanding_amount] | 		row += [total_tax, inv.grand_total, inv.rounded_total, inv.outstanding_amount] | ||||||
| 
 | 
 | ||||||
| 		data.append(row) | 		data.append(row) | ||||||
| 	 | 	 | ||||||
| @ -75,7 +82,6 @@ def get_columns(invoice_list): | |||||||
| 	] | 	] | ||||||
| 	 | 	 | ||||||
| 	income_accounts = tax_accounts = income_columns = tax_columns = [] | 	income_accounts = tax_accounts = income_columns = tax_columns = [] | ||||||
| 	renamed_columns = {} |  | ||||||
| 	 | 	 | ||||||
| 	if invoice_list: | 	if invoice_list: | ||||||
| 		income_accounts = webnotes.conn.sql_list("""select distinct income_account  | 		income_accounts = webnotes.conn.sql_list("""select distinct income_account  | ||||||
| @ -85,24 +91,20 @@ def get_columns(invoice_list): | |||||||
| 	 | 	 | ||||||
| 		tax_accounts = 	webnotes.conn.sql_list("""select distinct account_head  | 		tax_accounts = 	webnotes.conn.sql_list("""select distinct account_head  | ||||||
| 			from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice'  | 			from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice'  | ||||||
| 			and docstatus = 1 and ifnull(tax_amount, 0) > 0  | 			and docstatus = 1 and ifnull(tax_amount, 0) != 0  | ||||||
| 			and parent in (%s) order by account_head""" %  | 			and parent in (%s) order by account_head""" %  | ||||||
| 			', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list])) | 			', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list])) | ||||||
| 			 | 
 | ||||||
| 	income_columns = [(account + ":Currency:120") for account in income_accounts] | 	income_columns = [(account + ":Currency:120") for account in income_accounts] | ||||||
| 	for account in tax_accounts: | 	for account in tax_accounts: | ||||||
| 		if account in income_accounts: | 		if account not in income_accounts: | ||||||
| 			new_account = account + " (Tax)" |  | ||||||
| 			renamed_columns[account] = new_account |  | ||||||
| 			tax_columns.append(new_account + ":Currency:120") |  | ||||||
| 		else: |  | ||||||
| 			tax_columns.append(account + ":Currency:120") | 			tax_columns.append(account + ":Currency:120") | ||||||
| 	 | 	 | ||||||
| 	columns = columns + income_columns + ["Net Total:Currency:120"] + tax_columns + \ | 	columns = columns + income_columns + ["Net Total:Currency:120"] + tax_columns + \ | ||||||
| 		["Total Tax:Currency:120"] + ["Grand Total:Currency:120"] + \ | 		["Total Tax:Currency:120"] + ["Grand Total:Currency:120"] + \ | ||||||
| 		["Rounded Total:Currency:120"] + ["Outstanding Amount:Currency:120"] | 		["Rounded Total:Currency:120"] + ["Outstanding Amount:Currency:120"] | ||||||
| 
 | 
 | ||||||
| 	return columns, income_accounts, tax_accounts, renamed_columns | 	return columns, income_accounts, tax_accounts | ||||||
| 
 | 
 | ||||||
| def get_conditions(filters): | def get_conditions(filters): | ||||||
| 	conditions = "" | 	conditions = "" | ||||||
| @ -118,8 +120,8 @@ def get_conditions(filters): | |||||||
| def get_invoices(filters): | def get_invoices(filters): | ||||||
| 	conditions = get_conditions(filters) | 	conditions = get_conditions(filters) | ||||||
| 	return webnotes.conn.sql("""select name, posting_date, debit_to, project_name, customer,  | 	return webnotes.conn.sql("""select name, posting_date, debit_to, project_name, customer,  | ||||||
| 		customer_name, remarks, net_total, other_charges_total, grand_total, rounded_total,  | 		customer_name, remarks, grand_total, rounded_total, outstanding_amount  | ||||||
| 		outstanding_amount from `tabSales Invoice`  | 		from `tabSales Invoice`  | ||||||
| 		where docstatus = 1 %s order by posting_date desc, name desc""" %  | 		where docstatus = 1 %s order by posting_date desc, name desc""" %  | ||||||
| 		conditions, filters, as_dict=1) | 		conditions, filters, as_dict=1) | ||||||
| 	 | 	 | ||||||
| @ -135,18 +137,20 @@ def get_invoice_income_map(invoice_list): | |||||||
| 	 | 	 | ||||||
| 	return invoice_income_map | 	return invoice_income_map | ||||||
| 	 | 	 | ||||||
| def get_invoice_tax_map(invoice_list, renamed_columns): | def get_invoice_tax_map(invoice_list, invoice_income_map): | ||||||
| 	tax_details = webnotes.conn.sql("""select parent, account_head, sum(tax_amount) as tax_amount | 	tax_details = webnotes.conn.sql("""select parent, account_head, sum(tax_amount) as tax_amount | ||||||
| 		from `tabSales Taxes and Charges` where parent in (%s) group by parent, account_head""" %  | 		from `tabSales Taxes and Charges` where parent in (%s) group by parent, account_head""" %  | ||||||
| 		', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1) | 		', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1) | ||||||
| 	 | 	 | ||||||
| 	invoice_tax_map = {} | 	invoice_tax_map = {} | ||||||
| 	for d in tax_details: | 	for d in tax_details: | ||||||
| 		account = renamed_columns.get(d.account_head) or d.account_head | 		if d.account_head in invoice_income_map.get(d.parent): | ||||||
| 		invoice_tax_map.setdefault(d.parent, webnotes._dict()).setdefault(account, []) | 			invoice_income_map[d.parent][d.account_head] += flt(d.tax_amount) | ||||||
| 		invoice_tax_map[d.parent][account] = flt(d.tax_amount) | 		else: | ||||||
|  | 			invoice_tax_map.setdefault(d.parent, webnotes._dict()).setdefault(d.account_head, []) | ||||||
|  | 			invoice_tax_map[d.parent][d.account_head] = flt(d.tax_amount) | ||||||
| 	 | 	 | ||||||
| 	return invoice_tax_map | 	return invoice_income_map, invoice_tax_map | ||||||
| 	 | 	 | ||||||
| def get_invoice_so_dn_map(invoice_list): | def get_invoice_so_dn_map(invoice_list): | ||||||
| 	si_items = webnotes.conn.sql("""select parent, sales_order, delivery_note | 	si_items = webnotes.conn.sql("""select parent, sales_order, delivery_note | ||||||
|  | |||||||
| @ -2,7 +2,7 @@ | |||||||
|  { |  { | ||||||
|   "creation": "2013-02-22 18:01:55",  |   "creation": "2013-02-22 18:01:55",  | ||||||
|   "docstatus": 0,  |   "docstatus": 0,  | ||||||
|   "modified": "2013-05-28 16:03:15",  |   "modified": "2013-07-16 13:19:24",  | ||||||
|   "modified_by": "Administrator",  |   "modified_by": "Administrator",  | ||||||
|   "owner": "Administrator" |   "owner": "Administrator" | ||||||
|  },  |  },  | ||||||
| @ -11,7 +11,7 @@ | |||||||
|   "doctype": "Report",  |   "doctype": "Report",  | ||||||
|   "is_standard": "Yes",  |   "is_standard": "Yes",  | ||||||
|   "name": "__common__",  |   "name": "__common__",  | ||||||
|   "query": "select \n    `tabPurchase Order`.`name` as \"Purchase Order:Link/Purchase Order:120\",\n\t`tabPurchase Order`.`transaction_date` as \"Date:Date:100\",\n\t`tabPurchase Order`.`supplier` as \"Supplier:Link/Supplier:120\",\n\t`tabPurchase Order Item`.`project_name` as \"Project\",\n\t`tabPurchase Order Item`.item_code as \"Item Code:Link/Item:120\",\n\t`tabPurchase Order Item`.qty as \"Qty:Float:100\",\n\t`tabPurchase Order Item`.received_qty as \"Received Qty:Float:100\", \n\t(`tabPurchase Order Item`.qty - ifnull(`tabPurchase Order Item`.received_qty, 0)) as \"Qty to Receive:Float:100\",\n\t`tabPurchase Order Item`.item_name as \"Item Name::150\",\n\t`tabPurchase Order Item`.description as \"Description::200\"\nfrom\n\t`tabPurchase Order`, `tabPurchase Order Item`\nwhere\n\t`tabPurchase Order Item`.`parent` = `tabPurchase Order`.`name`\n\tand `tabPurchase Order`.docstatus = 1\n\tand `tabPurchase Order`.status != \"Stopped\"\n\tand ifnull(`tabPurchase Order Item`.received_qty, 0) < ifnull(`tabPurchase Order Item`.qty, 0)\norder by `tabPurchase Order`.transaction_date asc",  |   "query": "select \n    `tabPurchase Order`.`name` as \"Purchase Order:Link/Purchase Order:120\",\n\t`tabPurchase Order`.`transaction_date` as \"Date:Date:100\",\n\t`tabPurchase Order`.`supplier` as \"Supplier:Link/Supplier:120\",\n\t`tabPurchase Order Item`.`project_name` as \"Project\",\n\t`tabPurchase Order Item`.item_code as \"Item Code:Link/Item:120\",\n\t`tabPurchase Order Item`.qty as \"Qty:Float:100\",\n\t`tabPurchase Order Item`.received_qty as \"Received Qty:Float:100\", \n\t(`tabPurchase Order Item`.qty - ifnull(`tabPurchase Order Item`.received_qty, 0)) as \"Qty to Receive:Float:100\",\n    `tabPurchase Order Item`.warehouse as \"Warehouse:Link/Warehouse:150\",\n\t`tabPurchase Order Item`.item_name as \"Item Name::150\",\n\t`tabPurchase Order Item`.description as \"Description::200\",\n    `tabPurchase Order Item`.brand as \"Brand::100\"\nfrom\n\t`tabPurchase Order`, `tabPurchase Order Item`\nwhere\n\t`tabPurchase Order Item`.`parent` = `tabPurchase Order`.`name`\n\tand `tabPurchase Order`.docstatus = 1\n\tand `tabPurchase Order`.status != \"Stopped\"\n\tand ifnull(`tabPurchase Order Item`.received_qty, 0) < ifnull(`tabPurchase Order Item`.qty, 0)\norder by `tabPurchase Order`.transaction_date asc",  | ||||||
|   "ref_doctype": "Purchase Receipt",  |   "ref_doctype": "Purchase Receipt",  | ||||||
|   "report_name": "Purchase Order Items To Be Received",  |   "report_name": "Purchase Order Items To Be Received",  | ||||||
|   "report_type": "Query Report" |   "report_type": "Query Report" | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user