Esempio n. 1
0
def _notify(args):
    from dataent.utils import get_fullname, get_url

    args = dataent._dict(args)
    contact = args.contact
    txt = args.txt

    try:
        if not isinstance(contact, list):
            contact = [
                dataent.db.get_value("User", contact, "email") or contact
            ]

        dataent.sendmail(\
         recipients=contact,
         sender= dataent.db.get_value("User", dataent.session.user, "email"),
         subject=_("New message from {0}").format(get_fullname(dataent.session.user)),
         template="new_message",
         args={
          "from": get_fullname(dataent.session.user),
          "message": txt,
          "link": get_url()
         },
         header=[_('New Message'), 'orange'])
    except dataent.OutgoingEmailError:
        pass
Esempio n. 2
0
    def validate(self):
        self._assignment = None
        if self.is_new():

            if self.assigned_by == self.owner:
                assignment_message = dataent._(
                    "{0} self assigned this task: {1}").format(
                        get_fullname(self.assigned_by), self.description)
            else:
                assignment_message = dataent._("{0} assigned {1}: {2}").format(
                    get_fullname(self.assigned_by), get_fullname(self.owner),
                    self.description)

            self._assignment = {
                "text": assignment_message,
                "comment_type": "Assigned"
            }

        else:
            # NOTE the previous value is only available in validate method
            if self.get_db_value("status") != self.status:
                self._assignment = {
                    "text":
                    dataent._("Assignment closed by {0}".format(
                        get_fullname(dataent.session.user))),
                    "comment_type":
                    "Assignment Completed"
                }
Esempio n. 3
0
    def on_trash(self):
        if not self.flags.ignore_share_permission:
            self.check_share_permission()

        self.get_doc().add_comment(
            "Unshared",
            _("{0} un-shared this document with {1}").format(
                get_fullname(self.owner), get_fullname(self.user)))
Esempio n. 4
0
    def after_insert(self):
        doc = self.get_doc()
        owner = get_fullname(self.owner)

        if self.everyone:
            doc.add_comment(
                "Shared",
                _("{0} shared this document with everyone").format(owner))
        else:
            doc.add_comment(
                "Shared",
                _("{0} shared this document with {1}").format(
                    owner, get_fullname(self.user)))
Esempio n. 5
0
def get_party(user=None):
	if not user:
		user = dataent.session.user

	contact_name = dataent.db.get_value("Contact", {"email_id": user})
	party = None

	if contact_name:
		contact = dataent.get_doc('Contact', contact_name)
		if contact.links:
			party_doctype = contact.links[0].link_doctype
			party = contact.links[0].link_name

	cart_settings = dataent.get_doc("Shopping Cart Settings")

	debtors_account = ''

	if cart_settings.enable_checkout:
		debtors_account = get_debtors_account(cart_settings)

	if party:
		return dataent.get_doc(party_doctype, party)

	else:
		if not cart_settings.enabled:
			dataent.local.flags.redirect_location = "/contact"
			raise dataent.Redirect
		customer = dataent.new_doc("Customer")
		fullname = get_fullname(user)
		customer.update({
			"customer_name": fullname,
			"customer_type": "Individual",
			"customer_group": get_shopping_cart_settings().default_customer_group,
			"territory": get_root_of("Territory")
		})

		if debtors_account:
			customer.update({
				"accounts": [{
					"company": cart_settings.company,
					"account": debtors_account
				}]
			})

		customer.flags.ignore_mandatory = True
		customer.insert(ignore_permissions=True)

		contact = dataent.new_doc("Contact")
		contact.update({
			"first_name": fullname,
			"email_id": user
		})
		contact.append('links', dict(link_doctype='Customer', link_name=customer.name))
		contact.flags.ignore_mandatory = True
		contact.insert(ignore_permissions=True)

		return customer
Esempio n. 6
0
def get_context(context):
    context.no_cache = True
    data = dataent.db.sql("""select count(*) as translated, modified_by
		from `tabTranslated Message`
		where modified_by != "Administrator"
		group by modified_by order by translated desc limit 20""",
                          as_dict=1)

    for d in data:
        d.fullname = get_fullname(d.modified_by)

    context.users = data
Esempio n. 7
0
    def get_context(self, context):
        # this is for double precaution. usually it wont reach this code if not published
        if not cint(self.published):
            raise Exception("This blog has not been published yet!")

        # temp fields
        context.full_name = get_fullname(self.owner)
        context.updated = global_date_format(self.published_on)

        if self.blogger:
            context.blogger_info = dataent.get_doc("Blogger",
                                                   self.blogger).as_dict()

        context.description = self.blog_intro or self.content[:140]

        context.metatags = {
            "name": self.title,
            "description": context.description,
        }

        if "<!-- markdown -->" in context.content:
            context.content = markdown(context.content)

        image = find_first_image(self.content)
        if image:
            context.metatags["image"] = image

        context.comment_list = get_comment_list(self.doctype, self.name)
        if not context.comment_list:
            context.comment_text = _('No comments yet')
        else:
            if (len(context.comment_list)) == 1:
                context.comment_text = _('1 comment')
            else:
                context.comment_text = _('{0} comments').format(
                    len(context.comment_list))

        context.category = dataent.db.get_value("Blog Category",
                                                context.doc.blog_category,
                                                ["title", "route"],
                                                as_dict=1)
        context.parents = [{
            "name": _("Home"),
            "route": "/"
        }, {
            "name": "Blog",
            "route": "/blog"
        }, {
            "label": context.category.title,
            "route": context.category.route
        }]
Esempio n. 8
0
    def make_new_lead_if_required(self):
        """Set lead against new opportunity"""
        if (not self.get("party_name")) and self.contact_email:
            # check if customer is already created agains the self.contact_email
            customer = dataent.db.sql("""select
				distinct `tabDynamic Link`.link_name as customer
				from
					`tabContact`,
					`tabDynamic Link`
				where `tabContact`.email_id='{0}'
				and
					`tabContact`.name=`tabDynamic Link`.parent
				and
					ifnull(`tabDynamic Link`.link_name, '')<>''
				and
					`tabDynamic Link`.link_doctype='Customer'
			""".format(self.contact_email),
                                      as_dict=True)
            if customer and customer[0].customer:
                self.party_name = customer[0].customer
                self.opportunity_from = "Customer"
                return

            lead_name = dataent.db.get_value("Lead",
                                             {"email_id": self.contact_email})
            if not lead_name:
                sender_name = get_fullname(self.contact_email)
                if sender_name == self.contact_email:
                    sender_name = None

                if not sender_name and ('@' in self.contact_email):
                    email_name = self.contact_email.split('@')[0]

                    email_split = email_name.split('.')
                    sender_name = ''
                    for s in email_split:
                        sender_name += s.capitalize() + ' '

                lead = dataent.get_doc({
                    "doctype": "Lead",
                    "email_id": self.contact_email,
                    "lead_name": sender_name or 'Unknown'
                })

                lead.flags.ignore_email_validation = True
                lead.insert(ignore_permissions=True)
                lead_name = lead.name

            self.opportunity_from = "Lead"
            self.party_name = lead_name
Esempio n. 9
0
def notify_mentions(doc):
    if doc.communication_type != "Comment":
        return

    if doc.reference_doctype and doc.reference_name and doc.content and doc.comment_type == "Comment":
        mentions = extract_mentions(doc.content)

        if not mentions:
            return

        sender_fullname = get_fullname(dataent.session.user)
        title_field = dataent.get_meta(doc.reference_doctype).get_title_field()
        title = doc.reference_name if title_field == "name" else \
         dataent.db.get_value(doc.reference_doctype, doc.reference_name, title_field)

        if title != doc.reference_name:
            parent_doc_label = "{0}: {1} (#{2})".format(
                _(doc.reference_doctype), title, doc.reference_name)
        else:
            parent_doc_label = "{0}: {1}".format(_(doc.reference_doctype),
                                                 doc.reference_name)

        subject = _("{0} mentioned you in a comment").format(sender_fullname)

        recipients = [
            dataent.db.get_value("User", {
                "enabled": 1,
                "name": name,
                "user_type": "System User"
            }, "email") for name in mentions
        ]
        link = get_link_to_form(doc.reference_doctype,
                                doc.reference_name,
                                label=parent_doc_label)

        dataent.sendmail(recipients=recipients,
                         sender=dataent.session.user,
                         subject=subject,
                         template="mentioned_in_comment",
                         args={
                             "body_content":
                             _("{0} mentioned you in a comment in {1}").format(
                                 sender_fullname, link),
                             "comment":
                             doc,
                             "link":
                             link
                         },
                         header=[_('New Mention'), 'orange'])
Esempio n. 10
0
def insert_feed(doc):
    from dataent.utils import get_fullname

    if dataent.flags.in_install or dataent.flags.in_import or getattr(
            doc, "no_feed_on_delete", False):
        return

    dataent.get_doc({
        "doctype": "Communication",
        "communication_type": "Comment",
        "comment_type": "Deleted",
        "reference_doctype": doc.doctype,
        "subject": "{0} {1}".format(_(doc.doctype), doc.name),
        "full_name": get_fullname(doc.owner)
    }).insert(ignore_permissions=True)
Esempio n. 11
0
def update_feed(doc, method=None):
    if dataent.flags.in_patch or dataent.flags.in_install or dataent.flags.in_import:
        return

    if doc._action != "save" or doc.flags.ignore_feed:
        return

    if doc.doctype == "Activity Log" or doc.meta.issingle:
        return

    if hasattr(doc, "get_feed"):
        feed = doc.get_feed()

        if feed:
            if isinstance(feed, string_types):
                feed = {"subject": feed}

            feed = dataent._dict(feed)
            doctype = feed.doctype or doc.doctype
            name = feed.name or doc.name

            # delete earlier feed
            dataent.db.sql(
                """delete from `tabActivity Log`
				where
					reference_doctype=%s and reference_name=%s
					and link_doctype=%s""", (doctype, name, feed.link_doctype))
            dataent.get_doc({
                "doctype":
                "Activity Log",
                "reference_doctype":
                doctype,
                "reference_name":
                name,
                "subject":
                feed.subject,
                "full_name":
                get_fullname(doc.owner),
                "reference_owner":
                dataent.db.get_value(doctype, name, "owner"),
                "link_doctype":
                feed.link_doctype,
                "link_name":
                feed.link_name
            }).insert(ignore_permissions=True)
Esempio n. 12
0
def get_upgrade_url(upgrade_url):
    parts = urlsplit(upgrade_url)
    params = dict(parse_qsl(parts.query))
    params.update({
        'site':
        dataent.local.site,
        'email':
        dataent.session.user,
        'full_name':
        get_fullname(),
        'country':
        dataent.db.get_value("System Settings", "System Settings", 'country')
    })

    query = urlencode(params, doseq=True)
    url = urlunsplit(
        (parts.scheme, parts.netloc, parts.path, query, parts.fragment))
    return url
Esempio n. 13
0
def execute():
    for user_id in dataent.db.sql_list(
            """select distinct user_id from `tabEmployee`
		where ifnull(user_id, '')!=''
		group by user_id having count(name) > 1"""):

        fullname = get_fullname(user_id)
        employee = dataent.db.get_value("Employee", {
            "employee_name": fullname,
            "user_id": user_id
        })

        if employee:
            dataent.db.sql(
                """update `tabEmployee` set user_id=null
				where user_id=%s and name!=%s""", (user_id, employee))
        else:
            count = dataent.db.sql(
                """select count(*) from `tabEmployee` where user_id=%s""",
                user_id)[0][0]
            dataent.db.sql(
                """update `tabEmployee` set user_id=null
				where user_id=%s limit %s""", (user_id, count - 1))
Esempio n. 14
0
 def before_insert(self):
     self.full_name = get_fullname(self.user)
     self.date = now()
Esempio n. 15
0
def logout_feed(user, reason):
    if user and user != "Guest":
        subject = _("{0} logged out: {1}").format(get_fullname(user),
                                                  dataent.bold(reason))
        add_authentication_log(subject, user, operation="Logout")
Esempio n. 16
0
def login_feed(login_manager):
    if login_manager.user != "Guest":
        subject = _("{0} logged in").format(get_fullname(login_manager.user))
        add_authentication_log(subject, login_manager.user)