email to leave approver and employee
This commit is contained in:
parent
fb67605042
commit
0bf801af62
@ -18,19 +18,19 @@ from __future__ import unicode_literals
|
|||||||
import webnotes
|
import webnotes
|
||||||
from webnotes import _
|
from webnotes import _
|
||||||
|
|
||||||
from webnotes.utils import cint, cstr, date_diff, flt, formatdate, getdate
|
from webnotes.utils import cint, cstr, date_diff, flt, formatdate, getdate, get_url_to_form, get_fullname
|
||||||
from webnotes.model import db_exists
|
from webnotes import msgprint
|
||||||
from webnotes.model.wrapper import copy_doclist
|
from webnotes.utils.email_lib import sendmail
|
||||||
from webnotes import form, msgprint
|
|
||||||
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
class LeaveDayBlockedError(Exception): pass
|
class LeaveDayBlockedError(Exception): pass
|
||||||
|
|
||||||
class DocType:
|
from webnotes.model.controller import DocListController
|
||||||
def __init__(self, doc, doclist):
|
class DocType(DocListController):
|
||||||
self.doc = doc
|
def setup(self):
|
||||||
self.doclist = doclist
|
if webnotes.conn.exists(self.doc.doctype, self.doc.name):
|
||||||
|
self.previous_doc = webnotes.doc(self.doc.doctype, self.doc.name)
|
||||||
|
else:
|
||||||
|
self.previous_doc = None
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
# if self.doc.leave_approver == self.doc.owner:
|
# if self.doc.leave_approver == self.doc.owner:
|
||||||
@ -39,12 +39,29 @@ class DocType:
|
|||||||
self.validate_leave_overlap()
|
self.validate_leave_overlap()
|
||||||
self.validate_max_days()
|
self.validate_max_days()
|
||||||
self.validate_block_days()
|
self.validate_block_days()
|
||||||
|
|
||||||
|
def on_update(self):
|
||||||
|
if (not self.previous_doc and self.doc.leave_approver) or (self.doc.status == "Open" \
|
||||||
|
and self.previous_doc.leave_approver != self.doc.leave_approver):
|
||||||
|
# notify leave approver about creation
|
||||||
|
self.notify_leave_approver()
|
||||||
|
elif self.previous_doc and \
|
||||||
|
self.previous_doc.status == "Open" and self.doc.status == "Rejected":
|
||||||
|
# notify employee about rejection
|
||||||
|
self.notify_employee(self.doc.status)
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
if self.doc.status != "Approved":
|
if self.doc.status != "Approved":
|
||||||
webnotes.msgprint("""Only Leave Applications with status 'Approved' can be Submitted.""",
|
webnotes.msgprint("""Only Leave Applications with status 'Approved' can be Submitted.""",
|
||||||
raise_exception=True)
|
raise_exception=True)
|
||||||
|
|
||||||
|
# notify leave applier about approval
|
||||||
|
self.notify_employee(self.doc.status)
|
||||||
|
|
||||||
|
def on_cancel(self):
|
||||||
|
# notify leave applier about cancellation
|
||||||
|
self.notify_employee("cancelled")
|
||||||
|
|
||||||
def validate_block_days(self):
|
def validate_block_days(self):
|
||||||
for block_list in self.get_applicable_block_lists():
|
for block_list in self.get_applicable_block_lists():
|
||||||
self.check_block_dates(block_list)
|
self.check_block_dates(block_list)
|
||||||
@ -148,7 +165,54 @@ class DocType:
|
|||||||
if max_days and self.doc.total_leave_days > max_days:
|
if max_days and self.doc.total_leave_days > max_days:
|
||||||
msgprint("Sorry ! You cannot apply for %s for more than %s days" % (self.doc.leave_type, max_days))
|
msgprint("Sorry ! You cannot apply for %s for more than %s days" % (self.doc.leave_type, max_days))
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
|
def notify_employee(self, status):
|
||||||
|
employee = webnotes.doc("Employee", self.doc.employee)
|
||||||
|
if not employee.user_id:
|
||||||
|
return
|
||||||
|
|
||||||
|
def _get_message(url=False):
|
||||||
|
if url:
|
||||||
|
name = get_url_to_form(self.doc.doctype, self.doc.name)
|
||||||
|
else:
|
||||||
|
name = self.doc.name
|
||||||
|
|
||||||
|
return (_("Leave Application") + ": %s - %s") % (name, _(status))
|
||||||
|
|
||||||
|
self.notify({
|
||||||
|
# for post in messages
|
||||||
|
"message": _get_message(url=True),
|
||||||
|
"message_to": employee.user_id,
|
||||||
|
|
||||||
|
"subject": _get_message(),
|
||||||
|
})
|
||||||
|
|
||||||
|
def notify_leave_approver(self):
|
||||||
|
employee = webnotes.doc("Employee", self.doc.employee)
|
||||||
|
|
||||||
|
def _get_message(url=False):
|
||||||
|
name = self.doc.name
|
||||||
|
employee_name = get_fullname(employee.user_id)
|
||||||
|
if url:
|
||||||
|
name = get_url_to_form(self.doc.doctype, self.doc.name)
|
||||||
|
employee_name = get_url_to_form("Employee", self.doc.employee, label=employee_name)
|
||||||
|
|
||||||
|
return (_("New Leave Application") + ": %s - " + _("Employee") + ": %s") % (name, employee_name)
|
||||||
|
|
||||||
|
self.notify({
|
||||||
|
# for post in messages
|
||||||
|
"message": _get_message(url=True),
|
||||||
|
"message_to": self.doc.leave_approver,
|
||||||
|
|
||||||
|
# for email
|
||||||
|
"subject": _get_message()
|
||||||
|
})
|
||||||
|
|
||||||
|
def notify(self, args):
|
||||||
|
args = webnotes._dict(args)
|
||||||
|
from utilities.page.messages.messages import post
|
||||||
|
post({"txt": args.message, "contact": args.message_to, "subject": args.subject,
|
||||||
|
"notify": True})
|
||||||
|
|
||||||
@webnotes.whitelist()
|
@webnotes.whitelist()
|
||||||
def get_leave_balance(employee, leave_type, fiscal_year):
|
def get_leave_balance(employee, leave_type, fiscal_year):
|
||||||
|
@ -66,12 +66,14 @@ def get_active_users(arg=None):
|
|||||||
def post(arg=None):
|
def post(arg=None):
|
||||||
import webnotes
|
import webnotes
|
||||||
"""post message"""
|
"""post message"""
|
||||||
if arg:
|
if not arg:
|
||||||
import json
|
|
||||||
arg = json.loads(arg)
|
|
||||||
else:
|
|
||||||
arg = {}
|
arg = {}
|
||||||
arg.update(webnotes.form_dict)
|
arg.update(webnotes.form_dict)
|
||||||
|
|
||||||
|
if isinstance(arg, basestring):
|
||||||
|
import json
|
||||||
|
arg = json.loads(arg)
|
||||||
|
|
||||||
from webnotes.model.doc import Document
|
from webnotes.model.doc import Document
|
||||||
d = Document('Comment')
|
d = Document('Comment')
|
||||||
d.parenttype = arg.get("parenttype")
|
d.parenttype = arg.get("parenttype")
|
||||||
@ -90,16 +92,13 @@ def delete(arg=None):
|
|||||||
webnotes.form_dict['name']);
|
webnotes.form_dict['name']);
|
||||||
|
|
||||||
def notify(arg=None):
|
def notify(arg=None):
|
||||||
from webnotes.utils import cstr
|
from webnotes.utils import cstr, get_fullname
|
||||||
from startup import get_url
|
from startup import get_url
|
||||||
|
|
||||||
fn = webnotes.conn.sql('select first_name, last_name from tabProfile where name=%s', webnotes.user.name)[0]
|
fn = get_fullname(webnotes.user.name) or webnotes.user.name
|
||||||
if fn[0] or f[1]:
|
|
||||||
fn = cstr(fn[0]) + (fn[0] and ' ' or '') + cstr(fn[1])
|
|
||||||
else:
|
|
||||||
fn = webnotes.user.name
|
|
||||||
|
|
||||||
url = get_url()
|
url = get_url()
|
||||||
|
|
||||||
message = '''You have a message from <b>%s</b>:
|
message = '''You have a message from <b>%s</b>:
|
||||||
|
|
||||||
%s
|
%s
|
||||||
@ -108,8 +107,11 @@ def notify(arg=None):
|
|||||||
<a href=\"%s\" target='_blank'>%s</a>
|
<a href=\"%s\" target='_blank'>%s</a>
|
||||||
''' % (fn, arg['txt'], url, url)
|
''' % (fn, arg['txt'], url, url)
|
||||||
|
|
||||||
sender = webnotes.user.name!='Administrator' and webnotes.user.name or 'support+admin_post@erpnext.com'
|
sender = webnotes.conn.get_value("Profile", webnotes.user.name, "email") \
|
||||||
|
or webnotes.user.name
|
||||||
|
recipient = [webnotes.conn.get_value("Profile", arg["contact"], "email") \
|
||||||
|
or arg["contact"]]
|
||||||
|
|
||||||
from webnotes.utils.email_lib import sendmail
|
from webnotes.utils.email_lib import sendmail
|
||||||
sendmail([arg['contact']], sender, message, "You have a message from %s" % (fn,))
|
sendmail(recipient, sender, message, arg.get("subject") or "You have a message from %s" % (fn,))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user