From cd103c05d6d16734512d857cd139286851797849 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 8 Sep 2015 19:24:35 +0530 Subject: [PATCH] Check credit limit in Delivery Note / Sales Invoice, only if not created against Sales Order --- .../doctype/sales_invoice/sales_invoice.py | 17 ++++++++++++++--- erpnext/controllers/selling_controller.py | 4 ---- .../selling/doctype/sales_order/sales_order.py | 4 ++++ .../doctype/delivery_note/delivery_note.py | 11 +++++++++++ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 92e3c0dbd6..2ebe25da0c 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -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) diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 569bb82afe..4b44932a88 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -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) diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 065d32938f..8fcff10477 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -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 diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index c8f995cb0e..51d4e403fc 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -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): """