Exemple #1
0
    def validate_reference(self):
        if self.reference_doctype and self.reference_name:
            if not self.reference_owner:
                self.reference_owner = frappe.db.get_value(
                    self.reference_doctype, self.reference_name, "owner")

            # prevent communication against a child table
            if frappe.get_meta(self.reference_doctype).istable:
                frappe.throw(
                    _("Cannot create a {0} against a child document: {1}"
                      ).format(_(self.communication_type),
                               _(self.reference_doctype)))

            # Prevent circular linking of Communication DocTypes
            if self.reference_doctype == "Communication":
                circular_linking = False
                doc = get_parent_doc(self)
                while doc.reference_doctype == "Communication":
                    if get_parent_doc(doc).name == self.name:
                        circular_linking = True
                        break
                    doc = get_parent_doc(doc)

                if circular_linking:
                    frappe.throw(
                        _("Please make sure the Reference Communication Docs are not circularly linked."
                          ), frappe.CircularLinkingError)
Exemple #2
0
def update_parent_mins_to_first_response(doc):
    """Update mins_to_first_communication of parent document based on who is replying."""

    parent = get_parent_doc(doc)
    if not parent:
        return

    # update parent mins_to_first_communication only if we create the Email communication
    # ignore in case of only Comment is added
    if doc.communication_type == "Comment":
        return

    status_field = parent.meta.get_field("status")
    if status_field:
        options = (status_field.options or '').splitlines()

        # if status has a "Replied" option, then update the status for received communication
        if ('Replied' in options) and doc.sent_or_received == "Received":
            parent.db_set("status", "Open")
        else:
            # update the modified date for document
            parent.update_modified()

    update_mins_to_first_communication(parent, doc)
    parent.run_method('notify_communication', doc)
    parent.notify_update()
Exemple #3
0
def update_parent_mins_to_first_response(doc):
	"""Update mins_to_first_communication of parent document based on who is replying."""

	parent = get_parent_doc(doc)
	if not parent:
		return

	# update parent mins_to_first_communication only if we create the Email communication
	# ignore in case of only Comment is added
	if doc.communication_type == "Comment":
		return

	status_field = parent.meta.get_field("status")
	if status_field:
		options = (status_field.options or '').splitlines()

		# if status has a "Replied" option, then update the status for received communication
		if ('Replied' in options) and doc.sent_or_received=="Received":
			parent.db_set("status", "Open")
		else:
			# update the modified date for document
			parent.update_modified()

	update_mins_to_first_communication(parent, doc)
	parent.run_method('notify_communication', doc)
	parent.notify_update()
Exemple #4
0
def set_first_response_time(communication, method):
    if communication.get("reference_doctype") == "Issue":
        issue = get_parent_doc(communication)
        if is_first_response(issue) and issue.service_level_agreement:
            first_response_time = calculate_first_response_time(
                issue, get_datetime(issue.first_responded_on))
            issue.db_set("first_response_time", first_response_time)
Exemple #5
0
def get_attach_link(doc, print_format):
	"""Returns public link for the attachment via `templates/emails/print_link.html`."""
	return frappe.get_template("templates/emails/print_link.html").render({
		"url": get_url(),
		"doctype": doc.reference_doctype,
		"name": doc.reference_name,
		"print_format": print_format,
		"key": get_parent_doc(doc).get_signature()
	})
Exemple #6
0
def get_attach_link(doc, print_format):
	"""Returns public link for the attachment via `templates/emails/print_link.html`."""
	return frappe.get_template("templates/emails/print_link.html").render({
		"url": get_url(),
		"doctype": doc.reference_doctype,
		"name": doc.reference_name,
		"print_format": print_format,
		"key": get_parent_doc(doc).get_signature()
	})
Exemple #7
0
	def validate_reference(self):
		if self.reference_doctype and self.reference_name:
			if not self.reference_owner:
				self.reference_owner = frappe.db.get_value(self.reference_doctype, self.reference_name, "owner")

			# prevent communication against a child table
			if frappe.get_meta(self.reference_doctype).istable:
				frappe.throw(_("Cannot create a {0} against a child document: {1}")
					.format(_(self.communication_type), _(self.reference_doctype)))

			# Prevent circular linking of Communication DocTypes
			if self.reference_doctype == "Communication":
				circular_linking = False
				doc = get_parent_doc(self)
				while doc.reference_doctype == "Communication":
					if get_parent_doc(doc).name==self.name:
						circular_linking = True
						break
					doc = get_parent_doc(doc)
				if circular_linking:
					frappe.throw(_("Please make sure the Reference Communication Docs are not circularly linked."), frappe.CircularLinkingError)
Exemple #8
0
def on_communication_update(doc, status):
    if doc.communication_type == "Comment":
        return

    parent = get_parent_doc(doc)
    if not parent:
        return

    if not parent.meta.has_field("service_level_agreement"):
        return

    if (doc.sent_or_received == "Received"  # a reply is received
            and parent.get("status") ==
            "Open"  # issue status is set as open from communication.py
            and parent.get_doc_before_save() and parent.get("status") !=
            parent._doc_before_save.get("status")  # status changed
        ):
        # undo the status change in db
        # since prev status is fetched from db
        frappe.db.set_value(
            parent.doctype,
            parent.name,
            "status",
            parent._doc_before_save.get("status"),
            update_modified=False,
        )

    elif (doc.sent_or_received == "Sent"  # a reply is sent
          and parent.get("first_responded_on"
                         )  # first_responded_on is set from communication.py
          and parent.get_doc_before_save() and not parent._doc_before_save.get(
              "first_responded_on")  # first_responded_on was not set
          ):
        # reset first_responded_on since it will be handled/set later on
        parent.first_responded_on = None
        parent.flags.on_first_reply = True

    else:
        return

    for_resolution = frappe.db.get_value("Service Level Agreement",
                                         parent.service_level_agreement,
                                         "apply_sla_for_resolution")

    handle_status_change(parent, for_resolution)
    update_response_and_resolution_metrics(parent, for_resolution)
    update_agreement_status(parent, for_resolution)

    parent.save(ignore_permissions=True)
Exemple #9
0
def get_owner_email(doc):
    owner = get_parent_doc(doc).owner
    return get_formatted_email(owner) or owner
Exemple #10
0
def get_owner_email(doc):
	owner = get_parent_doc(doc).owner
	return get_formatted_email(owner) or owner
Exemple #11
0
	def get_owner(self):
		"""Get owner of the communication docs parent.
		"""
		parent_doc = get_parent_doc(self)
		return parent_doc.owner if parent_doc else None