From 8ad4efee25a3060b33f05fc82dc8ce1146602f75 Mon Sep 17 00:00:00 2001 From: ashish Date: Wed, 25 Oct 2017 16:07:21 +0530 Subject: [PATCH] sales_order.py -- Three changes are done (a) if bypass credit limit check is enabled we should not check customer credit on submit of sales order (b.1/b.2) There is provision to make delivery note and sales invoice from sales order. Since credit limit is bypassed at sales order level we need to check credit of customer on make of (b.1)delivery note or (b.2)sales invoice --- .../doctype/sales_order/sales_order.py | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index fa21a3d7ee4..d68f09535fa 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -196,7 +196,11 @@ class SalesOrder(SellingController): def check_credit_limit(self): from erpnext.selling.doctype.customer.customer import check_credit_limit - check_credit_limit(self.customer, self.company) + #PR : 10861, Author : ashish-greycube & jigneshpshah, Email:mr.ashish.shah@gmail.com + # bypass credit limit check is set to true (1) at sales order level, then we need not to check credit limit and vise versa + bypass_credit_limit_check_at_sales_order = frappe.db.get_value("Customer", self.customer, "bypass_credit_limit_check_at_sales_order") + if bypass_credit_limit_check_at_sales_order == 0: + check_credit_limit(self.customer, self.company) def check_nextdoc_docstatus(self): # Checks Delivery Note @@ -347,15 +351,15 @@ class SalesOrder(SellingController): return items def on_recurring(self, reference_doc, subscription_doc): - self.set("delivery_date", get_next_schedule_date(reference_doc.delivery_date, - subscription_doc.frequency, cint(subscription_doc.repeat_on_day))) + self.set("delivery_date", get_next_schedule_date(reference_doc.delivery_date, subscription_doc.frequency, + cint(subscription_doc.repeat_on_day))) for d in self.get("items"): reference_delivery_date = frappe.db.get_value("Sales Order Item", {"parent": reference_doc.name, "item_code": d.item_code, "idx": d.idx}, "delivery_date") - d.set("delivery_date", get_next_schedule_date(reference_delivery_date, - subscription_doc.frequency, cint(subscription_doc.repeat_on_day))) + d.set("delivery_date", + get_next_schedule_date(reference_delivery_date, subscription_doc.frequency, cint(subscription_doc.repeat_on_day))) def get_list_context(context=None): from erpnext.controllers.website_list_for_contact import get_list_context @@ -461,6 +465,14 @@ def make_delivery_note(source_name, target_doc=None): target.po_no = ", ".join(list(set(target_po_no))) if len(target_po_no) > 1 else target_po_no[0] else: target.po_no = source.po_no + + #PR : 10861, Author : ashish-greycube & jigneshpshah, Email:mr.ashish.shah@gmail.com + # Since the credit limit check is bypassed at sales order level, we need to check it at delivery note + bypass_credit_limit_check_at_sales_order = frappe.db.get_value("Customer", source.customer, "bypass_credit_limit_check_at_sales_order") + if bypass_credit_limit_check_at_sales_order == 1: + from erpnext.selling.doctype.customer.customer import check_credit_limit + check_credit_limit(source.customer, source.company) + target.ignore_pricing_rule = 1 target.run_method("set_missing_values") @@ -524,6 +536,13 @@ def make_sales_invoice(source_name, target_doc=None, ignore_permissions=False): target.run_method("set_missing_values") target.run_method("calculate_taxes_and_totals") + #PR : 10861, Author : ashish-greycube & jigneshpshah, Email:mr.ashish.shah@gmail.com + # Since the credit limit check is bypassed at sales order level, we need to check it at sales invoice + bypass_credit_limit_check_at_sales_order = frappe.db.get_value("Customer", source.customer, "bypass_credit_limit_check_at_sales_order") + if bypass_credit_limit_check_at_sales_order == 1: + from erpnext.selling.doctype.customer.customer import check_credit_limit + check_credit_limit(source.customer, source.company) + # set company address target.update(get_company_address(target.company)) if target.company_address: