customer_credit_balance.py -- Credit limit should now reflect outstanding amount for each customer based on value of flage bypass credit limit check at sales order level. A new column is added to show the value of this flag. customer.py -- get_credit_limit function which gets called by the above customer_credit_balance report is updated to deduct the amount of sales order for which credit limit bypass flag is set

This commit is contained in:
ashish 2017-10-25 16:17:55 +05:30
parent ff20182d03
commit fb364df091
2 changed files with 30 additions and 10 deletions

View File

@ -170,7 +170,9 @@ def check_credit_limit(customer, company):
throw(_("Please contact to the user who have Sales Master Manager {0} role")
.format(" / " + credit_controller if credit_controller else ""))
def get_customer_outstanding(customer, company):
#PR : 10861, Author : ashish-greycube & jigneshpshah, Email:mr.ashish.shah@gmail.com
# get_customer_outstanding is a very generic function which is invoked from many places. A third non mandatory argument is added to change its behaviour based on caller .
def get_customer_outstanding(customer, company,caller=None):
# Outstanding based on GL Entries
outstanding_based_on_gle = frappe.db.sql("""select sum(debit) - sum(credit)
from `tabGL Entry` where party_type = 'Customer' and party = %s and company=%s""", (customer, company))
@ -186,6 +188,20 @@ def get_customer_outstanding(customer, company):
outstanding_based_on_so = flt(outstanding_based_on_so[0][0]) if outstanding_based_on_so else 0.0
#PR : 10861, Author : ashish-greycube & jigneshpshah, Email:mr.ashish.shah@gmail.com
# Since the credit limit check is bypassed at sales order level, when customer credit balance report is run we need to treat sales order with status 'To Deliver and Bill' as not outstanding
outstanding_based_on_bypassed_so = 0.0
bypass_credit_limit_check_at_sales_order = frappe.db.get_value("Customer", customer, "bypass_credit_limit_check_at_sales_order")
if bypass_credit_limit_check_at_sales_order == 1 and caller=='customer_credit_balance_report':
outstanding_based_on_bypassed_so = frappe.db.sql("""
select (sum(base_grand_total))
from `tabSales Order`
where customer=%s and docstatus = 1 and company=%s
and advance_paid = 0
and per_billed < 100 and status ='To Deliver and Bill'""", (customer, company))
outstanding_based_on_bypassed_so = flt(outstanding_based_on_bypassed_so[0][0]) if outstanding_based_on_bypassed_so else 0.0
# Outstanding based on Delivery Note
unmarked_delivery_note_items = frappe.db.sql("""select
dn_item.name, dn_item.amount, dn.base_net_total, dn.base_grand_total
@ -207,8 +223,8 @@ def get_customer_outstanding(customer, company):
if flt(dn_item.amount) > flt(si_amount) and dn_item.base_net_total:
outstanding_based_on_dn += ((flt(dn_item.amount) - flt(si_amount)) \
/ dn_item.base_net_total) * dn_item.base_grand_total
return outstanding_based_on_gle + outstanding_based_on_so + outstanding_based_on_dn
#PR : 10861, Author : ashish-greycube & jigneshpshah, Email:mr.ashish.shah@gmail.com. In return substract the bypassed SO values
return outstanding_based_on_gle + outstanding_based_on_so + outstanding_based_on_dn - outstanding_based_on_bypassed_so
def get_credit_limit(customer, company):

View File

@ -19,14 +19,15 @@ def execute(filters=None):
for d in customer_list:
row = []
outstanding_amt = get_customer_outstanding(d.name, filters.get("company"))
#PR : 10861, Author : ashish-greycube & jigneshpshah, Email:mr.ashish.shah@gmail.com. 3rd arg is added
outstanding_amt = get_customer_outstanding(d.name, filters.get("company"),'customer_credit_balance_report')
credit_limit = get_credit_limit(d.name, filters.get("company"))
bal = flt(credit_limit) - flt(outstanding_amt)
#PR : 10861, Author : ashish-greycube & jigneshpshah, Email:mr.ashish.shah@gmail.com. Value of new col is passed
if customer_naming_type == "Naming Series":
row = [d.name, d.customer_name, credit_limit, outstanding_amt, bal]
row = [d.name, d.customer_name, d.bypass_credit_limit_check_at_sales_order, credit_limit, outstanding_amt, bal]
else:
row = [d.name, credit_limit, outstanding_amt, bal]
row = [d.name, d.bypass_credit_limit_check_at_sales_order, credit_limit, outstanding_amt, bal]
if credit_limit:
data.append(row)
@ -35,7 +36,9 @@ def execute(filters=None):
def get_columns(customer_naming_type):
columns = [
_("Customer") + ":Link/Customer:120", _("Credit Limit") + ":Currency:120",
#PR : 10861, Author : ashish-greycube & jigneshpshah, Email:mr.ashish.shah@gmail.com
# New column is added to reflect status of bypass credit limit check flag of sales order
_("Customer") + ":Link/Customer:120",_("Bypass credit check at Sales Order ") + ":Check:30", _("Credit Limit") + ":Currency:120",
_("Outstanding Amt") + ":Currency:100", _("Credit Balance") + ":Currency:120"
]
@ -49,6 +52,7 @@ def get_details(filters):
if filters.get("customer"):
conditions += " where name = %(customer)s"
return frappe.db.sql("""select name, customer_name from `tabCustomer` %s"""
#PR : 10861, Author : ashish-greycube & jigneshpshah, Email:mr.ashish.shah@gmail.com
# Return column bypass credit limit check at sales order level
return frappe.db.sql("""select name, customer_name,bypass_credit_limit_check_at_sales_order from `tabCustomer` %s"""
% conditions, filters, as_dict=1)