Merge pull request #39830 from Nihantra-Patel/fix_check_credit_limit

fix: check_credit_limit on_update_after_submit of Sales Order
This commit is contained in:
ruthra kumar 2024-02-23 14:20:36 +05:30 committed by GitHub
commit 97c3e27c60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 5 deletions

View File

@ -297,11 +297,35 @@ class TestCustomer(FrappeTestCase):
if credit_limit > outstanding_amt:
set_credit_limit("_Test Customer", "_Test Company", credit_limit)
# Makes Sales invoice from Sales Order
so.save(ignore_permissions=True)
si = make_sales_invoice(so.name)
si.save(ignore_permissions=True)
self.assertRaises(frappe.ValidationError, make_sales_order)
def test_customer_credit_limit_after_submit(self):
from erpnext.controllers.accounts_controller import update_child_qty_rate
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
outstanding_amt = self.get_customer_outstanding_amount()
credit_limit = get_credit_limit("_Test Customer", "_Test Company")
if outstanding_amt <= 0.0:
item_qty = int((abs(outstanding_amt) + 200) / 100)
make_sales_order(qty=item_qty)
if credit_limit <= 0.0:
set_credit_limit("_Test Customer", "_Test Company", outstanding_amt + 100)
so = make_sales_order(rate=100, qty=1)
# Update qty in submitted Sales Order to trigger Credit Limit validation
fields = ["name", "item_code", "delivery_date", "conversion_factor", "qty", "rate", "uom", "idx"]
modified_item = frappe._dict()
for x in fields:
modified_item[x] = so.items[0].get(x)
modified_item["docname"] = so.items[0].name
modified_item["qty"] = 2
self.assertRaises(
frappe.ValidationError,
update_child_qty_rate,
so.doctype,
frappe.json.dumps([modified_item]),
so.name,
)
def test_customer_credit_limit_on_change(self):
outstanding_amt = self.get_customer_outstanding_amount()

View File

@ -515,6 +515,9 @@ class SalesOrder(SellingController):
def on_update(self):
pass
def on_update_after_submit(self):
self.check_credit_limit()
def before_update_after_submit(self):
self.validate_po()
self.validate_drop_ship()