Ejemplo n.º 1
0
    def get_html_table(self, columns=None, data=None):

        date_time = global_date_format(now()) + ' ' + format_time(now())
        report_doctype = dataent.db.get_value('Report', self.report,
                                              'ref_doctype')

        return dataent.render_template(
            'dataent/templates/emails/auto_email_report.html', {
                'title':
                self.name,
                'description':
                self.description,
                'date_time':
                date_time,
                'columns':
                columns,
                'data':
                data,
                'report_url':
                get_url_to_report(self.report, self.report_type,
                                  report_doctype),
                'report_name':
                self.report,
                'edit_report_settings':
                get_link_to_form('Auto Email Report', self.name)
            })
Ejemplo n.º 2
0
def execute():
	wrong_records = []
	for dt in ("Quotation", "Sales Order", "Delivery Note", "Sales Invoice", 
		"Purchase Order", "Purchase Receipt", "Purchase Invoice"):
			records = dataent.db.sql_list("""select name from `tab{0}` 
				where apply_discount_on = 'Net Total' and ifnull(discount_amount, 0) != 0
				and modified >= '2015-02-17' and docstatus=1""".format(dt))
		
			if records:
				records = [get_link_to_form(dt, d) for d in records]
				wrong_records.append([dt, records])
				
	if wrong_records:
		content = """Dear System Manager,

Due to an error related to Discount Amount on Net Total, tax calculation might be wrong in the following records. We did not fix the tax amount automatically because it can corrupt the entries, so we request you to check these records and amend if you found the calculation wrong.

Please check following Entries:

%s


Regards,

Administrator""" % "\n".join([(d[0] + ": " + ", ".join(d[1])) for d in wrong_records])
		try:
			sendmail_to_system_managers("[Important] [EPAAS] Tax calculation might be wrong, please check.", content)
		except:
			pass
		
		print("="*50)
		print(content)
		print("="*50)
Ejemplo n.º 3
0
def notify_assignment(assigned_by,
                      owner,
                      doc_type,
                      doc_name,
                      action='CLOSE',
                      description=None,
                      notify=0):
    """
		Notify assignee that there is a change in assignment
	"""
    if not (assigned_by and owner and doc_type and doc_name): return

    # self assignment / closing - no message
    if assigned_by == owner:
        return

    # Search for email address in description -- i.e. assignee
    from dataent.utils import get_link_to_form
    assignment = get_link_to_form(doc_type,
                                  doc_name,
                                  label="%s: %s" % (doc_type, doc_name))
    owner_name = dataent.get_cached_value('User', owner, 'full_name')
    user_name = dataent.get_cached_value('User', dataent.session.user,
                                         'full_name')
    if action == 'CLOSE':
        if owner == dataent.session.get('user'):
            arg = {
                'contact':
                assigned_by,
                'txt':
                _("The task {0}, that you assigned to {1}, has been closed.").
                format(assignment, owner_name)
            }
        else:
            arg = {
                'contact':
                assigned_by,
                'txt':
                _("The task {0}, that you assigned to {1}, has been closed by {2}."
                  ).format(assignment, owner_name, user_name)
            }
    else:
        description_html = "<p>{0}</p>".format(description)
        arg = {
            'contact':
            owner,
            'txt':
            _("A new task, {0}, has been assigned to you by {1}. {2}").format(
                assignment, user_name, description_html),
            'notify':
            notify
        }

    if arg and cint(arg.get("notify")):
        _notify(arg)
Ejemplo n.º 4
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'])
Ejemplo n.º 5
0
def add_comment(doctype, name):
    doc = dataent.get_doc(doctype, name)

    if doctype == "Communication" and doc.reference_doctype and doc.reference_name:
        link = get_link_to_form(
            doc.reference_doctype, doc.reference_name,
            "{0} {1}".format(_(doc.reference_doctype), doc.reference_name))

        doc.add_comment("Like",
                        _("{0}: {1} in {2}").format(
                            _(doc.communication_type),
                            "<b>" + doc.subject + "</b>", link),
                        link_doctype=doc.reference_doctype,
                        link_name=doc.reference_name)

    else:
        doc.add_comment("Like", _("Liked"))
Ejemplo n.º 6
0
    def validate_duplicate(self):
        data = dataent.db.sql(
            """ select name from `tabStudent Leave Application`
			where
				((%(from_date)s > from_date and %(from_date)s < to_date) or
				(%(to_date)s > from_date and %(to_date)s < to_date) or
				(%(from_date)s <= from_date and %(to_date)s >= to_date)) and
				name != %(name)s and student = %(student)s and docstatus < 2
		""", {
                'from_date': self.from_date,
                'to_date': self.to_date,
                'student': self.student,
                'name': self.name
            },
            as_dict=1)

        if data:
            link = get_link_to_form("Student Leave Application", data[0].name)
            dataent.throw(
                _("Leave application {0} already exists against the student {1}"
                  ).format(link, self.student))
Ejemplo n.º 7
0
    def update_delivery_notes(self, delete=False):
        """
		Update all connected Delivery Notes with Delivery Trip details
		(Driver, Vehicle, etc.). If `delete` is `True`, then details
		are removed.

		Args:
			delete (bool, optional): Defaults to `False`. `True` if driver details need to be emptied, else `False`.
		"""

        delivery_notes = list(
            set([
                stop.delivery_note for stop in self.delivery_stops
                if stop.delivery_note
            ]))

        update_fields = {
            "driver": self.driver,
            "driver_name": self.driver_name,
            "vehicle_no": self.vehicle,
            "lr_no": self.name,
            "lr_date": self.departure_time
        }

        for delivery_note in delivery_notes:
            note_doc = dataent.get_doc("Delivery Note", delivery_note)

            for field, value in update_fields.items():
                value = None if delete else value
                setattr(note_doc, field, value)

            note_doc.flags.ignore_validate_update_after_submit = True
            note_doc.save()

        delivery_notes = [
            get_link_to_form("Delivery Note", note) for note in delivery_notes
        ]
        dataent.msgprint(
            _("Delivery Notes {0} updated".format(", ".join(delivery_notes))))
Ejemplo n.º 8
0
def check_if_child_exists(name):
    child_tasks = dataent.get_all("Task", filters={"parent_task": name})
    child_tasks = [get_link_to_form("Task", task.name) for task in child_tasks]
    return child_tasks