Merge branch 'develop' of github.com:frappe/erpnext into develop

This commit is contained in:
Nabin Hait 2014-05-02 10:27:17 +05:30
commit 92c4fc4e19
3 changed files with 70 additions and 10 deletions

View File

@ -1,5 +1,5 @@
{ {
"creation": "2013-01-10 16:34:15.000000", "creation": "2013-01-10 16:34:15",
"docstatus": 0, "docstatus": 0,
"doctype": "DocType", "doctype": "DocType",
"fields": [ "fields": [
@ -355,7 +355,7 @@
"icon": "icon-file-text", "icon": "icon-file-text",
"idx": 1, "idx": 1,
"is_submittable": 1, "is_submittable": 1,
"modified": "2014-01-20 17:49:18.000000", "modified": "2014-05-01 04:31:14.543092",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Salary Slip", "name": "Salary Slip",
@ -387,6 +387,12 @@
"role": "HR Manager", "role": "HR Manager",
"submit": 1, "submit": 1,
"write": 1 "write": 1
},
{
"permlevel": 0,
"read": 1,
"restricted": 0,
"role": "Employee"
} }
] ]
} }

View File

@ -1,8 +1,11 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt # License: GNU General Public License v3. See license.txt
import frappe
import unittest import unittest
import frappe
from frappe.utils import today
from erpnext.hr.doctype.employee.employee import make_salary_structure
from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip
class TestSalarySlip(unittest.TestCase): class TestSalarySlip(unittest.TestCase):
def setUp(self): def setUp(self):
@ -16,6 +19,7 @@ class TestSalarySlip(unittest.TestCase):
def tearDown(self): def tearDown(self):
frappe.db.set_value("HR Settings", "HR Settings", "include_holidays_in_total_working_days", 0) frappe.db.set_value("HR Settings", "HR Settings", "include_holidays_in_total_working_days", 0)
frappe.set_user("Administrator")
def test_salary_slip_with_holidays_included(self): def test_salary_slip_with_holidays_included(self):
frappe.db.set_value("HR Settings", "HR Settings", "include_holidays_in_total_working_days", 1) frappe.db.set_value("HR Settings", "HR Settings", "include_holidays_in_total_working_days", 1)
@ -42,6 +46,62 @@ class TestSalarySlip(unittest.TestCase):
self.assertEquals(ss.gross_pay, 15000) self.assertEquals(ss.gross_pay, 15000)
self.assertEquals(ss.net_pay, 14851.67) self.assertEquals(ss.net_pay, 14851.67)
def test_employee_salary_slip_read_permission(self):
self.make_employee("test_employee@example.com")
self.make_employee("test_employee_2@example.com")
salary_slip_test_employee = frappe.get_doc("Salary Slip",
self.make_employee_salary_slip("test_employee@example.com"))
salary_slip_test_employee_2 = frappe.get_doc("Salary Slip",
self.make_employee_salary_slip("test_employee_2@example.com"))
frappe.set_user("test_employee@example.com")
self.assertTrue(salary_slip_test_employee.has_permission("read"))
self.assertFalse(salary_slip_test_employee_2.has_permission("read"))
def make_employee(self, user):
if not frappe.db.get_value("User", user):
frappe.get_doc({
"doctype": "User",
"email": user,
"first_name": user,
"new_password": "password",
"user_roles": [{"doctype": "UserRole", "role": "Employee"}]
}).insert()
if not frappe.db.get_value("Employee", {"user_id": user}):
frappe.get_doc({
"doctype": "Employee",
"naming_series": "_T-Employee-",
"employee_name": user,
"user_id": user,
"company": "_Test Company",
"date_of_birth": "1990-05-08",
"date_of_joining": "2013-01-01",
"department": "_Test Department 1",
"gender": "Female",
"status": "Active"
}).insert()
def make_employee_salary_slip(self, user):
employee = frappe.db.get_value("Employee", {"user_id": user})
salary_structure = frappe.db.get_value("Salary Structure", {"employee": employee})
if not salary_structure:
salary_structure = make_salary_structure(employee)
salary_structure.from_date = today()
salary_structure.insert()
salary_structure = salary_structure.name
salary_slip = frappe.db.get_value("Salary Slip", {"employee": employee})
if not salary_slip:
salary_slip = make_salary_slip(salary_structure)
salary_slip.insert()
salary_slip.submit()
salary_slip = salary_slip.name
return salary_slip
test_dependencies = ["Leave Application"] test_dependencies = ["Leave Application"]
test_records = frappe.get_test_records('Salary Slip') test_records = frappe.get_test_records('Salary Slip')

View File

@ -7,8 +7,7 @@ import frappe
from frappe.utils import cstr, flt from frappe.utils import cstr, flt
from frappe.model.naming import make_autoname from frappe.model.naming import make_autoname
from frappe import _ from frappe import _
from frappe.model.mapper import get_mapped_doc
from frappe.model.document import Document from frappe.model.document import Document
class SalaryStructure(Document): class SalaryStructure(Document):
@ -70,11 +69,6 @@ class SalaryStructure(Document):
@frappe.whitelist() @frappe.whitelist()
def make_salary_slip(source_name, target_doc=None): def make_salary_slip(source_name, target_doc=None):
return get_mapped_doc(source_name, target_doc).as_dict()
def get_mapped_doc(source_name, target_doc=None):
from frappe.model.mapper import get_mapped_doc
def postprocess(source, target): def postprocess(source, target):
target.run_method("pull_emp_details") target.run_method("pull_emp_details")
target.run_method("get_leave_details") target.run_method("get_leave_details")