Merge pull request #7162 from nabinhait/manqala-exchange_rate_modifications1
Exchange rate base on date
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py
index f0733b7..95bea7a 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.py
@@ -243,16 +243,15 @@
def get_payment_days(self, joining_date, relieving_date):
start_date = getdate(self.start_date)
-
if joining_date:
- if joining_date > getdate(self.start_date):
+ if getdate(self.start_date) <= joining_date <= getdate(self.end_date):
start_date = joining_date
elif joining_date > getdate(self.end_date):
return
end_date = getdate(self.end_date)
if relieving_date:
- if relieving_date > start_date and relieving_date < getdate(self.end_date):
+ if getdate(self.start_date) <= relieving_date <= getdate(self.end_date):
end_date = relieving_date
elif relieving_date < getdate(self.start_date):
frappe.throw(_("Employee relieved on {0} must be set as 'Left'")
@@ -263,7 +262,6 @@
if not cint(frappe.db.get_value("HR Settings", None, "include_holidays_in_total_working_days")):
holidays = self.get_holidays_for_employee(start_date, end_date)
payment_days -= len(holidays)
-
return payment_days
def get_holidays_for_employee(self, start_date, end_date):
diff --git a/erpnext/hr/doctype/salary_slip/test_records.json b/erpnext/hr/doctype/salary_slip/test_records.json
deleted file mode 100644
index da6365f..0000000
--- a/erpnext/hr/doctype/salary_slip/test_records.json
+++ /dev/null
@@ -1,45 +0,0 @@
-[
- {
- "company": "_Test Company",
- "doctype": "Salary Slip",
- "deductions": [
- {
- "doctype": "Salary Detail",
- "amount": 100,
- "depends_on_lwp": 0,
- "salary_component": "_Test Professional Tax",
- "parentfield": "deductions"
- },
- {
- "doctype": "Salary Detail",
- "amount": 48.39,
- "depends_on_lwp": 0,
- "salary_component": "_Test TDS",
- "parentfield": "deductions"
- }
- ],
- "earnings": [
- {
- "doctype": "Salary Detail",
- "amount": 14516.13,
- "depends_on_lwp": 0,
- "salary_component": "_Test Basic Salary",
- "parentfield": "earnings"
- },
- {
- "doctype": "Salary Detail",
- "amount": 500,
- "depends_on_lwp": 0,
- "salary_component": "_Test Allowance",
- "parentfield": "earnings"
- }
- ],
- "employee": "_T-Employee-0001",
- "employee_name": "_Test Employee",
- "posting_date": "2013-02-01",
- "fiscal_year": "_Test Fiscal Year 2013",
- "month": "01",
- "payment_days": 31,
- "total_working_days": 31
- }
-]
\ No newline at end of file
diff --git a/erpnext/hr/doctype/salary_slip/test_salary_slip.py b/erpnext/hr/doctype/salary_slip/test_salary_slip.py
index 89dced4..4025db7 100644
--- a/erpnext/hr/doctype/salary_slip/test_salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/test_salary_slip.py
@@ -5,9 +5,9 @@
import unittest
import frappe
import erpnext
-from frappe.utils.make_random import get_random
+import calendar
from erpnext.accounts.utils import get_fiscal_year
-from frappe.utils import today, now_datetime, getdate, cstr, add_years, nowdate, add_days
+from frappe.utils import getdate, nowdate, add_days
from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip
from erpnext.hr.doctype.process_payroll.test_process_payroll import get_salary_component_account
from erpnext.hr.doctype.process_payroll.process_payroll import get_month_details
@@ -24,17 +24,13 @@
frappe.db.set_value("Company", erpnext.get_default_company(), "default_holiday_list", "Salary Slip Test Holiday List")
- from erpnext.hr.doctype.leave_application.test_leave_application import _test_records as leave_applications
- la = frappe.copy_doc(leave_applications[2])
- la.insert()
- la.status = "Approved"
- la.submit()
def tearDown(self):
frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 0)
frappe.set_user("Administrator")
def test_salary_slip_with_holidays_included(self):
+ no_of_days = self.get_no_of_days()
frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 1)
self.make_employee("test_employee@salary.com")
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "relieving_date", None)
@@ -42,8 +38,8 @@
ss = frappe.get_doc("Salary Slip",
self.make_employee_salary_slip("test_employee@salary.com", "Monthly"))
- self.assertEquals(ss.total_working_days, 31)
- self.assertEquals(ss.payment_days, 31)
+ self.assertEquals(ss.total_working_days, no_of_days[0])
+ self.assertEquals(ss.payment_days, no_of_days[0])
self.assertEquals(ss.earnings[0].amount, 5000)
self.assertEquals(ss.earnings[1].amount, 3000)
self.assertEquals(ss.deductions[0].amount, 5000)
@@ -52,6 +48,7 @@
self.assertEquals(ss.net_pay, 3000)
def test_salary_slip_with_holidays_excluded(self):
+ no_of_days = self.get_no_of_days()
frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 0)
self.make_employee("test_employee@salary.com")
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "relieving_date", None)
@@ -59,8 +56,8 @@
ss = frappe.get_doc("Salary Slip",
self.make_employee_salary_slip("test_employee@salary.com", "Monthly"))
- self.assertEquals(ss.total_working_days, 28)
- self.assertEquals(ss.payment_days, 28)
+ self.assertEquals(ss.total_working_days, no_of_days[0] - no_of_days[1])
+ self.assertEquals(ss.payment_days, no_of_days[0] - no_of_days[1])
self.assertEquals(ss.earnings[0].amount, 5000)
self.assertEquals(ss.earnings[0].default_amount, 5000)
self.assertEquals(ss.earnings[1].amount, 3000)
@@ -70,37 +67,46 @@
self.assertEquals(ss.net_pay, 3000)
def test_payment_days(self):
+ no_of_days = self.get_no_of_days()
# Holidays not included in working days
- frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 0)
+ frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 1)
# set joinng date in the same month
self.make_employee("test_employee@salary.com")
- frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "date_of_joining", "2013-01-11")
+ if getdate(nowdate()).day > 15:
+ date_of_joining = getdate(add_days(nowdate(),-10))
+ relieving_date = getdate(add_days(nowdate(),-10))
+ elif getdate(nowdate()).day < 15 and getdate(nowdate()).day > 5:
+ date_of_joining = getdate(add_days(nowdate(),-3))
+ relieving_date = getdate(add_days(nowdate(),-3))
+ elif getdate(nowdate()).day < 5 and not getdate(nowdate()).day == 1:
+ date_of_joining = getdate(add_days(nowdate(),-1))
+ relieving_date = getdate(add_days(nowdate(),-1))
+ elif getdate(nowdate()).day == 1:
+ date_of_joining = getdate(nowdate())
+ relieving_date = getdate(nowdate())
+
+ frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "date_of_joining", date_of_joining)
+ frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "relieving_date", None)
+ frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "status", "Active")
ss = frappe.get_doc("Salary Slip",
self.make_employee_salary_slip("test_employee@salary.com", "Monthly"))
- self.assertEquals(ss.total_working_days, 28)
- self.assertEquals(ss.payment_days, 28)
+ self.assertEquals(ss.total_working_days, no_of_days[0])
+ self.assertEquals(ss.payment_days, (no_of_days[0] - getdate(date_of_joining).day + 1))
# set relieving date in the same month
- frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "relieving_date", "12-12-2016")
+ frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "date_of_joining", (add_days(nowdate(),-60)))
+ frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "relieving_date", relieving_date)
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "status", "Left")
-
- self.assertEquals(ss.total_working_days, 28)
- self.assertEquals(ss.payment_days, 28)
ss.save()
+ self.assertEquals(ss.total_working_days, no_of_days[0])
+ self.assertEquals(ss.payment_days, getdate(relieving_date).day)
+
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "relieving_date", None)
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "status", "Active")
- # Holidays included in working days
- frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 1)
- self.assertEquals(ss.total_working_days, 28)
- self.assertEquals(ss.payment_days, 28)
- ss.save()
- #
- # frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "date_of_joining", "2001-01-11")
- # frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "relieving_date", None)
def test_employee_salary_slip_read_permission(self):
self.make_employee("test_employee@salary.com")
@@ -126,7 +132,7 @@
def test_payroll_frequency(self):
fiscal_year = get_fiscal_year(nowdate())[0]
- month = "%02d" % getdate(nowdate()).month or "%02d" % getdate(nowdate()).month
+ month = "%02d" % getdate(nowdate()).month
m = get_month_details(fiscal_year, month)
for payroll_frequncy in ["Monthly", "Bimonthly", "Fortnightly", "Weekly", "Daily"]:
@@ -176,12 +182,13 @@
}).insert()
def make_holiday_list(self):
+ fiscal_year = get_fiscal_year(nowdate())
if not frappe.db.get_value("Holiday List", "Salary Slip Test Holiday List"):
holiday_list = frappe.get_doc({
"doctype": "Holiday List",
"holiday_list_name": "Salary Slip Test Holiday List",
- "from_date": nowdate(),
- "to_date": add_years(nowdate(), 1),
+ "from_date": fiscal_year[1],
+ "to_date": fiscal_year[2],
"weekly_off": "Sunday"
}).insert()
holiday_list.get_weekly_off_dates()
@@ -211,6 +218,14 @@
activity_type.wage_rate = 25
activity_type.save()
+ def get_no_of_days(self):
+ no_of_days_in_month = calendar.monthrange(getdate(nowdate()).year,
+ getdate(nowdate()).month)
+ no_of_holidays_in_month = len([1 for i in calendar.monthcalendar(getdate(nowdate()).year,
+ getdate(nowdate()).month) if i[6] != 0])
+ return [no_of_days_in_month[1], no_of_holidays_in_month]
+
+
def make_earning_salary_component(salary_components):
for salary_component in salary_components:
if not frappe.db.exists('Salary Component', salary_component):
@@ -318,7 +333,4 @@
"formula": 'base*.1',
"idx": 3
}
- ]
-
-test_dependencies = ["Leave Application", "Holiday List"]
-
\ No newline at end of file
+ ]
\ No newline at end of file
diff --git a/erpnext/hr/doctype/salary_structure/test_salary_structure.py b/erpnext/hr/doctype/salary_structure/test_salary_structure.py
index 83ea12e..9217c64 100644
--- a/erpnext/hr/doctype/salary_structure/test_salary_structure.py
+++ b/erpnext/hr/doctype/salary_structure/test_salary_structure.py
@@ -9,25 +9,15 @@
from frappe.utils import nowdate, add_days, add_years
from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip
from erpnext.hr.doctype.salary_slip.test_salary_slip import make_earning_salary_component, make_deduction_salary_component
-# test_records = frappe.get_test_records('Salary Structure')
class TestSalaryStructure(unittest.TestCase):
def test_setup(self):
- if not frappe.db.exists("Fiscal Year", "_Test Fiscal Year 2016"):
- fy = frappe.get_doc({
- "doctype": "Fiscal Year",
- "year": "_Test Fiscal Year 2016",
- "year_end_date": "2016-12-31",
- "year_start_date": "2016-01-01"
- })
- fy.insert()
-
self.make_holiday_list()
frappe.db.set_value("Company", erpnext.get_default_company(), "default_holiday_list", "Salary Structure Test Holiday List")
make_earning_salary_component(["Basic Salary", "Allowance", "HRA"])
make_deduction_salary_component(["Professional Tax", "TDS"])
- employee1 = self.make_employee("test_employee@salary.com")
- employee2 = self.make_employee("test_employee_2@salary.com")
+ self.make_employee("test_employee@salary.com")
+ self.make_employee("test_employee_2@salary.com")
def make_holiday_list(self):
if not frappe.db.get_value("Holiday List", "Salary Structure Test Holiday List"):
@@ -88,8 +78,7 @@
sal_struct = make_salary_structure('Salary Structure Sample')
sal_slip = make_salary_slip(sal_struct, employee = employee)
sal_slip.employee_name = frappe.get_value("Employee", {"name":employee}, "employee_name")
- sal_slip.month = "11"
- sal_slip.fiscal_year = "_Test Fiscal Year 2016"
+ sal_slip.start_date = nowdate()
sal_slip.posting_date = nowdate()
sal_slip.payroll_frequency = "Monthly"
sal_slip.insert()
diff --git a/erpnext/setup/doctype/company/fixtures/india/__init__.py b/erpnext/setup/doctype/company/fixtures/india/__init__.py
index 2aeec99..0f4bd4f 100644
--- a/erpnext/setup/doctype/company/fixtures/india/__init__.py
+++ b/erpnext/setup/doctype/company/fixtures/india/__init__.py
@@ -7,9 +7,10 @@
def install(company):
docs = [
- {'doctype': 'Salary Component', 'salary_component': 'Professional Tax', 'description': 'Professional Tax'},
- {'doctype': 'Salary Component', 'salary_component': 'Provident Fund', 'description': 'Provident fund'},
- {'doctype': 'Salary Component', 'salary_component': 'House Rent Allowance', 'description': 'House Rent Allowance'}
+ {'doctype': 'Salary Component', 'salary_component': 'Professional Tax', 'description': 'Professional Tax', 'type': 'Deduction'},
+ {'doctype': 'Salary Component', 'salary_component': 'Provident Fund', 'description': 'Provident fund', 'type': 'Deduction'},
+ {'doctype': 'Salary Component', 'salary_component': 'House Rent Allowance', 'description': 'House Rent Allowance', 'type': 'Earning'},
+ {'doctype': 'Salary Component', 'salary_component': 'Basic', 'description': 'Basic', 'type': 'Earning'}
]
for d in docs: