Ejemplo n.º 1
0
    def update_stop_details(source_doc, target_doc, source_parent):
        from erpnext.stock.doctype.delivery_trip.delivery_trip import get_delivery_window  #To resolve Cyclic Dependency, Please Keep it inside the function
        delivery_window = get_delivery_window(source_parent.doctype,
                                              source_parent.name)
        target_doc.delivery_start_time = delivery_window.delivery_start_time
        target_doc.delivery_end_time = delivery_window.delivery_end_time
        target_doc.customer = source_parent.customer
        target_doc.address = source_parent.shipping_address_name
        target_doc.customer_address = source_parent.shipping_address
        target_doc.contact = source_parent.contact_person
        target_doc.customer_contact = source_parent.contact_display
        target_doc.grand_total = source_parent.grand_total

        # Append unique Delivery Notes in Delivery Trip
        delivery_notes.append(target_doc.delivery_note)
Ejemplo n.º 2
0
def validate_delivery_window(doc, method):
	from erpnext.stock.doctype.delivery_trip.delivery_trip import get_delivery_window
	if not frappe.db.get_single_value("Delivery Settings", "send_delivery_window_warning"):
		return

	if not (doc.get("delivery_start_time") and doc.get("delivery_end_time")):
		return

	if not doc.get("customer"):
		return

	delivery_window = get_delivery_window(customer=doc.get("customer"))
	delivery_start_time = delivery_window.delivery_start_time
	delivery_end_time = delivery_window.delivery_end_time

	if not (delivery_start_time and delivery_end_time):
		return

	if to_timedelta(doc.delivery_start_time) < to_timedelta(delivery_start_time) \
		or to_timedelta(doc.delivery_end_time) > to_timedelta(delivery_end_time):
		if method == "validate":
			frappe.msgprint(_("The delivery window is set outside the customer's default timings"))
		elif method == "on_submit":
			# send an email notifying users that the document is outside the customer's delivery window
			role_profiles = ["Fulfillment Manager"]
			role_profile_users = frappe.get_all("User", filters={"role_profile_name": ["IN", role_profiles]}, fields=["email"])
			role_profile_users = [user.email for user in role_profile_users]

			accounts_managers = get_users_with_role("Accounts Manager")
			system_managers = get_users_with_role("System Manager")

			recipients = list(set(role_profile_users + accounts_managers) - set(system_managers))

			if not recipients:
				return

			# form the email
			subject = _("[Info] An order may be delivered outside a customer's preferred delivery window")
			message = _("""An order ({name}) has the following delivery window: {doc_start} - {doc_end}<br><br>
				While the default delivery window is {customer_start} - {customer_end}""".format(
					name=frappe.utils.get_link_to_form(doc.doctype, doc.name),
					doc_start=get_time(doc.delivery_start_time).strftime("%I:%M %p"),
					doc_end=get_time(doc.delivery_end_time).strftime("%I:%M %p"),
					customer_start=get_time(delivery_start_time).strftime("%I:%M %p"),
					customer_end=get_time(delivery_end_time).strftime("%I:%M %p"),
				))

			frappe.sendmail(recipients=recipients, subject=subject, message=message)
Ejemplo n.º 3
0
	def update_stop_details(source_doc, target_doc, source_parent):
		# to avoid cyclic dependencies with delivery trip
		from erpnext.stock.doctype.delivery_trip.delivery_trip import get_delivery_window

		delivery_window = get_delivery_window(source_parent.doctype, source_parent.name)
		target_doc.delivery_start_time = delivery_window.delivery_start_time
		target_doc.delivery_end_time = delivery_window.delivery_end_time
		target_doc.customer = source_parent.customer
		target_doc.address = source_parent.shipping_address_name
		target_doc.customer_address = source_parent.shipping_address
		target_doc.contact = source_parent.contact_person
		target_doc.customer_contact = source_parent.contact_display
		target_doc.grand_total = source_parent.grand_total

		# Append unique Delivery Notes in Delivery Trip
		delivery_notes.append(target_doc.delivery_note)