Check credit limit in Delivery Note / Sales Invoice, only if not created against Sales Order

This commit is contained in:
Nabin Hait 2015-09-08 19:24:35 +05:30
parent 4fb7f881c8
commit cd103c05d6
4 changed files with 29 additions and 7 deletions

View File

@ -88,13 +88,13 @@ class SalesInvoice(SellingController):
self.update_status_updater_args()
self.update_prevdoc_status()
# this sequence because outstanding may get -ve
self.make_gl_entries()
if not self.is_return:
self.update_billing_status_for_zero_amount_refdoc("Sales Order")
self.check_credit_limit()
# this sequence because outstanding may get -ve
self.make_gl_entries()
if not cint(self.is_pos) == 1 and not self.is_return:
self.update_against_document_in_jv()
@ -161,6 +161,17 @@ class SalesInvoice(SellingController):
'extra_cond': """ and exists (select name from `tabSales Invoice` where name=`tabSales Invoice Item`.parent and update_stock=1 and is_return=1)"""
}
])
def check_credit_limit(self):
from erpnext.selling.doctype.customer.customer import check_credit_limit
validate_against_credit_limit = False
for d in self.get("items"):
if not (d.sales_order or d.delivery_note):
validate_against_credit_limit = True
break
if validate_against_credit_limit:
check_credit_limit(self.customer, self.company)
def set_missing_values(self, for_validate=False):
pos = self.set_pos_fields(for_validate)

View File

@ -32,10 +32,6 @@ class SellingController(StockController):
self.validate_max_discount()
check_active_sales_items(self)
def check_credit_limit(self):
from erpnext.selling.doctype.customer.customer import check_credit_limit
check_credit_limit(self.customer, self.company)
def set_missing_values(self, for_validate=False):
super(SellingController, self).set_missing_values(for_validate)

View File

@ -175,6 +175,10 @@ class SalesOrder(SellingController):
self.update_prevdoc_status('cancel')
frappe.db.set(self, 'status', 'Cancelled')
def check_credit_limit(self):
from erpnext.selling.doctype.customer.customer import check_credit_limit
check_credit_limit(self.customer, self.company)
def check_nextdoc_docstatus(self):
# Checks Delivery Note

View File

@ -214,6 +214,17 @@ class DeliveryNote(SellingController):
self.cancel_packing_slips()
self.make_gl_entries_on_cancel()
def check_credit_limit(self):
from erpnext.selling.doctype.customer.customer import check_credit_limit
validate_against_credit_limit = False
for d in self.get("items"):
if not (d.against_sales_order or d.against_sales_invoice):
validate_against_credit_limit = True
break
if validate_against_credit_limit:
check_credit_limit(self.customer, self.company)
def validate_packed_qty(self):
"""