Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disallow mulitple SO with same Purchase Order No if not enabled in Settings (backport #36590) #36680

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -96,18 +96,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 @@ -1741,7 +1741,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 @@ -697,7 +697,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 @@ -724,7 +724,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 @@ -768,7 +768,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 @@ -814,7 +814,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 @@ -1180,6 +1180,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
Loading