fix(ux): don't show `Create > Packing Slip` button if items are already packed
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js
index ae56645..08419c2 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.js
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.js
@@ -185,11 +185,30 @@
}
if(doc.docstatus==0 && !doc.__islocal) {
- this.frm.add_custom_button(__('Packing Slip'), function() {
- frappe.model.open_mapped_doc({
- method: "erpnext.stock.doctype.delivery_note.delivery_note.make_packing_slip",
- frm: me.frm
- }) }, __('Create'));
+ var remaining_qty = 0;
+
+ doc.items.forEach(item => {
+ frappe.db.exists("Product Bundle", item.item_code).then(exists => {
+ if (!exists) {
+ remaining_qty += (item.qty - item.packed_qty);
+ }
+ });
+ });
+
+ if (!remaining_qty) {
+ doc.packed_items.forEach(item => {
+ remaining_qty += (item.qty - item.packed_qty);
+ });
+ }
+
+ if (remaining_qty > 0) {
+ this.frm.add_custom_button(__('Packing Slip'), function() {
+ frappe.model.open_mapped_doc({
+ method: "erpnext.stock.doctype.delivery_note.delivery_note.make_packing_slip",
+ frm: me.frm
+ }) }, __('Create')
+ );
+ }
}
if (!doc.__islocal && doc.docstatus==1) {