mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-15 19:19:17 +00:00
mass replace sql with webnotes.conn.sql
This commit is contained in:
@@ -14,7 +14,7 @@ class DocType:
|
||||
self.doclist = doclist
|
||||
|
||||
def validate_duplicate_record(self):
|
||||
res = sql("""select name from `tabAttendance` where employee = %s and att_date = %s
|
||||
res = webnotes.conn.sql("""select name from `tabAttendance` where employee = %s and att_date = %s
|
||||
and name != %s and docstatus = 1""",
|
||||
(self.doc.employee, self.doc.att_date, self.doc.name))
|
||||
if res:
|
||||
@@ -23,7 +23,7 @@ class DocType:
|
||||
|
||||
def check_leave_record(self):
|
||||
if self.doc.status == 'Present':
|
||||
leave = sql("""select name from `tabLeave Application`
|
||||
leave = webnotes.conn.sql("""select name from `tabLeave Application`
|
||||
where employee = %s and %s between from_date and to_date and status = 'Approved'
|
||||
and docstatus = 1""", (self.doc.employee, self.doc.att_date))
|
||||
|
||||
@@ -41,7 +41,7 @@ class DocType:
|
||||
msgprint(_("Attendance can not be marked for future dates"), raise_exception=1)
|
||||
|
||||
def validate_employee(self):
|
||||
emp = sql("select name from `tabEmployee` where name = %s and status = 'Active'",
|
||||
emp = webnotes.conn.sql("select name from `tabEmployee` where name = %s and status = 'Active'",
|
||||
self.doc.employee)
|
||||
if not emp:
|
||||
msgprint(_("Employee: ") + self.doc.employee +
|
||||
|
||||
@@ -36,7 +36,7 @@ class DocType:
|
||||
|
||||
def check_existing_leave_allocation(self):
|
||||
"""check whether leave for same type is already allocated or not"""
|
||||
leave_allocation = sql("""select name from `tabLeave Allocation`
|
||||
leave_allocation = webnotes.conn.sql("""select name from `tabLeave Allocation`
|
||||
where employee=%s and leave_type=%s and fiscal_year=%s and docstatus=1""",
|
||||
(self.doc.employee, self.doc.leave_type, self.doc.fiscal_year))
|
||||
if leave_allocation:
|
||||
@@ -63,14 +63,14 @@ class DocType:
|
||||
return self.get_leaves_allocated(prev_fyear) - self.get_leaves_applied(prev_fyear)
|
||||
|
||||
def get_leaves_applied(self, fiscal_year):
|
||||
leaves_applied = sql("""select SUM(ifnull(total_leave_days, 0))
|
||||
leaves_applied = webnotes.conn.sql("""select SUM(ifnull(total_leave_days, 0))
|
||||
from `tabLeave Application` where employee=%s and leave_type=%s
|
||||
and fiscal_year=%s and docstatus=1""",
|
||||
(self.doc.employee, self.doc.leave_type, fiscal_year))
|
||||
return leaves_applied and flt(leaves_applied[0][0]) or 0
|
||||
|
||||
def get_leaves_allocated(self, fiscal_year):
|
||||
leaves_allocated = sql("""select SUM(ifnull(total_leaves_allocated, 0))
|
||||
leaves_allocated = webnotes.conn.sql("""select SUM(ifnull(total_leaves_allocated, 0))
|
||||
from `tabLeave Allocation` where employee=%s and leave_type=%s
|
||||
and fiscal_year=%s and docstatus=1 and name!=%s""",
|
||||
(self.doc.employee, self.doc.leave_type, fiscal_year, self.doc.name))
|
||||
@@ -78,7 +78,7 @@ class DocType:
|
||||
|
||||
def allow_carry_forward(self):
|
||||
"""check whether carry forward is allowed or not for this leave type"""
|
||||
cf = sql("""select is_carry_forward from `tabLeave Type` where name = %s""",
|
||||
cf = webnotes.conn.sql("""select is_carry_forward from `tabLeave Type` where name = %s""",
|
||||
self.doc.leave_type)
|
||||
cf = cf and cint(cf[0][0]) or 0
|
||||
if not cf:
|
||||
@@ -109,7 +109,7 @@ class DocType:
|
||||
webnotes.conn.set(self.doc,'total_leaves_allocated',flt(leave_det['total_leaves_allocated']))
|
||||
|
||||
def check_for_leave_application(self):
|
||||
exists = sql("""select name from `tabLeave Application`
|
||||
exists = webnotes.conn.sql("""select name from `tabLeave Application`
|
||||
where employee=%s and leave_type=%s and fiscal_year=%s and docstatus=1""",
|
||||
(self.doc.employee, self.doc.leave_type, self.doc.fiscal_year))
|
||||
if exists:
|
||||
|
||||
@@ -33,7 +33,7 @@ class DocType:
|
||||
emp_query = "select name from `tabEmployee` "
|
||||
if flag == 1:
|
||||
emp_query += condition
|
||||
e = sql(emp_query)
|
||||
e = webnotes.conn.sql(emp_query)
|
||||
return e
|
||||
|
||||
# ----------------
|
||||
|
||||
@@ -29,7 +29,7 @@ class DocType:
|
||||
cond = self.get_filter_condition()
|
||||
cond += self.get_joining_releiving_condition()
|
||||
|
||||
emp_list = sql("""
|
||||
emp_list = webnotes.conn.sql("""
|
||||
select t1.name
|
||||
from `tabEmployee` t1, `tabSalary Structure` t2
|
||||
where t1.docstatus!=2 and t2.docstatus != 2
|
||||
@@ -67,7 +67,7 @@ class DocType:
|
||||
|
||||
|
||||
def get_month_details(self, year, month):
|
||||
ysd = sql("select year_start_date from `tabFiscal Year` where name ='%s'"%year)[0][0]
|
||||
ysd = webnotes.conn.sql("select year_start_date from `tabFiscal Year` where name ='%s'"%year)[0][0]
|
||||
if ysd:
|
||||
from dateutil.relativedelta import relativedelta
|
||||
import calendar, datetime
|
||||
@@ -95,7 +95,7 @@ class DocType:
|
||||
emp_list = self.get_emp_list()
|
||||
ss_list = []
|
||||
for emp in emp_list:
|
||||
if not sql("""select name from `tabSalary Slip`
|
||||
if not webnotes.conn.sql("""select name from `tabSalary Slip`
|
||||
where docstatus!= 2 and employee = %s and month = %s and fiscal_year = %s and company = %s
|
||||
""", (emp[0], self.doc.month, self.doc.fiscal_year, self.doc.company)):
|
||||
ss = webnotes.bean({
|
||||
@@ -126,7 +126,7 @@ class DocType:
|
||||
which are not submitted
|
||||
"""
|
||||
cond = self.get_filter_condition()
|
||||
ss_list = sql("""
|
||||
ss_list = webnotes.conn.sql("""
|
||||
select t1.name from `tabSalary Slip` t1
|
||||
where t1.docstatus = 0 and month = '%s' and fiscal_year = '%s' %s
|
||||
""" % (self.doc.month, self.doc.fiscal_year, cond))
|
||||
@@ -188,7 +188,7 @@ class DocType:
|
||||
Get total salary amount from submitted salary slip based on selected criteria
|
||||
"""
|
||||
cond = self.get_filter_condition()
|
||||
tot = sql("""
|
||||
tot = webnotes.conn.sql("""
|
||||
select sum(rounded_total) from `tabSalary Slip` t1
|
||||
where t1.docstatus = 1 and month = '%s' and fiscal_year = '%s' %s
|
||||
""" % (self.doc.month, self.doc.fiscal_year, cond))
|
||||
@@ -201,7 +201,7 @@ class DocType:
|
||||
get default bank account,default salary acount from company
|
||||
"""
|
||||
amt = self.get_total_salary()
|
||||
com = sql("select default_bank_account from `tabCompany` where name = '%s'" % self.doc.company)
|
||||
com = webnotes.conn.sql("select default_bank_account from `tabCompany` where name = '%s'" % self.doc.company)
|
||||
|
||||
if not com[0][0] or not com[0][1]:
|
||||
msgprint("You can set Default Bank Account in Company master.")
|
||||
|
||||
@@ -9,7 +9,7 @@ test_records = []
|
||||
|
||||
# from webnotes.model.doc import Document
|
||||
# from webnotes.model.code import get_obj
|
||||
# sql = webnotes.conn.sql
|
||||
# webnotes.conn.sql = webnotes.conn.sql
|
||||
#
|
||||
# class TestSalaryManager(unittest.TestCase):
|
||||
# def setUp(self):
|
||||
@@ -20,15 +20,15 @@ test_records = []
|
||||
# ss1[0].employee = emp1.name
|
||||
# for s in ss1: s.save(1)
|
||||
# for s in ss1[1:]:
|
||||
# sql("update `tabSalary Structure Earning` set parent = '%s' where name = '%s'" % (ss1[0].name, s.name))
|
||||
# sql("update `tabSalary Structure Deduction` set parent = '%s' where name = '%s'" % (ss1[0].name, s.name))
|
||||
# webnotes.conn.sql("update `tabSalary Structure Earning` set parent = '%s' where name = '%s'" % (ss1[0].name, s.name))
|
||||
# webnotes.conn.sql("update `tabSalary Structure Deduction` set parent = '%s' where name = '%s'" % (ss1[0].name, s.name))
|
||||
#
|
||||
#
|
||||
# ss2[0].employee = emp2.name
|
||||
# for s in ss2: s.save(1)
|
||||
# for s in ss2[1:]:
|
||||
# sql("update `tabSalary Structure Earning` set parent = '%s' where name = '%s'" % (ss2[0].name, s.name))
|
||||
# sql("update `tabSalary Structure Deduction` set parent = '%s' where name = '%s'" % (ss2[0].name, s.name))
|
||||
# webnotes.conn.sql("update `tabSalary Structure Earning` set parent = '%s' where name = '%s'" % (ss2[0].name, s.name))
|
||||
# webnotes.conn.sql("update `tabSalary Structure Deduction` set parent = '%s' where name = '%s'" % (ss2[0].name, s.name))
|
||||
#
|
||||
# sman.save()
|
||||
# self.sm = get_obj('Salary Manager')
|
||||
@@ -36,7 +36,7 @@ test_records = []
|
||||
# self.sm.create_sal_slip()
|
||||
#
|
||||
# def test_creation(self):
|
||||
# ssid = sql("""
|
||||
# ssid = webnotes.conn.sql("""
|
||||
# select name, department
|
||||
# from `tabSalary Slip`
|
||||
# where month = '08' and fiscal_year='2011-2012'""")
|
||||
@@ -46,7 +46,7 @@ test_records = []
|
||||
#
|
||||
#
|
||||
# def test_lwp_calc(self):
|
||||
# ss = sql("""
|
||||
# ss = webnotes.conn.sql("""
|
||||
# select payment_days
|
||||
# from `tabSalary Slip`
|
||||
# where month = '08' and fiscal_year='2011-2012' and employee = '%s'
|
||||
|
||||
@@ -31,7 +31,7 @@ class DocType(TransactionBase):
|
||||
|
||||
|
||||
def check_sal_struct(self):
|
||||
struct = sql("select name from `tabSalary Structure` where employee ='%s' and is_active = 'Yes' "%self.doc.employee)
|
||||
struct = webnotes.conn.sql("select name from `tabSalary Structure` where employee ='%s' and is_active = 'Yes' "%self.doc.employee)
|
||||
if not struct:
|
||||
msgprint("Please create Salary Structure for employee '%s'"%self.doc.employee)
|
||||
self.doc.employee = ''
|
||||
@@ -99,13 +99,13 @@ class DocType(TransactionBase):
|
||||
return payment_days
|
||||
|
||||
def get_holidays_for_employee(self, m):
|
||||
holidays = sql("""select t1.holiday_date
|
||||
holidays = webnotes.conn.sql("""select t1.holiday_date
|
||||
from `tabHoliday` t1, tabEmployee t2
|
||||
where t1.parent = t2.holiday_list and t2.name = %s
|
||||
and t1.holiday_date between %s and %s""",
|
||||
(self.doc.employee, m['month_start_date'], m['month_end_date']))
|
||||
if not holidays:
|
||||
holidays = sql("""select t1.holiday_date
|
||||
holidays = webnotes.conn.sql("""select t1.holiday_date
|
||||
from `tabHoliday` t1, `tabHoliday List` t2
|
||||
where t1.parent = t2.name and ifnull(t2.is_default, 0) = 1
|
||||
and t2.fiscal_year = %s
|
||||
@@ -119,7 +119,7 @@ class DocType(TransactionBase):
|
||||
for d in range(m['month_days']):
|
||||
dt = add_days(cstr(m['month_start_date']), d)
|
||||
if dt not in holidays:
|
||||
leave = sql("""
|
||||
leave = webnotes.conn.sql("""
|
||||
select t1.name, t1.half_day
|
||||
from `tabLeave Application` t1, `tabLeave Type` t2
|
||||
where t2.name = t1.leave_type
|
||||
@@ -133,7 +133,7 @@ class DocType(TransactionBase):
|
||||
return lwp
|
||||
|
||||
def check_existing(self):
|
||||
ret_exist = sql("""select name from `tabSalary Slip`
|
||||
ret_exist = webnotes.conn.sql("""select name from `tabSalary Slip`
|
||||
where month = %s and fiscal_year = %s and docstatus != 2
|
||||
and employee = %s and name != %s""",
|
||||
(self.doc.month, self.doc.fiscal_year, self.doc.employee, self.doc.name))
|
||||
@@ -200,9 +200,9 @@ class DocType(TransactionBase):
|
||||
receiver = webnotes.conn.get_value("Employee", self.doc.employee, "company_email")
|
||||
if receiver:
|
||||
subj = 'Salary Slip - ' + cstr(self.doc.month) +'/'+cstr(self.doc.fiscal_year)
|
||||
earn_ret=sql("""select e_type, e_modified_amount from `tabSalary Slip Earning`
|
||||
earn_ret=webnotes.conn.sql("""select e_type, e_modified_amount from `tabSalary Slip Earning`
|
||||
where parent = %s""", self.doc.name)
|
||||
ded_ret=sql("""select d_type, d_modified_amount from `tabSalary Slip Deduction`
|
||||
ded_ret=webnotes.conn.sql("""select d_type, d_modified_amount from `tabSalary Slip Deduction`
|
||||
where parent = %s""", self.doc.name)
|
||||
|
||||
earn_table = ''
|
||||
|
||||
@@ -19,7 +19,7 @@ class DocType:
|
||||
|
||||
def get_employee_details(self):
|
||||
ret = {}
|
||||
det = sql("""select employee_name, branch, designation, department, grade
|
||||
det = webnotes.conn.sql("""select employee_name, branch, designation, department, grade
|
||||
from `tabEmployee` where name = %s""", self.doc.employee)
|
||||
if det:
|
||||
ret = {
|
||||
@@ -33,7 +33,7 @@ class DocType:
|
||||
return ret
|
||||
|
||||
def get_ss_values(self,employee):
|
||||
basic_info = sql("""select bank_name, bank_ac_no, esic_card_no, pf_number
|
||||
basic_info = webnotes.conn.sql("""select bank_name, bank_ac_no, esic_card_no, pf_number
|
||||
from `tabEmployee` where name =%s""", employee)
|
||||
ret = {'bank_name': basic_info and basic_info[0][0] or '',
|
||||
'bank_ac_no': basic_info and basic_info[0][1] or '',
|
||||
@@ -42,7 +42,7 @@ class DocType:
|
||||
return ret
|
||||
|
||||
def make_table(self, doct_name, tab_fname, tab_name):
|
||||
list1 = sql("select name from `tab%s` where docstatus != 2" % doct_name)
|
||||
list1 = webnotes.conn.sql("select name from `tab%s` where docstatus != 2" % doct_name)
|
||||
for li in list1:
|
||||
child = addchild(self.doc, tab_fname, tab_name, self.doclist)
|
||||
if(tab_fname == 'earning_details'):
|
||||
@@ -57,7 +57,7 @@ class DocType:
|
||||
self.make_table('Deduction Type','deduction_details', 'Salary Structure Deduction')
|
||||
|
||||
def check_existing(self):
|
||||
ret = sql("""select name from `tabSalary Structure` where is_active = 'Yes'
|
||||
ret = webnotes.conn.sql("""select name from `tabSalary Structure` where is_active = 'Yes'
|
||||
and employee = %s and name!=%s""", (self.doc.employee,self.doc.name))
|
||||
if ret and self.doc.is_active=='Yes':
|
||||
msgprint(_("""Another Salary Structure '%s' is active for employee '%s'.
|
||||
|
||||
Reference in New Issue
Block a user