fix(delivery): update package total on validate (#16131)

This commit is contained in:
Rohan 2018-12-10 17:47:31 +05:30 committed by Rushabh Mehta
parent 5472fff027
commit f43433b43d
3 changed files with 18 additions and 5 deletions

View File

@ -579,3 +579,4 @@ erpnext.patches.v10_0.update_user_image_in_employee
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

View File

@ -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)

View File

@ -25,6 +25,8 @@ class DeliveryTrip(Document):
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 @@ class DeliveryTrip(Document):
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 @@ class DeliveryTrip(Document):
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