refactor: convert raw sql to orm

This commit is contained in:
Mangesh-Khairnar 2019-08-08 17:43:23 +05:30
parent 9bc4232af6
commit bafc89f439
9 changed files with 23 additions and 50 deletions

View File

@ -126,7 +126,7 @@ class LeaveAllocation(Document):
def create_leave_ledger_entry(self, submit=True):
if self.unused_leaves:
expiry_days = frappe.db.get_value("Leave Type", self.leave_type, "expire_carried_forward_leaves")
expiry_days = frappe.db.get_value("Leave Type", self.leave_type, "expire_carry_forwarded_leaves_after_days")
args = dict(
leaves=self.unused_leaves,
from_date=self.from_date,

View File

@ -97,7 +97,7 @@ class TestLeaveAllocation(unittest.TestCase):
leave_type = create_leave_type(
leave_type_name="_Test_CF_leave_expiry",
is_carry_forward=1,
expire_carried_forward_leaves=90)
expire_carry_forwarded_leaves_after_days=90)
leave_type.submit()
# initial leave allocation

View File

@ -49,7 +49,7 @@ frappe.ui.form.on("Leave Application", {
async: false,
args: {
employee: frm.doc.employee,
date: frm.doc.from_date? frm.doc.from_date:frm.doc.posting_date
date: frm.doc.from_date || frm.doc.posting_date
},
callback: function(r) {
if (!r.exc && r.message['leave_allocation']) {

View File

@ -415,7 +415,7 @@ class TestLeaveApplication(unittest.TestCase):
leave_type = create_leave_type(
leave_type_name="_Test_CF_leave_expiry",
is_carry_forward=1,
expire_carried_forward_leaves=90)
expire_carry_forwarded_leaves_after_days=90)
leave_type.submit()
create_carry_forwarded_allocation(employee, leave_type)
@ -516,7 +516,7 @@ class TestLeaveApplication(unittest.TestCase):
leave_type = create_leave_type(
leave_type_name="_Test_CF_leave_expiry",
is_carry_forward=1,
expire_carried_forward_leaves=90)
expire_carry_forwarded_leaves_after_days=90)
leave_type.submit()
create_carry_forwarded_allocation(employee, leave_type)
@ -548,7 +548,7 @@ class TestLeaveApplication(unittest.TestCase):
leave_type = create_leave_type(
leave_type_name="_Test_CF_leave_expiry",
is_carry_forward=1,
expire_carried_forward_leaves=90)
expire_carry_forwarded_leaves_after_days=90)
leave_type.submit()
create_carry_forwarded_allocation(employee, leave_type)

View File

@ -92,7 +92,7 @@ def process_expired_allocation():
# fetch leave type records that has carry forwarded leaves expiry
leave_type_records = frappe.db.get_values("Leave Type", filters={
'expire_carried_forward_leaves': (">", 0)
'expire_carry_forwarded_leaves_after_days': (">", 0)
}, fieldname=['name'])
if leave_type_records:

View File

@ -95,7 +95,7 @@ def get_existing_allocations(employees, leave_period):
def get_leave_type_details():
leave_type_details = frappe._dict()
leave_types = frappe.get_all("Leave Type",
fields=["name", "is_lwp", "is_earned_leave", "is_compensatory", "is_carry_forward", "expire_carried_forward_leaves"])
fields=["name", "is_lwp", "is_earned_leave", "is_compensatory", "is_carry_forward", "expire_carry_forwarded_leaves_after_days"])
for d in leave_types:
leave_type_details.setdefault(d.name, d)
return leave_type_details

View File

@ -421,7 +421,7 @@
"depends_on": "",
"description": "Calculated in days",
"fetch_if_empty": 0,
"fieldname": "expire_carried_forward_leaves",
"fieldname": "expire_carry_forwarded_leaves_after_days",
"fieldtype": "Int",
"hidden": 0,
"ignore_user_permissions": 0,
@ -430,7 +430,7 @@
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Expire Carried Forward Leaves",
"label": "Expire Carry Forwarded Leaves After Days",
"length": 0,
"no_copy": 0,
"permlevel": 0,
@ -728,7 +728,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2019-07-22 15:38:39.334283",
"modified": "2019-08-01 15:38:39.334283",
"modified_by": "Administrator",
"module": "HR",
"name": "Leave Type",

View File

@ -19,7 +19,7 @@ def create_leave_type(**args):
"is_earned_leave": args.is_earned_leave or 0,
"is_lwp": args.is_lwp or 0,
"is_carry_forward": args.is_carry_forward or 0,
"expire_carried_forward_leaves": args.expire_carried_forward_leaves or 0,
"expire_carry_forwarded_leaves_after_days": args.expire_carry_forwarded_leaves_after_days or 0,
"encashment_threshold_days": args.encashment_threshold_days or 5,
"earning_component": "Leave Encashment"
})

View File

@ -69,45 +69,18 @@ def generate_expiry_allocation_ledger_entries():
expire_allocation(allocation_obj)
def get_allocation_records():
return frappe.db.sql("""
SELECT
name,
employee,
leave_type,
new_leaves_allocated,
unused_leaves,
from_date,
to_date,
carry_forward
FROM `tabLeave Allocation`
WHERE
docstatus=1
ORDER BY to_date ASC
""", as_dict=1)
return frappe.get_all("Leave Allocation", filters={
"docstatus": 1
}, fields=['name', 'employee', 'leave_type', 'new_leaves_allocated',
'unused_leaves', 'from_date', 'to_date', 'carry_forward'
], order_by='to_date ASC')
def get_leaves_application_records():
return frappe.db.sql("""
SELECT
name,
employee,
leave_type,
total_leave_days,
from_date,
to_date
FROM `tabLeave Application`
WHERE
docstatus=1
""", as_dict=1)
return frappe.get_all("Leave Application", filters={
"docstatus": 1
}, fields=['name', 'employee', 'leave_type', 'total_leave_days', 'from_date', 'to_date'])
def get_leave_encashment_records():
return frappe.db.sql("""
SELECT
name,
employee,
leave_type,
encashable_days,
encashment_date
FROM `tabLeave Encashment`
WHERE
docstatus=1
""", as_dict=1)
return frappe.get_all("Leave Encashment", filters={
"docstatus": 1
}, fields=['name', 'employee', 'leave_type', 'encashable_days', 'encashment_date'])