Repository: frappe/erpnext
Pull request: fix: completed DC will not appear in a delivery trip
fixes: #41427

Set the condition for the delivery trip so that a completed Delivery Challan (DC) will not appear. Also, add the customer filter in the "Get stops from".

The `docstatus` 1 was removed from the delivery trip due to https://github.com/frappe/erpnext/pull/38559, but `docstatus` 1 is still set in `delivery_note.js`, which is confusing because it is set in one place but not in another.

Currently, I haven't made any changes related to `docstatus`, but if you request, I will also update it in `delivery_note.js`.

**Output:**


https://github.com/frappe/erpnext/assets/141945075/e082f7a1-2813-4479-a6e1-789200bccdeb



Problem statement:
Delivery Trip can still schedule a delivery Note Even Delivery Trip is tagged as Completed
### Information about bug

Using the Old Versions, the delivery trip can filter fetching of delivery notes that are not yet delivered. But on version 14, you can still fetch all delivery notes regardless if it was already visited/delivered or not yet. 

You may encode all delivery notes through the "get stops from" button or manually create it at the delivery note "create" button.

### Module

stock

### Version

ERPNext: v14.69.0 (HEAD)
Frappe Framework: v14.74.0 (HEAD)
Frappe HR: v14.27.1 (HEAD)

### Installation method

FrappeCloud

### Relevant log output / Stack trace / Full Error Message.

_No response_

Hints from issue discussion:

Commit message: fix: completed DC will not appear in a delivery trip

Patch to review:
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js
index 06881c99c125..8e9fbcd2adb7 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.js
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.js
@@ -223,7 +223,7 @@ erpnext.stock.DeliveryNoteController = class DeliveryNoteController extends (
 				);
 			}
 
-			if (doc.docstatus == 1 && frappe.model.can_create("Delivery Trip")) {
+			if (doc.docstatus == 1 && doc.status == "Completed" && frappe.model.can_create("Delivery Trip")) {
 				this.frm.add_custom_button(
 					__("Delivery Trip"),
 					function () {
diff --git a/erpnext/stock/doctype/delivery_trip/delivery_trip.js b/erpnext/stock/doctype/delivery_trip/delivery_trip.js
index e0c20cf1351b..855bccdded5e 100755
--- a/erpnext/stock/doctype/delivery_trip/delivery_trip.js
+++ b/erpnext/stock/doctype/delivery_trip/delivery_trip.js
@@ -58,9 +58,11 @@ frappe.ui.form.on("Delivery Trip", {
 						date_field: "posting_date",
 						setters: {
 							company: frm.doc.company,
+							customer: null,
 						},
 						get_query_filters: {
 							company: frm.doc.company,
+							status: ["Not In", ["Completed", "Cancelled"]],
 						},
 					});
 				},


Code review comments:
diff_hunk: @@ -223,7 +223,7 @@ erpnext.stock.DeliveryNoteController = class DeliveryNoteController extends (
 				);
 			}
 
-			if (doc.docstatus == 1 && frappe.model.can_create("Delivery Trip")) {
+			if (doc.docstatus == 1 && doc.status == "Completed" && frappe.model.can_create("Delivery Trip")) {
path: erpnext/stock/doctype/delivery_note/delivery_note.js
text: @user1:
```suggestion
			if (doc.docstatus == 1 && doc.status != "Completed" && frappe.model.can_create("Delivery Trip")) {
```