Keep Delivery Trip stops unique based on their Delivery Notes (#15264)
* Keep Delivery Trip stops unique based on their Delivery Notes
* Pull single row when making a Trip from Delivery Note
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py
index 91912cb..15eab9d 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.py
@@ -2,19 +2,18 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
+
import frappe
-
-from frappe.utils import flt, cint
-
-from frappe import msgprint, _
import frappe.defaults
-from frappe.model.utils import get_fetch_values
-from frappe.model.mapper import get_mapped_doc
from erpnext.controllers.selling_controller import SellingController
-from frappe.desk.notifications import clear_doctype_notifications
from erpnext.stock.doctype.batch.batch import set_batch_nos
-from frappe.contacts.doctype.address.address import get_company_address
from erpnext.stock.doctype.serial_no.serial_no import get_delivery_note_serial_no
+from frappe import _
+from frappe.contacts.doctype.address.address import get_company_address
+from frappe.desk.notifications import clear_doctype_notifications
+from frappe.model.mapper import get_mapped_doc
+from frappe.model.utils import get_fetch_values
+from frappe.utils import cint, flt
form_grid_templates = {
"items": "templates/form_grid/item_grid.html"
@@ -170,12 +169,12 @@
if frappe.db.get_value("Item", d.item_code, "is_stock_item") == 1:
if e in check_list:
- msgprint(_("Note: Item {0} entered multiple times").format(d.item_code))
+ frappe.msgprint(_("Note: Item {0} entered multiple times").format(d.item_code))
else:
check_list.append(e)
else:
if f in chk_dupl_itm:
- msgprint(_("Note: Item {0} entered multiple times").format(d.item_code))
+ frappe.msgprint(_("Note: Item {0} entered multiple times").format(d.item_code))
else:
chk_dupl_itm.append(f)
@@ -451,6 +450,11 @@
target_doc.contact = source_parent.contact_person
target_doc.customer_contact = source_parent.contact_display
+ # Append unique Delivery Notes in Delivery Trip
+ delivery_notes.append(target_doc.delivery_note)
+
+ delivery_notes = []
+
doclist = get_mapped_doc("Delivery Note", source_name, {
"Delivery Note": {
"doctype": "Delivery Trip",
@@ -463,7 +467,8 @@
"field_map": {
"parent": "delivery_note"
},
- "postprocess": update_stop_details,
+ "condition": lambda item: item.parent not in delivery_notes,
+ "postprocess": update_stop_details
}
}, target_doc)