Skip to content

Commit

Permalink
Merge pull request #36620 from frappe/mergify/bp/version-14-hotfix/pr…
Browse files Browse the repository at this point in the history
…-36590

fix: disallow mulitple SO with same Purchase Order No if not enabled in Settings (backport #36590)
  • Loading branch information
ruthra-kumar authored Aug 13, 2023
2 parents 1693905 + 21d3fb0 commit df632d7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
28 changes: 18 additions & 10 deletions erpnext/selling/doctype/sales_order/sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,26 @@ def validate_po(self):
and customer = %s",
(self.po_no, self.name, self.customer),
)
if (
so
and so[0][0]
and not cint(
if so and so[0][0]:
if cint(
frappe.db.get_single_value("Selling Settings", "allow_against_multiple_purchase_orders")
)
):
frappe.msgprint(
_("Warning: Sales Order {0} already exists against Customer's Purchase Order {1}").format(
so[0][0], self.po_no
):
frappe.msgprint(
_("Warning: Sales Order {0} already exists against Customer's Purchase Order {1}").format(
frappe.bold(so[0][0]), frappe.bold(self.po_no)
)
)
else:
frappe.throw(
_(
"Sales Order {0} already exists against Customer's Purchase Order {1}. To allow multiple Sales Orders, Enable {2} in {3}"
).format(
frappe.bold(so[0][0]),
frappe.bold(self.po_no),
frappe.bold(_("'Allow Multiple Sales Orders Against a Customer's Purchase Order'")),
get_link_to_form("Selling Settings", "Selling Settings"),
)
)
)

def validate_for_items(self):
for d in self.get("items"):
Expand Down
2 changes: 1 addition & 1 deletion erpnext/selling/doctype/sales_order/test_sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2023,7 +2023,7 @@ def make_sales_order(**args):
so.company = args.company or "_Test Company"
so.customer = args.customer or "_Test Customer"
so.currency = args.currency or "INR"
so.po_no = args.po_no or "12345"
so.po_no = args.po_no or ""
if args.selling_price_list:
so.selling_price_list = args.selling_price_list

Expand Down
12 changes: 8 additions & 4 deletions erpnext/stock/doctype/delivery_note/test_delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ def test_closed_delivery_note(self):

def test_dn_billing_status_case1(self):
# SO -> DN -> SI
so = make_sales_order()
so = make_sales_order(po_no="12345")
dn = create_dn_against_so(so.name, delivered_qty=2)

self.assertEqual(dn.status, "To Bill")
Expand All @@ -755,7 +755,7 @@ def test_dn_billing_status_case2(self):
make_sales_invoice,
)

so = make_sales_order()
so = make_sales_order(po_no="12345")

si = make_sales_invoice(so.name)
si.get("items")[0].qty = 5
Expand Down Expand Up @@ -799,7 +799,7 @@ def test_dn_billing_status_case3(self):

frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)

so = make_sales_order()
so = make_sales_order(po_no="12345")

dn1 = make_delivery_note(so.name)
dn1.get("items")[0].qty = 2
Expand Down Expand Up @@ -845,7 +845,7 @@ def test_dn_billing_status_case4(self):
from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_delivery_note
from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice

so = make_sales_order()
so = make_sales_order(po_no="12345")

si = make_sales_invoice(so.name)
si.submit()
Expand Down Expand Up @@ -1211,6 +1211,10 @@ def test_batch_expiry_for_delivery_note(self):

self.assertTrue(return_dn.docstatus == 1)

def tearDown(self):
frappe.db.rollback()
frappe.db.set_single_value("Selling Settings", "dont_reserve_sales_order_qty_on_sales_return", 0)


def create_delivery_note(**args):
dn = frappe.new_doc("Delivery Note")
Expand Down

0 comments on commit df632d7

Please sign in to comment.