fix the test case for the payroll (#14480)
* fix the test case for the payroll * fix the shopify and stock entry * more structured test cases for payroll
This commit is contained in:
parent
d1fffb6ba1
commit
176e7c5ce2
@ -0,0 +1,527 @@
|
||||
[
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Print Settings",
|
||||
"fieldname": "compact_item_print",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"insert_after": "with_letterhead",
|
||||
"label": "Compact Item Print",
|
||||
"modified": "2016-06-06 15:18:17.025602",
|
||||
"name": "Print Settings-compact_item_print",
|
||||
"no_copy": 0,
|
||||
"options": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Customer",
|
||||
"fieldname": "shopify_customer_id",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"insert_after": "naming_series",
|
||||
"label": "Shopify Customer Id",
|
||||
"modified": "2016-01-15 17:25:28.991818",
|
||||
"name": "Customer-shopify_customer_id",
|
||||
"no_copy": 1,
|
||||
"options": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Address",
|
||||
"fieldname": "shopify_address_id",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"insert_after": "fax",
|
||||
"label": "Shopify Address Id",
|
||||
"modified": "2016-01-15 17:50:52.213743",
|
||||
"name": "Address-shopify_address_id",
|
||||
"no_copy": 1,
|
||||
"options": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Sales Order",
|
||||
"fieldname": "shopify_order_id",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"insert_after": "title",
|
||||
"label": "Shopify Order Id",
|
||||
"modified": "2016-01-18 09:55:50.764524",
|
||||
"name": "Sales Order-shopify_order_id",
|
||||
"no_copy": 1,
|
||||
"options": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Item",
|
||||
"fieldname": "shopify_product_id",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"insert_after": "item_code",
|
||||
"label": "Shopify Product Id",
|
||||
"modified": "2016-01-19 15:44:16.132952",
|
||||
"name": "Item-shopify_product_id",
|
||||
"no_copy": 1,
|
||||
"options": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Sales Invoice",
|
||||
"fieldname": "shopify_order_id",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"insert_after": "naming_series",
|
||||
"label": "Shopify Order Id",
|
||||
"modified": "2016-01-19 16:30:12.261797",
|
||||
"name": "Sales Invoice-shopify_order_id",
|
||||
"no_copy": 1,
|
||||
"options": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Delivery Note",
|
||||
"fieldname": "shopify_order_id",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"insert_after": "title",
|
||||
"label": "Shopify Order Id",
|
||||
"modified": "2016-01-19 16:30:31.201198",
|
||||
"name": "Delivery Note-shopify_order_id",
|
||||
"no_copy": 1,
|
||||
"options": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Item",
|
||||
"fieldname": "stock_keeping_unit",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"insert_after": "stock_uom",
|
||||
"label": "Stock Keeping Unit",
|
||||
"modified": "2015-11-10 09:29:10.854943",
|
||||
"name": "Item-stock_keeping_unit",
|
||||
"no_copy": 1,
|
||||
"options": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"default": "0",
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Item",
|
||||
"fieldname": "sync_with_shopify",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"insert_after": "is_stock_item",
|
||||
"label": "Sync With Shopify",
|
||||
"modified": "2015-10-12 15:54:31.997714",
|
||||
"name": "Item-sync_with_shopify",
|
||||
"no_copy": 0,
|
||||
"options": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Customer",
|
||||
"fieldname": "sync_with_shopify",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"insert_after": "is_frozen",
|
||||
"label": "Sync With Shopify",
|
||||
"modified": "2015-10-01 17:31:55.758826",
|
||||
"name": "Customer-sync_with_shopify",
|
||||
"no_copy": 0,
|
||||
"options": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Item",
|
||||
"fieldname": "shopify_variant_id",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 1,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"insert_after": "item_code",
|
||||
"label": "Variant Id",
|
||||
"modified": "2015-11-09 18:26:50.825858",
|
||||
"name": "Item-shopify_variant_id",
|
||||
"no_copy": 1,
|
||||
"options": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Item",
|
||||
"fieldname": "sync_qty_with_shopify",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"insert_after": "item_code",
|
||||
"label": "Sync Quantity With Shopify",
|
||||
"modified": "2015-12-29 08:37:46.183295",
|
||||
"name": "Item-sync_qty_with_shopify",
|
||||
"no_copy": 0,
|
||||
"options": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Delivery Note",
|
||||
"fieldname": "shopify_fulfillment_id",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"insert_after": "title",
|
||||
"label": "Shopify Fulfillment Id",
|
||||
"modified": "2016-01-20 23:50:35.609543",
|
||||
"name": "Delivery Note-shopify_fulfillment_id",
|
||||
"no_copy": 1,
|
||||
"options": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Supplier",
|
||||
"fieldname": "shopify_supplier_id",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 1,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"insert_after": "supplier_name",
|
||||
"label": "Shopify Supplier Id",
|
||||
"modified": "2016-02-01 15:41:25.818306",
|
||||
"name": "Supplier-shopify_supplier_id",
|
||||
"no_copy": 1,
|
||||
"options": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Item",
|
||||
"fieldname": "shopify_description",
|
||||
"fieldtype": "Text Editor",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"insert_after": "section_break_11",
|
||||
"label": "shopify_description",
|
||||
"modified": "2016-06-15 12:15:36.325581",
|
||||
"name": "Item-shopify_description",
|
||||
"no_copy": 0,
|
||||
"options": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"report_hide": 1,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
}
|
||||
]
|
@ -6,15 +6,20 @@ import frappe
|
||||
|
||||
import unittest, os, json
|
||||
from frappe.utils import cstr
|
||||
from frappe.utils.fixtures import sync_fixtures
|
||||
from erpnext.erpnext_integrations.connectors.shopify_connection import create_order
|
||||
from erpnext.erpnext_integrations.doctype.shopify_settings.sync_product import make_item
|
||||
from erpnext.erpnext_integrations.doctype.shopify_settings.sync_customer import create_customer
|
||||
from frappe.core.doctype.data_import.data_import import import_doc
|
||||
|
||||
|
||||
class ShopifySettings(unittest.TestCase):
|
||||
def setUp(self):
|
||||
frappe.set_user("Administrator")
|
||||
sync_fixtures("erpnext_shopify")
|
||||
|
||||
# use the fixture data
|
||||
import_doc(path=frappe.get_app_path("erpnext", "erpnext_integrations/doctype/shopify_settings/test_data/custom_field.json"),
|
||||
ignore_links=True, overwrite=True)
|
||||
|
||||
frappe.reload_doctype("Customer")
|
||||
frappe.reload_doctype("Sales Order")
|
||||
frappe.reload_doctype("Delivery Note")
|
||||
|
@ -4,6 +4,7 @@ from __future__ import unicode_literals
|
||||
|
||||
|
||||
import frappe
|
||||
import erpnext
|
||||
import unittest
|
||||
import frappe.utils
|
||||
|
||||
@ -32,3 +33,35 @@ class TestEmployee(unittest.TestCase):
|
||||
self.assertTrue("Subject: Birthday Reminder for {0}".format(employee.employee_name) \
|
||||
in email_queue[0].message)
|
||||
|
||||
|
||||
|
||||
def make_employee(user):
|
||||
if not frappe.db.get_value("User", user):
|
||||
frappe.get_doc({
|
||||
"doctype": "User",
|
||||
"email": user,
|
||||
"first_name": user,
|
||||
"new_password": "password",
|
||||
"roles": [{"doctype": "Has Role", "role": "Employee"}]
|
||||
}).insert()
|
||||
|
||||
if not frappe.db.get_value("Employee", {"user_id": user}):
|
||||
employee = frappe.get_doc({
|
||||
"doctype": "Employee",
|
||||
"naming_series": "EMP-",
|
||||
"employee_name": user,
|
||||
"company": erpnext.get_default_company(),
|
||||
"user_id": user,
|
||||
"date_of_birth": "1990-05-08",
|
||||
"date_of_joining": "2013-01-01",
|
||||
"department": frappe.get_all("Department", fields="name")[0].name,
|
||||
"gender": "Female",
|
||||
"company_email": user,
|
||||
"prefered_contact_email": "Company Email",
|
||||
"prefered_email": user,
|
||||
"status": "Active",
|
||||
"employment_type": "Intern"
|
||||
}).insert()
|
||||
return employee.name
|
||||
else:
|
||||
return frappe.get_value("Employee", {"employee_name":user}, "name")
|
||||
|
@ -7,8 +7,21 @@ import frappe
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from erpnext.accounts.utils import get_fiscal_year, getdate, nowdate
|
||||
from erpnext.hr.doctype.payroll_entry.payroll_entry import get_start_end_dates, get_end_date
|
||||
from erpnext.hr.doctype.employee.test_employee import make_employee
|
||||
from erpnext.hr.doctype.salary_slip.test_salary_slip import get_salary_component_account, \
|
||||
make_earning_salary_component, make_deduction_salary_component
|
||||
from erpnext.hr.doctype.salary_structure.test_salary_structure import make_salary_structure
|
||||
from erpnext.hr.doctype.loan.test_loan import create_loan
|
||||
|
||||
|
||||
class TestPayrollEntry(unittest.TestCase):
|
||||
def setUp(self):
|
||||
for dt in ["Salary Slip", "Salary Component", "Salary Component Account", "Payroll Entry", "Loan"]:
|
||||
frappe.db.sql("delete from `tab%s`" % dt)
|
||||
|
||||
make_earning_salary_component(["Basic Salary", "Special Allowance", "HRA"])
|
||||
make_deduction_salary_component(["Professional Tax", "TDS"])
|
||||
|
||||
def test_payroll_entry(self): # pylint: disable=no-self-use
|
||||
|
||||
for data in frappe.get_all('Salary Component', fields = ["name"]):
|
||||
@ -16,8 +29,9 @@ class TestPayrollEntry(unittest.TestCase):
|
||||
{'parent': data.name, 'company': erpnext.get_default_company()}, 'name'):
|
||||
get_salary_component_account(data.name)
|
||||
|
||||
if not frappe.db.get_value("Salary Slip", {"start_date": "2016-11-01", "end_date": "2016-11-30"}):
|
||||
make_payroll_entry()
|
||||
dates = get_start_end_dates('Monthly', nowdate())
|
||||
if not frappe.db.get_value("Salary Slip", {"start_date": dates.start_date, "end_date": dates.end_date}):
|
||||
make_payroll_entry(start_date=dates.start_date, end_date=dates.end_date)
|
||||
|
||||
def test_get_end_date(self):
|
||||
self.assertEqual(get_end_date('2017-01-01', 'monthly'), {'end_date': '2017-01-31'})
|
||||
@ -30,36 +44,12 @@ class TestPayrollEntry(unittest.TestCase):
|
||||
self.assertEqual(get_end_date('2017-02-15', 'daily'), {'end_date': '2017-02-15'})
|
||||
|
||||
def test_loan(self):
|
||||
from erpnext.hr.doctype.salary_structure.test_salary_structure import (make_employee,
|
||||
make_salary_structure)
|
||||
from erpnext.hr.doctype.loan.test_loan import create_loan
|
||||
|
||||
branch = "Test Employee Branch"
|
||||
applicant = make_employee("test_employee@loan.com")
|
||||
company = erpnext.get_default_company()
|
||||
holiday_list = make_holiday("test holiday for loan")
|
||||
|
||||
if not frappe.db.exists('Salary Component', 'Basic Salary'):
|
||||
frappe.get_doc({
|
||||
'doctype': 'Salary Component',
|
||||
'salary_component': 'Basic Salary',
|
||||
'salary_component_abbr': 'BS',
|
||||
'type': 'Earning',
|
||||
'accounts': [{
|
||||
'company': company,
|
||||
'default_account': frappe.db.get_value('Account',
|
||||
{'company': company, 'root_type': 'Expense', 'account_type': ''}, 'name')
|
||||
}]
|
||||
}).insert()
|
||||
|
||||
if not frappe.db.get_value('Salary Component Account',
|
||||
{'parent': 'Basic Salary', 'company': company}):
|
||||
salary_component = frappe.get_doc('Salary Component', 'Basic Salary')
|
||||
salary_component.append('accounts', {
|
||||
'company': company,
|
||||
'default_account': "Salary - " + frappe.db.get_value('Company', company, 'abbr')
|
||||
})
|
||||
|
||||
company_doc = frappe.get_doc('Company', company)
|
||||
if not company_doc.default_payroll_payable_account:
|
||||
company_doc.default_payroll_payable_account = frappe.db.get_value('Account',
|
||||
@ -81,23 +71,8 @@ class TestPayrollEntry(unittest.TestCase):
|
||||
"Personal Loan", 280000, "Repay Over Number of Periods", 20)
|
||||
loan.repay_from_salary = 1
|
||||
loan.submit()
|
||||
|
||||
salary_strcture = "Test Salary Structure for Loan"
|
||||
if not frappe.db.exists('Salary Structure', salary_strcture):
|
||||
salary_strcture = make_salary_structure(salary_strcture, [{
|
||||
'employee': applicant,
|
||||
'from_date': '2017-01-01',
|
||||
'base': 30000
|
||||
}])
|
||||
|
||||
salary_strcture = frappe.get_doc('Salary Structure', salary_strcture)
|
||||
salary_strcture.set('earnings', [{
|
||||
'salary_component': 'Basic Salary',
|
||||
'abbr': 'BS',
|
||||
'amount_based_on_formula':1,
|
||||
'formula': 'base*.5'
|
||||
}])
|
||||
salary_strcture.save()
|
||||
salary_structure = "Test Salary Structure for Loan"
|
||||
salary_structure = make_salary_structure(salary_structure, "Monthly", employee_doc.name)
|
||||
|
||||
dates = get_start_end_dates('Monthly', nowdate())
|
||||
make_payroll_entry(start_date=dates.start_date,
|
||||
@ -119,26 +94,6 @@ class TestPayrollEntry(unittest.TestCase):
|
||||
if salary_slip.docstatus == 0:
|
||||
frappe.delete_doc('Salary Slip', name)
|
||||
|
||||
loan.cancel()
|
||||
frappe.delete_doc('Loan', loan.name)
|
||||
|
||||
def get_salary_component_account(sal_comp):
|
||||
company = erpnext.get_default_company()
|
||||
sal_comp = frappe.get_doc("Salary Component", sal_comp)
|
||||
sc = sal_comp.append("accounts")
|
||||
sc.company = company
|
||||
sc.default_account = create_account(company)
|
||||
|
||||
def create_account(company):
|
||||
salary_account = frappe.db.get_value("Account", "Salary - " + frappe.db.get_value('Company', company, 'abbr'))
|
||||
if not salary_account:
|
||||
frappe.get_doc({
|
||||
"doctype": "Account",
|
||||
"account_name": "Salary",
|
||||
"parent_account": "Indirect Expenses - " + frappe.db.get_value('Company', company, 'abbr'),
|
||||
"company": company
|
||||
}).insert()
|
||||
return salary_account
|
||||
|
||||
def make_payroll_entry(**args):
|
||||
args = frappe._dict(args)
|
||||
|
@ -10,8 +10,9 @@ from erpnext.accounts.utils import get_fiscal_year
|
||||
from frappe.utils.make_random import get_random
|
||||
from frappe.utils import getdate, nowdate, add_days, add_months, flt
|
||||
from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip
|
||||
from erpnext.hr.doctype.payroll_entry.test_payroll_entry import get_salary_component_account
|
||||
from erpnext.hr.doctype.payroll_entry.payroll_entry import get_month_details
|
||||
from erpnext.hr.doctype.employee.test_employee import make_employee
|
||||
|
||||
|
||||
class TestSalarySlip(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@ -32,11 +33,10 @@ class TestSalarySlip(unittest.TestCase):
|
||||
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")
|
||||
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)
|
||||
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"))
|
||||
ss = make_employee_salary_slip("test_employee@salary.com", "Monthly")
|
||||
|
||||
self.assertEqual(ss.total_working_days, no_of_days[0])
|
||||
self.assertEqual(ss.payment_days, no_of_days[0])
|
||||
@ -50,11 +50,10 @@ class TestSalarySlip(unittest.TestCase):
|
||||
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")
|
||||
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)
|
||||
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"))
|
||||
ss = make_employee_salary_slip("test_employee@salary.com", "Monthly")
|
||||
|
||||
self.assertEqual(ss.total_working_days, no_of_days[0] - no_of_days[1])
|
||||
self.assertEqual(ss.payment_days, no_of_days[0] - no_of_days[1])
|
||||
@ -72,7 +71,7 @@ class TestSalarySlip(unittest.TestCase):
|
||||
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")
|
||||
make_employee("test_employee@salary.com")
|
||||
if getdate(nowdate()).day >= 15:
|
||||
date_of_joining = getdate(add_days(nowdate(),-10))
|
||||
relieving_date = getdate(add_days(nowdate(),-10))
|
||||
@ -93,8 +92,7 @@ class TestSalarySlip(unittest.TestCase):
|
||||
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"))
|
||||
ss = make_employee_salary_slip("test_employee@salary.com", "Monthly")
|
||||
|
||||
self.assertEqual(ss.total_working_days, no_of_days[0])
|
||||
self.assertEqual(ss.payment_days, (no_of_days[0] - getdate(date_of_joining).day + 1))
|
||||
@ -112,10 +110,9 @@ class TestSalarySlip(unittest.TestCase):
|
||||
frappe.db.set_value("Employee", frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"), "status", "Active")
|
||||
|
||||
def test_employee_salary_slip_read_permission(self):
|
||||
self.make_employee("test_employee@salary.com")
|
||||
make_employee("test_employee@salary.com")
|
||||
|
||||
salary_slip_test_employee = frappe.get_doc("Salary Slip",
|
||||
self.make_employee_salary_slip("test_employee@salary.com", "Monthly"))
|
||||
salary_slip_test_employee = make_employee_salary_slip("test_employee@salary.com", "Monthly")
|
||||
frappe.set_user("test_employee@salary.com")
|
||||
self.assertTrue(salary_slip_test_employee.has_permission("read"))
|
||||
|
||||
@ -126,9 +123,8 @@ class TestSalarySlip(unittest.TestCase):
|
||||
hr_settings.email_salary_slip_to_employee = 1
|
||||
hr_settings.save()
|
||||
|
||||
self.make_employee("test_employee@salary.com")
|
||||
ss = frappe.get_doc("Salary Slip",
|
||||
self.make_employee_salary_slip("test_employee@salary.com", "Monthly"))
|
||||
make_employee("test_employee@salary.com")
|
||||
ss = make_employee_salary_slip("test_employee@salary.com", "Monthly")
|
||||
ss.submit()
|
||||
|
||||
email_queue = frappe.db.sql("""select name from `tabEmail Queue`""")
|
||||
@ -136,26 +132,24 @@ class TestSalarySlip(unittest.TestCase):
|
||||
|
||||
def test_loan_repayment_salary_slip(self):
|
||||
from erpnext.hr.doctype.loan.test_loan import create_loan_type, create_loan
|
||||
applicant = self.make_employee("test_employee@salary.com")
|
||||
applicant = make_employee("test_employee@salary.com")
|
||||
create_loan_type("Car Loan", 500000, 6.4)
|
||||
loan = create_loan(applicant, "Car Loan", 11000, "Repay Over Number of Periods", 20)
|
||||
loan.repay_from_salary = 1
|
||||
loan.submit()
|
||||
ss = frappe.get_doc("Salary Slip",
|
||||
self.make_employee_salary_slip("test_employee@salary.com", "Monthly"))
|
||||
ss = make_employee_salary_slip("test_employee@salary.com", "Monthly")
|
||||
ss.submit()
|
||||
self.assertEqual(ss.total_loan_repayment, 582)
|
||||
self.assertEqual(ss.net_pay, (flt(ss.gross_pay) - (flt(ss.total_deduction) + flt(ss.total_loan_repayment))))
|
||||
|
||||
def test_payroll_frequency(self):
|
||||
fiscal_year = get_fiscal_year(nowdate(), company="_Test Company")[0]
|
||||
fiscal_year = get_fiscal_year(nowdate(), company=erpnext.get_default_company())[0]
|
||||
month = "%02d" % getdate(nowdate()).month
|
||||
m = get_month_details(fiscal_year, month)
|
||||
|
||||
for payroll_frequncy in ["Monthly", "Bimonthly", "Fortnightly", "Weekly", "Daily"]:
|
||||
self.make_employee(payroll_frequncy + "_test_employee@salary.com")
|
||||
ss = frappe.get_doc("Salary Slip",
|
||||
self.make_employee_salary_slip(payroll_frequncy + "_test_employee@salary.com", payroll_frequncy))
|
||||
make_employee(payroll_frequncy + "_test_employee@salary.com")
|
||||
ss = make_employee_salary_slip(payroll_frequncy + "_test_employee@salary.com", payroll_frequncy)
|
||||
if payroll_frequncy == "Monthly":
|
||||
self.assertEqual(ss.end_date, m['month_end_date'])
|
||||
elif payroll_frequncy == "Bimonthly":
|
||||
@ -164,45 +158,14 @@ class TestSalarySlip(unittest.TestCase):
|
||||
else:
|
||||
self.assertEqual(ss.end_date, m['month_end_date'])
|
||||
elif payroll_frequncy == "Fortnightly":
|
||||
self.assertEqual(ss.end_date, getdate(add_days(nowdate(),13)))
|
||||
self.assertEqual(ss.end_date, add_days(nowdate(),13))
|
||||
elif payroll_frequncy == "Weekly":
|
||||
self.assertEqual(ss.end_date, getdate(add_days(nowdate(),6)))
|
||||
self.assertEqual(ss.end_date, add_days(nowdate(),6))
|
||||
elif payroll_frequncy == "Daily":
|
||||
self.assertEqual(ss.end_date, getdate(nowdate()))
|
||||
|
||||
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",
|
||||
"roles": [{"doctype": "Has Role", "role": "Employee"}]
|
||||
}).insert()
|
||||
|
||||
if not frappe.db.get_value("Employee", {"user_id": user}):
|
||||
employee = frappe.get_doc({
|
||||
"doctype": "Employee",
|
||||
"naming_series": "EMP-",
|
||||
"employee_name": user,
|
||||
"company": erpnext.get_default_company(),
|
||||
"user_id": user,
|
||||
"date_of_birth": "1990-05-08",
|
||||
"date_of_joining": "2013-01-01",
|
||||
"department": frappe.get_all("Department", fields="name")[0].name,
|
||||
"gender": "Female",
|
||||
"company_email": user,
|
||||
"prefered_contact_email": "Company Email",
|
||||
"prefered_email": user,
|
||||
"status": "Active",
|
||||
"employment_type": "Intern"
|
||||
}).insert()
|
||||
return employee.name
|
||||
else:
|
||||
return frappe.get_value("Employee", {"employee_name":user}, "name")
|
||||
self.assertEqual(ss.end_date, nowdate())
|
||||
|
||||
def make_holiday_list(self):
|
||||
fiscal_year = get_fiscal_year(nowdate(), company="_Test Company")
|
||||
fiscal_year = get_fiscal_year(nowdate(), company=erpnext.get_default_company())
|
||||
if not frappe.db.get_value("Holiday List", "Salary Slip Test Holiday List"):
|
||||
holiday_list = frappe.get_doc({
|
||||
"doctype": "Holiday List",
|
||||
@ -214,22 +177,6 @@ class TestSalarySlip(unittest.TestCase):
|
||||
holiday_list.get_weekly_off_dates()
|
||||
holiday_list.save()
|
||||
|
||||
def make_employee_salary_slip(self, user, payroll_frequency):
|
||||
employee = frappe.db.get_value("Employee", {"user_id": user})
|
||||
salary_structure = make_salary_structure(payroll_frequency + " Salary Structure Test for Salary Slip", payroll_frequency, employee)
|
||||
salary_slip = frappe.db.get_value("Salary Slip", {"employee": frappe.db.get_value("Employee", {"user_id": user})})
|
||||
|
||||
if not salary_slip:
|
||||
salary_slip = make_salary_slip(salary_structure, employee = employee)
|
||||
salary_slip.employee_name = frappe.get_value("Employee", {"name":frappe.db.get_value("Employee", {"user_id": user})}, "employee_name")
|
||||
salary_slip.payroll_frequency = payroll_frequency
|
||||
salary_slip.posting_date = nowdate()
|
||||
salary_slip.insert()
|
||||
# salary_slip.submit()
|
||||
salary_slip = salary_slip.name
|
||||
|
||||
return salary_slip
|
||||
|
||||
def make_activity_for_employee(self):
|
||||
activity_type = frappe.get_doc("Activity Type", "_Test Activity Type")
|
||||
activity_type.billing_rate = 50
|
||||
@ -246,6 +193,26 @@ class TestSalarySlip(unittest.TestCase):
|
||||
return [no_of_days_in_month[1], no_of_holidays_in_month]
|
||||
|
||||
|
||||
def make_employee_salary_slip(user, payroll_frequency, salary_structure=None):
|
||||
from erpnext.hr.doctype.salary_structure.test_salary_structure import make_salary_structure
|
||||
if not salary_structure:
|
||||
salary_structure = payroll_frequency + " Salary Structure Test for Salary Slip"
|
||||
employee = frappe.db.get_value("Employee", {"user_id": user})
|
||||
salary_structure = make_salary_structure(salary_structure, payroll_frequency, employee)
|
||||
salary_slip = frappe.db.get_value("Salary Slip", {"employee": frappe.db.get_value("Employee", {"user_id": user})})
|
||||
|
||||
if not salary_slip:
|
||||
salary_slip = make_salary_slip(salary_structure, employee = employee)
|
||||
salary_slip.employee_name = frappe.get_value("Employee", {"name":frappe.db.get_value("Employee", {"user_id": user})}, "employee_name")
|
||||
salary_slip.payroll_frequency = payroll_frequency
|
||||
salary_slip.posting_date = nowdate()
|
||||
salary_slip.insert()
|
||||
# salary_slip.submit()
|
||||
# salary_slip = salary_slip.name
|
||||
|
||||
return salary_slip
|
||||
|
||||
|
||||
def make_earning_salary_component(salary_components):
|
||||
for salary_component in salary_components:
|
||||
if not frappe.db.exists('Salary Component', salary_component):
|
||||
@ -268,35 +235,32 @@ def make_deduction_salary_component(salary_components):
|
||||
sal_comp.insert()
|
||||
get_salary_component_account(salary_component)
|
||||
|
||||
def make_salary_structure(sal_struct, payroll_frequency, employee):
|
||||
if not frappe.db.exists('Salary Structure', sal_struct):
|
||||
salary_structure = frappe.get_doc({
|
||||
"doctype": "Salary Structure",
|
||||
"name": sal_struct,
|
||||
"company": "_Test Company",
|
||||
"earnings": get_earnings_component(),
|
||||
"deductions": get_deductions_component(),
|
||||
"payroll_frequency": payroll_frequency,
|
||||
"payment_account": get_random("Account")
|
||||
def get_salary_component_account(sal_comp):
|
||||
company = erpnext.get_default_company()
|
||||
sal_comp = frappe.get_doc("Salary Component", sal_comp)
|
||||
sal_comp.append("accounts", {
|
||||
"company": company,
|
||||
"default_account": create_account(company)
|
||||
})
|
||||
sal_comp.save()
|
||||
|
||||
|
||||
def create_account(company):
|
||||
salary_account = frappe.db.get_value("Account", "Salary - " + frappe.db.get_value('Company', company, 'abbr'))
|
||||
if not salary_account:
|
||||
frappe.get_doc({
|
||||
"doctype": "Account",
|
||||
"account_name": "Salary",
|
||||
"parent_account": "Indirect Expenses - " + frappe.db.get_value('Company', company, 'abbr'),
|
||||
"company": company
|
||||
}).insert()
|
||||
create_salary_structure_assignment(employee, salary_structure.name)
|
||||
return salary_account
|
||||
|
||||
elif not frappe.db.get_value("Salary Structure Assignment",{'salary_structure':sal_struct, 'employee':employee},'name'):
|
||||
create_salary_structure_assignment(employee, sal_struct)
|
||||
return sal_struct
|
||||
|
||||
def create_salary_structure_assignment(employee, salary_structure):
|
||||
salary_structure_assignment = frappe.new_doc("Salary Structure Assignment")
|
||||
salary_structure_assignment.employee = employee
|
||||
salary_structure_assignment.base = 50000
|
||||
salary_structure_assignment.variable = 5000
|
||||
salary_structure_assignment.from_date = add_months(nowdate(), -1)
|
||||
salary_structure_assignment.salary_structure = salary_structure
|
||||
salary_structure_assignment.company = erpnext.get_default_company()
|
||||
salary_structure_assignment.save(ignore_permissions=True)
|
||||
return salary_structure_assignment
|
||||
def get_earnings_component(setup=False):
|
||||
if setup:
|
||||
make_earning_salary_component(["Basic Salary", "Special Allowance", "HRA"])
|
||||
|
||||
def get_earnings_component():
|
||||
return [
|
||||
{
|
||||
"salary_component": 'Basic Salary',
|
||||
@ -327,7 +291,10 @@ def get_earnings_component():
|
||||
},
|
||||
]
|
||||
|
||||
def get_deductions_component():
|
||||
def get_deductions_component(setup=False):
|
||||
if setup:
|
||||
make_deduction_salary_component(["Professional Tax", "TDS"])
|
||||
|
||||
return [
|
||||
{
|
||||
"salary_component": 'Professional Tax',
|
||||
|
@ -8,18 +8,24 @@ import erpnext
|
||||
from frappe.utils.make_random import get_random
|
||||
from frappe.utils import nowdate, add_days, add_years, getdate, add_months
|
||||
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
|
||||
from erpnext.hr.doctype.salary_slip.test_salary_slip import get_earnings_component,\
|
||||
get_deductions_component, make_employee_salary_slip
|
||||
from erpnext.hr.doctype.employee.test_employee import make_employee
|
||||
|
||||
|
||||
test_dependencies = ["Fiscal Year"]
|
||||
|
||||
class TestSalaryStructure(unittest.TestCase):
|
||||
def setUp(self):
|
||||
for dt in ["Salary Slip", "Salary Structure", "Salary Structure Assignment"]:
|
||||
frappe.db.sql("delete from `tab%s`" % dt)
|
||||
|
||||
self.make_holiday_list()
|
||||
frappe.db.set_value("Company", erpnext.get_default_company(), "default_holiday_list", "Salary Structure Test Holiday List")
|
||||
make_employee("test_employee@salary.com")
|
||||
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"):
|
||||
holiday_list = frappe.get_doc({
|
||||
@ -33,18 +39,21 @@ class TestSalaryStructure(unittest.TestCase):
|
||||
holiday_list.save()
|
||||
|
||||
def test_amount_totals(self):
|
||||
sal_slip = frappe.get_value("Salary Slip", {"employee_name":"test_employee@salary.com"})
|
||||
sal_slip = frappe.get_value("Salary Slip", {"employee_name":"test_employee_2@salary.com"})
|
||||
if not sal_slip:
|
||||
sal_slip = make_salary_slip_from_salary_structure(employee=frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}))
|
||||
sal_slip = make_employee_salary_slip("test_employee_2@salary.com", "Monthly", "Salary Structure Sample")
|
||||
self.assertEqual(sal_slip.get("salary_structure"), 'Salary Structure Sample')
|
||||
self.assertEqual(sal_slip.get("earnings")[0].amount, 5000)
|
||||
self.assertEqual(sal_slip.get("earnings")[0].amount, 25000)
|
||||
self.assertEqual(sal_slip.get("earnings")[1].amount, 3000)
|
||||
self.assertEqual(sal_slip.get("earnings")[2].amount, 12500)
|
||||
self.assertEqual(sal_slip.get("gross_pay"), 40500)
|
||||
self.assertEqual(sal_slip.get("deductions")[0].amount, 5000)
|
||||
self.assertEqual(sal_slip.get("deductions")[1].amount, 2500)
|
||||
self.assertEqual(sal_slip.get("total_deduction"), 7500)
|
||||
self.assertEqual(sal_slip.get("net_pay"), 7500)
|
||||
self.assertEqual(sal_slip.get("deductions")[1].amount, 5000)
|
||||
self.assertEqual(sal_slip.get("total_deduction"), 10000)
|
||||
self.assertEqual(sal_slip.get("net_pay"), 30500)
|
||||
|
||||
def test_whitespaces_in_formula_conditions_fields(self):
|
||||
make_salary_structure("Salary Structure Sample")
|
||||
make_salary_structure("Salary Structure Sample", "Monthly")
|
||||
salary_structure = frappe.get_doc("Salary Structure", "Salary Structure Sample")
|
||||
|
||||
for row in salary_structure.earnings:
|
||||
@ -63,131 +72,33 @@ class TestSalaryStructure(unittest.TestCase):
|
||||
for row in salary_structure.deductions:
|
||||
self.assertFalse(("\n" in row.formula) or ("\n" in row.condition))
|
||||
|
||||
def make_employee(user):
|
||||
if not frappe.db.get_value("User", user):
|
||||
frappe.get_doc({
|
||||
"doctype": "User",
|
||||
"email": user,
|
||||
"first_name": user,
|
||||
"new_password": "password",
|
||||
"roles": [{"doctype": "Has Role", "role": "Employee"}]
|
||||
}).insert()
|
||||
|
||||
if not frappe.db.get_value("Employee", {"user_id": user}):
|
||||
emp = frappe.get_doc({
|
||||
"doctype": "Employee",
|
||||
"naming_series": "EMP-",
|
||||
"employee_name": user,
|
||||
"company": erpnext.get_default_company(),
|
||||
"user_id": user,
|
||||
"date_of_birth": "1990-05-08",
|
||||
"date_of_joining": "2013-01-01",
|
||||
"relieving_date": "",
|
||||
"department": frappe.get_all("Department", fields="name")[0].name,
|
||||
"gender": "Female",
|
||||
"company_email": user,
|
||||
"status": "Active",
|
||||
"employment_type": "Intern"
|
||||
}).insert()
|
||||
return emp.name
|
||||
else:
|
||||
return frappe.get_value("Employee", {"employee_name":user}, "name")
|
||||
|
||||
def make_salary_slip_from_salary_structure(employee):
|
||||
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.start_date = nowdate()
|
||||
sal_slip.posting_date = nowdate()
|
||||
sal_slip.payroll_frequency = "Monthly"
|
||||
sal_slip.insert()
|
||||
sal_slip.submit()
|
||||
return sal_slip
|
||||
|
||||
def make_salary_structure(sal_struct, employees=None):
|
||||
if not frappe.db.exists('Salary Structure', sal_struct):
|
||||
frappe.get_doc({
|
||||
def make_salary_structure(salary_structure, payroll_frequency, employee=None):
|
||||
if not frappe.db.exists('Salary Structure', salary_structure):
|
||||
salary_structure_doc = frappe.get_doc({
|
||||
"doctype": "Salary Structure",
|
||||
"name": sal_struct,
|
||||
"name": salary_structure,
|
||||
"company": erpnext.get_default_company(),
|
||||
"employees": employees or get_employee_details(),
|
||||
"earnings": get_earnings_component(),
|
||||
"deductions": get_deductions_component(),
|
||||
"payroll_frequency": "Monthly",
|
||||
"payment_account": frappe.get_value('Account', {'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name")
|
||||
"payroll_frequency": payroll_frequency,
|
||||
"payment_account": get_random("Account")
|
||||
}).insert()
|
||||
return sal_struct
|
||||
if employee:
|
||||
create_salary_structure_assignment(employee, salary_structure)
|
||||
|
||||
def get_employee_details():
|
||||
return [{"employee": frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}, "name"),
|
||||
"base": 25000,
|
||||
"variable": 5000,
|
||||
"from_date": add_months(nowdate(),-1),
|
||||
"idx": 1
|
||||
},
|
||||
{"employee": frappe.get_value("Employee", {"employee_name":"test_employee_2@salary.com"}, "name"),
|
||||
"base": 15000,
|
||||
"variable": 100,
|
||||
"from_date": add_months(nowdate(),-1),
|
||||
"idx": 2
|
||||
}
|
||||
]
|
||||
elif employee and not frappe.db.get_value("Salary Structure Assignment",{'salary_structure':salary_structure, 'employee':employee},'name'):
|
||||
create_salary_structure_assignment(employee, salary_structure)
|
||||
return salary_structure
|
||||
|
||||
def get_earnings_component():
|
||||
make_earning_salary_component(["Basic Salary", "Special Allowance", "HRA"])
|
||||
make_deduction_salary_component(["Professional Tax", "TDS"])
|
||||
|
||||
return [
|
||||
{
|
||||
"salary_component": 'Basic Salary',
|
||||
"abbr":'BS',
|
||||
"condition": 'base > 10000',
|
||||
"formula": 'base*.2',
|
||||
"idx": 1
|
||||
},
|
||||
{
|
||||
"salary_component": 'Basic Salary',
|
||||
"abbr":'BS',
|
||||
"condition": 'base < 10000',
|
||||
"formula": 'base*.1',
|
||||
"idx": 2
|
||||
},
|
||||
{
|
||||
"salary_component": 'HRA',
|
||||
"abbr":'H',
|
||||
"amount": 10000,
|
||||
"idx": 3
|
||||
},
|
||||
{
|
||||
"salary_component": 'Special Allowance',
|
||||
"abbr":'SA',
|
||||
"condition": 'H < 10000',
|
||||
"formula": 'BS*.5',
|
||||
"idx": 4
|
||||
},
|
||||
]
|
||||
|
||||
def get_deductions_component():
|
||||
return [
|
||||
{
|
||||
"salary_component": 'Professional Tax',
|
||||
"abbr":'PT',
|
||||
"condition": 'base > 10000',
|
||||
"formula": 'base*.2',
|
||||
"idx": 1
|
||||
},
|
||||
{
|
||||
"salary_component": 'TDS',
|
||||
"abbr":'T',
|
||||
"condition": 'employment_type!="Intern"',
|
||||
"formula": 'base*.5',
|
||||
"idx": 2
|
||||
},
|
||||
{
|
||||
"salary_component": 'TDS',
|
||||
"abbr":'T',
|
||||
"condition": 'employment_type=="Intern"',
|
||||
"formula": 'base*.1',
|
||||
"idx": 3
|
||||
}
|
||||
]
|
||||
def create_salary_structure_assignment(employee, salary_structure):
|
||||
salary_structure_assignment = frappe.new_doc("Salary Structure Assignment")
|
||||
salary_structure_assignment.employee = employee
|
||||
salary_structure_assignment.base = 50000
|
||||
salary_structure_assignment.variable = 5000
|
||||
salary_structure_assignment.from_date = add_months(nowdate(), -1)
|
||||
salary_structure_assignment.salary_structure = salary_structure
|
||||
salary_structure_assignment.company = erpnext.get_default_company()
|
||||
salary_structure_assignment.save(ignore_permissions=True)
|
||||
salary_structure_assignment.submit()
|
||||
return salary_structure_assignment
|
@ -685,7 +685,7 @@ class TestStockEntry(unittest.TestCase):
|
||||
from erpnext.manufacturing.doctype.work_order.work_order \
|
||||
import make_stock_entry as _make_stock_entry
|
||||
bom_no = frappe.db.get_value("BOM", {"item": "_Test FG Item 2",
|
||||
"is_default": 1, "docstatus": 1}, ["name", "operating_cost"])
|
||||
"is_default": 1, "docstatus": 1})
|
||||
|
||||
work_order = frappe.new_doc("Work Order")
|
||||
work_order.update({
|
||||
|
@ -9,15 +9,12 @@ class TestWoocommerce(unittest.TestCase):
|
||||
company.abbr = "W"
|
||||
company.default_currency = "INR"
|
||||
company.save()
|
||||
frappe.db.commit()
|
||||
|
||||
default = frappe.get_doc("Global Defaults")
|
||||
self.old_default_company = default.default_company
|
||||
default.default_company = "Woocommerce"
|
||||
default.save()
|
||||
|
||||
frappe.db.commit()
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
woo_settings = frappe.get_doc("Woocommerce Settings")
|
||||
@ -30,7 +27,6 @@ class TestWoocommerce(unittest.TestCase):
|
||||
woo_settings.f_n_f_account = "Expenses - W"
|
||||
woo_settings.save(ignore_permissions=True)
|
||||
|
||||
frappe.db.commit()
|
||||
|
||||
def test_woocommerce_request(self):
|
||||
r = emulate_request()
|
||||
@ -51,7 +47,6 @@ class TestWoocommerce(unittest.TestCase):
|
||||
default = frappe.get_doc("Global Defaults")
|
||||
default.default_company = self.old_default_company
|
||||
default.save()
|
||||
frappe.db.commit()
|
||||
|
||||
|
||||
|
||||
@ -86,6 +81,5 @@ def cancel_and_delete_order():
|
||||
if isinstance(so, erpnext.selling.doctype.sales_order.sales_order.SalesOrder):
|
||||
so.cancel()
|
||||
so.delete()
|
||||
frappe.db.commit()
|
||||
except frappe.DoesNotExistError:
|
||||
pass
|
Loading…
x
Reference in New Issue
Block a user