From 7c831c3fe59b776a26ad3bfa2276aed8f16e3d14 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 19 Sep 2014 14:31:49 +0530 Subject: [PATCH] Get advance in sales/purchase invoice --- erpnext/controllers/accounts_controller.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index bf6a343157..34a342e93f 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -362,6 +362,9 @@ class AccountsController(TransactionBase): def get_advances(self, account_head, child_doctype, parentfield, dr_or_cr, against_order_field): so_list = list(set([d.get(against_order_field) for d in self.get("entries") if d.get(against_order_field)])) + cond = "" + if so_list: + cond = "or (ifnull(t2.%s, '') in (%s))" % ("against_" + against_order_field, ', '.join(['%s']*len(so_list))) res = frappe.db.sql(""" select @@ -376,12 +379,9 @@ class AccountsController(TransactionBase): and ifnull(t2.against_jv, '') = '' and ifnull(t2.against_sales_order, '') = '' and ifnull(t2.against_purchase_order, '') = '' - ) or ( - ifnull(t2.%s, '') in (%s) - ) - ) + ) %s) order by t1.posting_date""" % - (dr_or_cr, '%s', "against_" + against_order_field, ', '.join(['%s']*len(so_list))), + (dr_or_cr, '%s', cond), tuple([account_head] + so_list), as_dict= True) self.set(parentfield, [])