def validate_existing_appraisal(self):
chk = frappe.db.sql(“”“select name from tabAppraisal where employee=%s
and (status=‘Submitted’ or status=‘Draft’)
and ((start_date>=%s and start_date<=%s)
or (end_date>=%s and end_date<=%s))”“”,
(self.employee,self.start_date,self.end_date,self.start_date,self.end_date))
if chk:
frappe.throw(_(“Appraisal {0} created for Employee {1} in the given date range”).format(chk[0][0], self.employee_name))
so, when i save same document more than one, its giving date validation SMS and can’t go next step. if i don’t use work flow, it work, but i need work flow.
in work flow, Employee save and apply(save). and supervisor verify(save) and approver Approve(submitted).
so in this case employee have to save 2 time, (save and apply)
One more thing this query string needs a small correction
You’ll face issues.
"""
select name from `tabAppraisal`
where employee=%s
and (status=‘Submitted’ or status=‘Draft’)
and ((start_date>=%s and start_date<=%s)
or (end_date>=%s and end_date<=%s))"""%(self.employee,self.start_date,self.end_date,self.start_date,self.end_date)
``
Do one thing. replace your code by this one and check if you are able to save or not
def validate_existing_appraisal(self):
cond_exp = "and name <> '%s'"%(self.name) if self.get('__islocal') else '1=1'
chk = frappe.db.sql("""
select
name from tabAppraisal
where employee=%s
and %s
and (status=‘Submitted’ or status=‘Draft’)
and ((start_date>=%s and start_date<=%s)
or (end_date>=%s and end_date<=%s))"""%(self.employee, cond_exp, self.start_date,self.end_date,self.start_date,self.end_date))
if chk:
frappe.throw(_(“Appraisal {0} created for Employee {1} in the given date range”).format(chk[0][0], self.employee_name))
ProgrammingError: (1064, “You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘CDCL1803006’’ \n\t\t\t\tand ‘‘1=1’’ \n\t\t\t\tand (status=‘Submitted’ or ‘status=‘Draft’)\n’ at line 1”)
code:
def validate_existing_appraisal(self):
cond_exp = “and name <> ‘%s’”%(self.name) if self.get(‘__islocal’) else ‘1=1’
chk = frappe.db.sql(“”“select name from tabAppraisal where employee=‘%s’
and ‘%s’
and (status=‘Submitted’ or ‘status=‘Draft’)
and ((start_date>=’%s’ and start_date<=‘%s’)
or (end_date>=‘%s’ and end_date<=‘%s’))”“”, (self.employee, cond_exp, self.start_date, self.end_date,self.start_date, self.end_date))
if chk:
frappe.throw(_(“Appraisal {0} created for Employee {1} in the given date range”).format(chk[0][0], self.employee_name))
def validate_existing_appraisal(self):
chk = frappe.db.sql("""select name, start_date, end_date
from `tabAppraisal`
where employee = %(employee)s and docstatus < 2 and status in ("Draft", "Approved")
and end_date >= %(start_date)s and start_date <= %(end_date)s
and name != %(name)s""", {
"employee": self.employee,
"start_date":self.start_date,
"end_date":self.end_date,
"name":self.name
})