diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index be876727314..2c96286d3bb 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -118,11 +118,19 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends ( }); 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.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 c202b70dc42..8ed23724dfb 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -2211,7 +2211,9 @@ def make_delivery_note(source_name, target_doc=None): "cost_center": "cost_center", }, "postprocess": update_item, - "condition": lambda doc: doc.delivered_by_supplier != 1 and not doc.dn_detail, + "condition": lambda doc: doc.delivered_by_supplier != 1 + 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": {