From 30e6b5daac923dc0977ab897ab5641e3bf499d0d Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Wed, 21 Jan 2026 17:13:35 +0530 Subject: [PATCH] fix: create DN btn should not be shown if it cannot be created (cherry picked from commit 70ec977cb25a8217b4ec361fac0917a4874c7fea) --- .../doctype/sales_invoice/sales_invoice.js | 17 +++++++++++++---- .../doctype/sales_invoice/sales_invoice.py | 3 ++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index caafdcedc23..0ba6feef6da 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -116,11 +116,20 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends ( if (cint(doc.update_stock) != 1) { if (!is_delivered_by_supplier) { - this.frm.add_custom_button( - __("Delivery Note"), - this.frm.cscript["Make Delivery Note"], - __("Create") + const should_create_delivery_note = doc.items.some( + (item) => + item.qty - item.delivered_qty > 0 && + !item.scio_detail && + !item.dn_detail && + !item.delivered_by_supplier ); + if (should_create_delivery_note) { + this.frm.add_custom_button( + __("Delivery Note"), + this.frm.cscript["Make Delivery Note"], + __("Create") + ); + } } } diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index befa1ddea24..a87ad06564e 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -2424,7 +2424,8 @@ def make_delivery_note(source_name, target_doc=None): "postprocess": update_item, "condition": lambda doc: doc.delivered_by_supplier != 1 and not doc.scio_detail - and not doc.dn_detail, + and not doc.dn_detail + and doc.qty - doc.delivered_qty > 0, }, "Sales Taxes and Charges": {"doctype": "Sales Taxes and Charges", "reset_value": True}, "Sales Team": {