Exemplo n.º 1
0
    def notify(self):
        if not frappe.db.get_single_value("Projects Settings",
                                          "send_notifications_for_project"):
            return

        notification_doc = {
            'type':
            'Notify',
            'document_type':
            self.doctype,
            'subject':
            _("Project {0} has been updated.").format(
                "<a href='{0}'>{1}</a>".format(self.get_url(),
                                               frappe.bold(self.name))),
            'document_name':
            self.name,
            'from_user':
            frappe.session.user
        }

        enqueue_create_notification(self.get_assigned_users(),
                                    notification_doc)

        for user in self.get_assigned_users():
            if user == frappe.session.user:
                continue

            frappe.publish_realtime('show_notification_alert',
                                    message=notification_doc.get("subject"),
                                    after_commit=True,
                                    user=user)
Exemplo n.º 2
0
def expire_dx_adv(today=nowdate()):
	for i in range(2):
		adv_idx = str(i)
		# advs = frappe.get_list('Adv Item', filters=[['parentfield','=','adv'+ adv_idx],['date','<=',today], ['type','in',['AC','AT']]], fields=['*'])
		advs = frappe.get_list('Adv Item', filters=[['parentfield','=','adv'+ adv_idx], ['date','<=',today]], fields=['*'])

		for adv in advs:
			# idx = frappe.db.count('SP', {'parent': adv.parent, 'parentfield': 'loan' + suffix })
			# adv = frappe.get_doc("Adv Item", adv.name)
			dx = frappe.get_doc(adv.parenttype, adv.parent)
			dx.append('mkt'+adv.line ,{'date':adv.date,'number': adv.number, 'dppu': adv.dppu, 'type':adv.type, 'line': adv.line, 'note': adv.note, 'territory': adv.territory})
			dx.validate()
			dx.save()
			dppu = frappe.get_doc('DPPU', adv.dppu)
			mkt = frappe.get_doc({'doctype': 'Mkt','date':adv.date,'number': adv.number, 'dppu': adv.dppu, 'line': adv.line, 'note': adv.note, 'territory': adv.territory, 'dx': dx.name, 'dm': dppu.dm_user, 'sm': dppu.sm_user, 'mr': dppu.mr_user}).insert(ignore_permissions=True)
			mkt.submit()
			Event_doc, message = make_to_do(adv.parent, adv.owner, adv.dppu)
			#frappe.delete_doc("SP", adv.name)
			notification_doc = {
				'type': 'To Do',
				'document_type': "",
				'document_name': Event_doc.name,
				'subject': message,
				'from_user': "******",
				'email_content': '<div>{}</div>'.format(message)
			}

			enqueue_create_notification(adv.owner, notification_doc)

	frappe.db.commit()

	return {"status" : "success"}
Exemplo n.º 3
0
    def after_insert(self):
        alert_dict = get_alert_dict(self)
        if alert_dict:
            frappe.publish_realtime('energy_point_alert',
                                    message=alert_dict,
                                    user=self.user)

        frappe.cache().hdel('energy_points', self.user)
        frappe.publish_realtime('update_points', after_commit=True)

        if self.type != 'Review':
            reference_user = self.user if self.type == 'Auto' else self.owner
            notification_doc = {
                'type':
                'Energy Point',
                'document_type':
                self.reference_doctype,
                'document_name':
                self.reference_name,
                'subject':
                get_notification_message(self),
                'from_user':
                reference_user,
                'email_content':
                '<div>{}</div>'.format(self.reason) if self.reason else None
            }

            enqueue_create_notification(self.user, notification_doc)
Exemplo n.º 4
0
def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE',
	description=None):
	"""
		Notify assignee that there is a change in assignment
	"""
	if not (assigned_by and owner and doc_type and doc_name): return

	# return if self assigned or user disabled
	if assigned_by == owner or not frappe.db.get_value('User', owner, 'enabled'):
		return

	# Search for email address in description -- i.e. assignee
	user_name = frappe.get_cached_value('User', frappe.session.user, 'full_name')
	title = get_title(doc_type, doc_name)
	description_html =  "<div>{0}</div>".format(description) if description else None

	if action == 'CLOSE':
		subject = _('Your assignment on {0} {1} has been removed by {2}')\
			.format(frappe.bold(doc_type), get_title_html(title), frappe.bold(user_name))
	else:
		user_name = frappe.bold(user_name)
		document_type = frappe.bold(doc_type)
		title = get_title_html(title)
		subject = _('{0} assigned a new task {1} {2} to you').format(user_name, document_type, title)

	notification_doc = {
		'type': 'Assignment',
		'document_type': doc_type,
		'subject': subject,
		'document_name': doc_name,
		'from_user': frappe.session.user,
		'email_content': description_html
	}

	enqueue_create_notification(owner, notification_doc)
Exemplo n.º 5
0
    def notify_mentions(self):
        if self.reference_doctype and self.reference_name and self.content:
            mentions = extract_mentions(self.content)

            if not mentions:
                return

            sender_fullname = get_fullname(frappe.session.user)
            title = get_title(self.reference_doctype, self.reference_name)

            recipients = [
                frappe.db.get_value(
                    "User", {
                        "enabled": 1,
                        "name": name,
                        "user_type": "System User",
                        "allowed_in_mentions": 1
                    }, "email") for name in mentions
            ]

            notification_message = _('''{0} mentioned you in a comment in {1} {2}''')\
             .format(frappe.bold(sender_fullname), frappe.bold(self.reference_doctype), get_title_html(title))

            notification_doc = {
                'type': 'Mention',
                'document_type': self.reference_doctype,
                'document_name': self.reference_name,
                'subject': notification_message,
                'from_user': frappe.session.user,
                'email_content': self.content
            }

            enqueue_create_notification(recipients, notification_doc)
Exemplo n.º 6
0
    def after_insert(self):
        alert_dict = get_alert_dict(self)
        if alert_dict:
            frappe.publish_realtime("energy_point_alert",
                                    message=alert_dict,
                                    user=self.user)

        frappe.cache().hdel("energy_points", self.user)
        frappe.publish_realtime("update_points", after_commit=True)

        if self.type != "Review" and frappe.get_cached_value(
                "Notification Settings", self.user,
                "energy_points_system_notifications"):

            reference_user = self.user if self.type == "Auto" else self.owner
            notification_doc = {
                "type":
                "Energy Point",
                "document_type":
                self.reference_doctype,
                "document_name":
                self.reference_name,
                "subject":
                get_notification_message(self),
                "from_user":
                reference_user,
                "email_content":
                "<div>{}</div>".format(self.reason) if self.reason else None,
            }

            enqueue_create_notification(self.user, notification_doc)
Exemplo n.º 7
0
	def make_notification_log(self):
		# if self.notes and frappe.session.user != self.owner_user:
			# alert_doc = frappe.get_doc(self.doctype_name,self.doc_name)
			users = [self.owner, self.modified_by]
			notification_doc = {
				'type': 'Share',
				'document_type': self.doctype,
				'subject': self.notes,
				'document_name': self.name,
				'from_user': frappe.session.user
			}
			enqueue_create_notification(users, notification_doc)
Exemplo n.º 8
0
    def make_notification_log(self):
        alert_doc = frappe.get_doc(self.doctype_name, self.doc_name)
        users = [alert_doc.owner, alert_doc.modified_by]
        notification_doc = {
            'type': 'Share',
            'document_type': self.doctype_name,
            'subject': self.subject,
            'document_name': self.doc_name,
            'from_user': frappe.session.user
        }

        enqueue_create_notification(users, notification_doc)
Exemplo n.º 9
0
def notify_assignment(assigned_by,
                      owner,
                      doc_type,
                      doc_name,
                      action="CLOSE",
                      description=None):
    """
	Notify assignee that there is a change in assignment
	"""
    if not (assigned_by and owner and doc_type and doc_name):
        return

    # return if self assigned or user disabled
    if assigned_by == owner or not frappe.db.get_value("User", owner,
                                                       "enabled"):
        return

    # Search for email address in description -- i.e. assignee
    user_name = frappe.get_cached_value("User", frappe.session.user,
                                        "full_name")
    title = get_title(doc_type, doc_name)
    description_html = "<div>{0}</div>".format(
        description) if description else None

    if action == "CLOSE":
        subject = _(
            "Your assignment on {0} {1} has been removed by {2}").format(
                frappe.bold(doc_type), get_title_html(title),
                frappe.bold(user_name))
    else:
        user_name = frappe.bold(user_name)
        document_type = frappe.bold(doc_type)
        title = get_title_html(title)
        subject = _("{0} assigned a new task {1} {2} to you").format(
            user_name, document_type, title)

    notification_doc = {
        "type": "Assignment",
        "document_type": doc_type,
        "subject": subject,
        "document_name": doc_name,
        "from_user": frappe.session.user,
        "email_content": description_html,
    }

    enqueue_create_notification(owner, notification_doc)
Exemplo n.º 10
0
	def create_system_notification(self, doc, context):
		subject = self.subject
		if "{" in subject:
			subject = frappe.render_template(self.subject, context)

		attachments = self.get_attachment(doc)
		recipients, cc, bcc = self.get_list_of_recipients(doc, context)
		users = recipients + cc + bcc

		notification_doc = {
			'type': 'Alert',
			'document_type': doc.doctype,
			'document_name': doc.name,
			'subject': subject,
			'email_content': frappe.render_template(self.message, context),
			'attached_file': attachments and json.dumps(attachments[0])
		}
		enqueue_create_notification(users, notification_doc)
    def make_notification_log(self):
        alert_doc = frappe.get_doc(self.doctype_name, self.doc_name)
        users = []
        owner_email = frappe.get_value("User", alert_doc.owner, "email")
        if owner_email:
            users.append(owner_email)
        modified_by_email = frappe.get_value("User", alert_doc.modified_by,
                                             "email")
        if modified_by_email:
            users.append(modified_by_email)
        if len(users) == 0:
            return
        notification_doc = {
            "type": "Share",
            "document_type": self.doctype_name,
            "subject": self.subject,
            "document_name": self.doc_name,
            "from_user": frappe.session.user,
        }

        enqueue_create_notification(users, notification_doc)
Exemplo n.º 12
0
def notify_assignment(shared_by, doctype, doc_name, everyone):

	if not (shared_by and doctype and doc_name) or everyone: return

	from frappe.utils import get_fullname

	title = get_title(doctype, doc_name)

	reference_user = get_fullname(frappe.session.user)
	notification_message = _('{0} shared a document {1} {2} with you').format(
		frappe.bold(reference_user), frappe.bold(doctype), get_title_html(title))

	notification_doc = {
		'type': 'Share',
		'document_type': doctype,
		'subject': notification_message,
		'document_name': doc_name,
		'from_user': frappe.session.user
	}

	enqueue_create_notification(shared_by, notification_doc)
Exemplo n.º 13
0
def notify_assignment(shared_by, doctype, doc_name, everyone, notify=0):

    if not (shared_by and doctype and doc_name) or everyone or not notify:
        return

    from frappe.utils import get_fullname

    title = get_title(doctype, doc_name)

    reference_user = get_fullname(frappe.session.user)
    notification_message = _("{0} shared a document {1} {2} with you").format(
        frappe.bold(reference_user), frappe.bold(doctype),
        get_title_html(title))

    notification_doc = {
        "type": "Share",
        "document_type": doctype,
        "subject": notification_message,
        "document_name": doc_name,
        "from_user": frappe.session.user,
    }

    enqueue_create_notification(shared_by, notification_doc)
Exemplo n.º 14
0
    def create_system_notification(self, doc, context):
        subject = self.subject
        if "{" in subject:
            subject = frappe.render_template(self.subject, context)

        attachments = self.get_attachment(doc)

        recipients, cc, bcc = self.get_list_of_recipients(doc, context)

        users = recipients + cc + bcc

        if not users:
            return

        notification_doc = {
            "type": "Alert",
            "document_type": doc.doctype,
            "document_name": doc.name,
            "subject": subject,
            "from_user": doc.modified_by or doc.owner,
            "email_content": frappe.render_template(self.message, context),
            "attached_file": attachments and json.dumps(attachments[0]),
        }
        enqueue_create_notification(users, notification_doc)
Exemplo n.º 15
0
def notify_user(erpnext_support_issue):
    if frappe.db.exists("DocType", "Notification Log"):
        from frappe.desk.doctype.notification_log.notification_log import enqueue_create_notification

        erpnext_support_issue = frappe.get_doc("ERPNext Support Issue",
                                               erpnext_support_issue)
        notification_doc = {
            'type':
            'Mention',
            'document_type':
            'ERPNext Support Issue',
            'document_name':
            erpnext_support_issue.name,
            'subject':
            erpnext_support_issue.subject,
            'from_user':
            '******',
            'email_content':
            'You have a new reply for support issue {0}'.format(
                erpnext_support_issue.name)
        }

        enqueue_create_notification(erpnext_support_issue.raised_by,
                                    notification_doc)