Skip to content

Commit

Permalink
test: credit check on Sales Order re-open
Browse files Browse the repository at this point in the history
  • Loading branch information
ruthra-kumar committed Jul 1, 2024
1 parent 5eed781 commit 60694e0
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion erpnext/selling/doctype/sales_order/test_sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.utils import add_days, flt, getdate, nowdate, today

from erpnext.accounts.test.accounts_mixin import AccountsTestMixin
from erpnext.controllers.accounts_controller import InvalidQtyError, update_child_qty_rate
from erpnext.maintenance.doctype.maintenance_schedule.test_maintenance_schedule import (
make_maintenance_schedule,
Expand All @@ -32,7 +33,7 @@
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry


class TestSalesOrder(FrappeTestCase):
class TestSalesOrder(AccountsTestMixin, FrappeTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand All @@ -48,6 +49,9 @@ def tearDownClass(cls) -> None:
)
super().tearDownClass()

def setUp(self):
self.create_customer("_Test Customer Credit")

def tearDown(self):
frappe.set_user("Administrator")

Expand Down Expand Up @@ -2171,6 +2175,28 @@ def test_auto_update_price_list(self):
frappe.db.set_single_value("Stock Settings", "update_existing_price_list_rate", 0)
frappe.db.set_single_value("Stock Settings", "auto_insert_price_list_rate_if_missing", 0)

def test_credit_limit_on_so_reopning(self):
# set credit limit
company = "_Test Company"
customer = frappe.get_doc("Customer", self.customer)
customer.credit_limits = []
customer.append(
"credit_limits", {"company": company, "credit_limit": 1000, "bypass_credit_limit_check": False}
)
customer.save()

so1 = make_sales_order(qty=9, rate=100, do_not_submit=True)
so1.customer = self.customer
so1.save().submit()

so1.update_status("Closed")

so2 = make_sales_order(qty=9, rate=100, do_not_submit=True)
so2.customer = self.customer
so2.save().submit()

self.assertRaises(frappe.ValidationError, so1.update_status, "Draft")


def automatically_fetch_payment_terms(enable=1):
accounts_settings = frappe.get_doc("Accounts Settings")
Expand Down

0 comments on commit 60694e0

Please sign in to comment.