fix(delivery): update package total on validate (#16131)
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 4a67eb4..0452132 100755
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -579,3 +579,4 @@
erpnext.patches.v11_0.update_delivery_trip_status
erpnext.patches.v10_0.repost_gle_for_purchase_receipts_with_rejected_items
erpnext.patches.v11_0.set_missing_gst_hsn_code
+erpnext.patches.v11_0.update_package_total_in_delivery_trips
\ No newline at end of file
diff --git a/erpnext/patches/v11_0/update_package_total_in_delivery_trips.py b/erpnext/patches/v11_0/update_package_total_in_delivery_trips.py
new file mode 100755
index 0000000..d609890
--- /dev/null
+++ b/erpnext/patches/v11_0/update_package_total_in_delivery_trips.py
@@ -0,0 +1,7 @@
+import frappe
+
+def execute():
+ for trip in frappe.get_all("Delivery Trip", {"docstatus" : 1}):
+ trip_doc = frappe.get_doc("Delivery Trip", trip.name)
+ total = sum([stop.grand_total for stop in trip_doc.delivery_stops if stop.grand_total])
+ frappe.db.set_value("Delivery Trip", trip.name, "package_total", total, update_modified=False)
\ No newline at end of file
diff --git a/erpnext/stock/doctype/delivery_trip/delivery_trip.py b/erpnext/stock/doctype/delivery_trip/delivery_trip.py
index 01b4734..cafc938 100644
--- a/erpnext/stock/doctype/delivery_trip/delivery_trip.py
+++ b/erpnext/stock/doctype/delivery_trip/delivery_trip.py
@@ -25,6 +25,8 @@
def validate(self):
self.validate_stop_addresses()
+ self.update_status()
+ self.update_package_total()
def on_submit(self):
self.update_status()
@@ -37,11 +39,6 @@
self.update_status()
self.update_delivery_notes(delete=True)
- def validate_stop_addresses(self):
- for stop in self.delivery_stops:
- if not stop.customer_address:
- stop.customer_address = get_address_display(frappe.get_doc("Address", stop.address).as_dict())
-
def update_status(self):
status = {
0: "Draft",
@@ -58,6 +55,14 @@
self.db_set("status", status)
+ def update_package_total(self):
+ self.package_total = sum([stop.grand_total for stop in self.delivery_stops if stop.grand_total])
+
+ def validate_stop_addresses(self):
+ for stop in self.delivery_stops:
+ if not stop.customer_address:
+ stop.customer_address = get_address_display(frappe.get_doc("Address", stop.address).as_dict())
+
def update_delivery_notes(self, delete=False):
"""
Update all connected Delivery Notes with Delivery Trip details