fix: test cases

This commit is contained in:
Afshan
2020-10-23 23:09:55 +05:30
parent fceee55905
commit 4730646dd8
21 changed files with 181 additions and 106 deletions

View File

@@ -962,7 +962,7 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=
party_account = set_party_account(dt, dn, doc, party_type)
exchange_rate = 1
party_account_currency = set_party_account_currency(dt, party_account, doc)
if party_account_currency != doc.currency:
if dt != 'Expense Claim' and party_account_currency != doc.currency:
exchange_rate = doc.get('exchange_rate', 1)
payment_type = set_payment_type(dt, doc)
grand_total, outstanding_amount = set_grand_total_and_outstanding_amount(party_amount, dt, party_account_currency, doc, exchange_rate)

View File

@@ -13,8 +13,8 @@ from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import g
class AssetValueAdjustment(Document):
def validate(self):
self.validate_date()
self.set_difference_amount()
self.set_current_asset_value()
self.set_difference_amount()
def on_submit(self):
self.make_depreciation_entry()

View File

@@ -134,7 +134,7 @@ def setup_employee():
salary_component = frappe.get_doc('Salary Component', d.name)
salary_component.append('accounts', dict(
company=erpnext.get_default_company(),
default_account=frappe.get_value('Account', dict(account_name=('like', 'Salary%')))
account=frappe.get_value('Account', dict(account_name=('like', 'Salary%')))
))
salary_component.save()

View File

@@ -3,15 +3,17 @@
# See license.txt
from __future__ import unicode_literals
import frappe
import frappe, erpnext
import unittest
from frappe.utils import nowdate
from erpnext.hr.doctype.employee_advance.employee_advance import make_bank_entry
from erpnext.hr.doctype.employee_advance.employee_advance import EmployeeAdvanceOverPayment
from erpnext.hr.doctype.employee.test_employee import make_employee
class TestEmployeeAdvance(unittest.TestCase):
def test_paid_amount_and_status(self):
advance = make_employee_advance()
employee_name = make_employee("_T@employe.advance")
advance = make_employee_advance(employee_name)
journal_entry = make_payment_entry(advance)
journal_entry.submit()
@@ -33,11 +35,13 @@ def make_payment_entry(advance):
return journal_entry
def make_employee_advance():
def make_employee_advance(employee_name):
doc = frappe.new_doc("Employee Advance")
doc.employee = "_T-Employee-00001"
doc.employee = employee_name
doc.company = "_Test company"
doc.purpose = "For site visit"
doc.currency = erpnext.get_company_currency("_Test company")
doc.exchange_rate = 1
doc.advance_amount = 1000
doc.posting_date = nowdate()
doc.advance_account = "_Test Employee Advance - _TC"

View File

@@ -45,7 +45,8 @@ class TestLeaveEncashment(unittest.TestCase):
employee=self.employee,
leave_type="_Test Leave Type Encashment",
leave_period=self.leave_period.name,
payroll_date=today()
payroll_date=today(),
currency="INR"
)).insert()
self.assertEqual(leave_encashment.leave_balance, 10)
@@ -65,7 +66,8 @@ class TestLeaveEncashment(unittest.TestCase):
employee=self.employee,
leave_type="_Test Leave Type Encashment",
leave_period=self.leave_period.name,
payroll_date=today()
payroll_date=today(),
currency="INR"
)).insert()
leave_encashment.submit()

View File

@@ -19,6 +19,7 @@ from erpnext.loan_management.doctype.loan_security_unpledge.loan_security_unpled
from erpnext.loan_management.doctype.loan_application.loan_application import create_pledge
from erpnext.loan_management.doctype.loan_disbursement.loan_disbursement import get_disbursal_amount
from erpnext.loan_management.doctype.loan_repayment.loan_repayment import calculate_amounts
from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure
class TestLoan(unittest.TestCase):
def setUp(self):
@@ -44,6 +45,7 @@ class TestLoan(unittest.TestCase):
create_loan_security_price("Test Security 2", 250, "Nos", get_datetime() , get_datetime(add_to_date(nowdate(), hours=24)))
self.applicant1 = make_employee("robert_loan@loan.com")
make_salary_structure("Test Salary Structure Loan", "Monthly", employee=self.applicant1, currency='INR')
if not frappe.db.exists("Customer", "_Test Loan Customer"):
frappe.get_doc(get_customer_dict('_Test Loan Customer')).insert(ignore_permissions=True)

View File

@@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe
import unittest
from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_employee
from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_employee, make_salary_structure
from erpnext.loan_management.doctype.loan.test_loan import create_loan_type, create_loan_accounts
class TestLoanApplication(unittest.TestCase):
@@ -14,6 +14,7 @@ class TestLoanApplication(unittest.TestCase):
create_loan_type("Home Loan", 500000, 9.2, 0, 1, 0, 'Cash', 'Payment Account - _TC', 'Loan Account - _TC',
'Interest Income Account - _TC', 'Penalty Income Account - _TC', 'Repay Over Number of Periods', 18)
self.applicant = make_employee("kate_loan@loan.com", "_Test Company")
make_salary_structure("Test Salary Structure Loan", "Monthly", employee=self.applicant, currency='INR')
self.create_loan_application()
def create_loan_application(self):

View File

@@ -8,6 +8,7 @@ from frappe.utils import nowdate, add_days
from erpnext.hr.doctype.employee.test_employee import make_employee
from erpnext.payroll.doctype.salary_component.test_salary_component import create_salary_component
from erpnext.payroll.doctype.salary_slip.test_salary_slip import make_employee_salary_slip, setup_test
from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure
class TestAdditionalSalary(unittest.TestCase):
@@ -16,11 +17,14 @@ class TestAdditionalSalary(unittest.TestCase):
setup_test()
def test_recurring_additional_salary(self):
amount = 0
salary_component = None
emp_id = make_employee("test_additional@salary.com")
frappe.db.set_value("Employee", emp_id, "relieving_date", add_days(nowdate(), 1800))
salary_structure = make_salary_structure("Test Salary Structure Additional Salary", "Monthly", employee=emp_id)
add_sal = get_additional_salary(emp_id)
ss = make_employee_salary_slip("test_additional@salary.com", "Monthly")
ss = make_employee_salary_slip("test_additional@salary.com", "Monthly", salary_structure=salary_structure.name)
for earning in ss.earnings:
if earning.salary_component == "Recurring Salary Component":
amount = earning.amount
@@ -40,6 +44,7 @@ def get_additional_salary(emp_id):
add_sal.from_date = add_days(nowdate(), -50)
add_sal.to_date = add_days(nowdate(), 180)
add_sal.amount = 5000
add_sal.currency = erpnext.get_default_currency()
add_sal.save()
add_sal.submit()

View File

@@ -22,6 +22,7 @@ class TestEmployeeTaxExemptionDeclaration(unittest.TestCase):
"employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"),
"company": erpnext.get_default_company(),
"payroll_period": "_Test Payroll Period",
"currency": erpnext.get_default_currency(),
"declarations": [
dict(exemption_sub_category = "_Test Sub Category",
exemption_category = "_Test Category",
@@ -39,6 +40,7 @@ class TestEmployeeTaxExemptionDeclaration(unittest.TestCase):
"employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"),
"company": erpnext.get_default_company(),
"payroll_period": "_Test Payroll Period",
"currency": erpnext.get_default_currency(),
"declarations": [
dict(exemption_sub_category = "_Test Sub Category",
exemption_category = "_Test Category",
@@ -54,6 +56,7 @@ class TestEmployeeTaxExemptionDeclaration(unittest.TestCase):
"employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"),
"company": erpnext.get_default_company(),
"payroll_period": "_Test Payroll Period",
"currency": erpnext.get_default_currency(),
"declarations": [
dict(exemption_sub_category = "_Test Sub Category",
exemption_category = "_Test Category",
@@ -70,6 +73,7 @@ class TestEmployeeTaxExemptionDeclaration(unittest.TestCase):
"employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"),
"company": erpnext.get_default_company(),
"payroll_period": "_Test Payroll Period",
"currency": erpnext.get_default_currency(),
"declarations": [
dict(exemption_sub_category = "_Test Sub Category",
exemption_category = "_Test Category",

View File

@@ -18,7 +18,7 @@ frappe.ui.form.on('Payroll Entry', {
};
});
frm.set_query("default_payroll_payable_account", function() {
frm.set_query("payroll_payable_account", function() {
return {
filters: {
"company": frm.doc.company,

View File

@@ -15,7 +15,7 @@
"column_break1",
"currency",
"exchange_rate",
"default_payroll_payable_account",
"payroll_payable_account",
"section_break_8",
"branch",
"department",
@@ -280,7 +280,7 @@
},
{
"depends_on": "company",
"fieldname": "default_payroll_payable_account",
"fieldname": "payroll_payable_account",
"fieldtype": "Link",
"label": "Payroll Payable Account",
"options": "Account",
@@ -290,7 +290,7 @@
"icon": "fa fa-cog",
"is_submittable": 1,
"links": [],
"modified": "2020-10-22 01:57:27.226066",
"modified": "2020-10-23 13:00:33.753228",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Payroll Entry",

View File

@@ -59,7 +59,7 @@ class PayrollEntry(Document):
if sal_struct:
cond += "and t2.salary_structure IN %(sal_struct)s "
cond += "and t2.default_payroll_payable_account = %(default_payroll_payable_account)s "
cond += "and t2.payroll_payable_account = %(payroll_payable_account)s "
cond += "and %(from_date)s >= t2.from_date"
emp_list = frappe.db.sql("""
select
@@ -70,7 +70,7 @@ class PayrollEntry(Document):
t1.name = t2.employee
and t2.docstatus = 1
%s order by t2.from_date desc
""" % cond, {"sal_struct": tuple(sal_struct), "from_date": self.end_date, "default_payroll_payable_account": self.default_payroll_payable_account}, as_dict=True)
""" % cond, {"sal_struct": tuple(sal_struct), "from_date": self.end_date, "payroll_payable_account": self.payroll_payable_account}, as_dict=True)
return emp_list
def fill_employee_details(self):
@@ -163,10 +163,10 @@ class PayrollEntry(Document):
def get_salary_component_account(self, salary_component):
account = frappe.db.get_value("Salary Component Account",
{"parent": salary_component, "company": self.company}, "default_account")
{"parent": salary_component, "company": self.company}, "account")
if not account:
frappe.throw(_("Please set default account in Salary Component {0}")
frappe.throw(_("Please set account in Salary Component {0}")
.format(salary_component))
return account
@@ -210,7 +210,7 @@ class PayrollEntry(Document):
self.check_permission('write')
earnings = self.get_salary_component_total(component_type = "earnings") or {}
deductions = self.get_salary_component_total(component_type = "deductions") or {}
default_payroll_payable_account = self.default_payroll_payable_account
payroll_payable_account = self.payroll_payable_account
jv_name = ""
precision = frappe.get_precision("Journal Entry Account", "debit_in_account_currency")
@@ -255,9 +255,9 @@ class PayrollEntry(Document):
})
# Payable amount
exchange_rate, conversion_rate = self.get_exchange_rate(default_payroll_payable_account, company_currency, currencies)
exchange_rate, conversion_rate = self.get_exchange_rate(payroll_payable_account, company_currency, currencies)
accounts.append({
"account": default_payroll_payable_account,
"account": payroll_payable_account,
"credit_in_account_currency": flt((payable_amount * conversion_rate), precision),
"exchange_rate": flt(exchange_rate),
"party_type": '',
@@ -268,7 +268,7 @@ class PayrollEntry(Document):
if len(currencies) > 1:
multi_currency = 1
journal_entry.multi_currency = multi_currency
journal_entry.title = default_payroll_payable_account
journal_entry.title = payroll_payable_account
journal_entry.save()
try:
@@ -319,7 +319,7 @@ class PayrollEntry(Document):
self.create_journal_entry(salary_slip_total, "salary")
def create_journal_entry(self, je_payment_amount, user_remark):
default_payroll_payable_account = self.default_payroll_payable_account
payroll_payable_account = self.payroll_payable_account
precision = frappe.get_precision("Journal Entry Account", "debit_in_account_currency")
accounts = []
@@ -335,9 +335,9 @@ class PayrollEntry(Document):
"exchange_rate": flt(exchange_rate),
})
exchange_rate, conversion_rate = self.get_exchange_rate(default_payroll_payable_account, company_currency, currencies)
exchange_rate, conversion_rate = self.get_exchange_rate(payroll_payable_account, company_currency, currencies)
accounts.append({
"account": default_payroll_payable_account,
"account": payroll_payable_account,
"debit_in_account_currency": flt(je_payment_amount * conversion_rate, precision),
"exchange_rate": flt(exchange_rate),
"reference_type": self.doctype,

View File

@@ -4,9 +4,11 @@ from __future__ import unicode_literals
import unittest
import erpnext
import frappe
import random
from dateutil.relativedelta import relativedelta
from erpnext.accounts.utils import get_fiscal_year, getdate, nowdate
from frappe.utils import add_months
from frappe.utils.make_random import get_random
from erpnext.payroll.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.payroll.doctype.salary_slip.test_salary_slip import get_salary_component_account, \
@@ -34,10 +36,30 @@ class TestPayrollEntry(unittest.TestCase):
get_salary_component_account(data.name)
employee = frappe.db.get_value("Employee", {'company': company})
make_salary_structure("_Test Salary Structure", "Monthly", employee, company=company)
company_doc = frappe.get_doc('Company', company)
make_salary_structure("_Test Salary Structure", "Monthly", employee, company=company, currency=company_doc.default_currency)
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)
make_payroll_entry(start_date=dates.start_date, end_date=dates.end_date, payable_account=company_doc.default_payroll_payable_account,
currency=company_doc.default_currency)
def test_multi_currency_payroll_entry(self): # pylint: disable=no-self-use
company = erpnext.get_default_company()
for data in frappe.get_all('Salary Component', fields = ["name"]):
if not frappe.db.get_value('Salary Component Account',
{'parent': data.name, 'company': company}, 'name'):
get_salary_component_account(data.name)
employee = frappe.db.get_value("Employee", {'company': company})
company_doc = frappe.get_doc('Company', company)
currency = frappe.db.get_value("Currency", {'currency_name': ('not in',[company_doc.default_currency]), 'enabled': 1}, 'currency_name')
exchange_rate = random.random()*100
make_salary_structure("_Test Multi Currency Salary Structure", "Monthly", employee, company=company, currency=currency)
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, payable_account=company_doc.default_payroll_payable_account,
currency=currency, exchange_rate=exchange_rate)
def test_payroll_entry_with_employee_cost_center(self): # pylint: disable=no-self-use
for data in frappe.get_all('Salary Component', fields = ["name"]):
@@ -56,9 +78,9 @@ class TestPayrollEntry(unittest.TestCase):
department="cc - _TC", company="_Test Company")
employee2 = make_employee("test_employee2@example.com", payroll_cost_center="_Test Cost Center 2 - _TC",
department="cc - _TC", company="_Test Company")
make_salary_structure("_Test Salary Structure 1", "Monthly", employee1, company="_Test Company")
make_salary_structure("_Test Salary Structure 2", "Monthly", employee2, company="_Test Company")
company_doc = frappe.get_doc('Company', '_Test Company')
make_salary_structure("_Test Salary Structure 1", "Monthly", employee1, company="_Test Company", currency=company_doc.default_currency)
make_salary_structure("_Test Salary Structure 2", "Monthly", employee2, company="_Test Company", currency=company_doc.default_currency)
if not frappe.db.exists("Account", "_Test Payroll Payable - _TC"):
create_account(account_name="_Test Payroll Payable",
@@ -68,8 +90,8 @@ class TestPayrollEntry(unittest.TestCase):
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}):
pe = make_payroll_entry(start_date=dates.start_date, end_date=dates.end_date,
department="cc - _TC", company="_Test Company", payment_account="Cash - _TC", cost_center="Main - _TC")
pe = make_payroll_entry(start_date=dates.start_date, end_date=dates.end_date, payable_account=company_doc.default_payroll_payable_account,
currency=company_doc.default_currency, department="cc - _TC", company="_Test Company", payment_account="Cash - _TC", cost_center="Main - _TC")
je = frappe.db.get_value("Salary Slip", {"payroll_entry": pe.name}, "journal_entry")
je_entries = frappe.db.sql("""
select account, cost_center, debit, credit
@@ -121,7 +143,7 @@ class TestPayrollEntry(unittest.TestCase):
employee_doc.save()
salary_structure = "Test Salary Structure for Loan"
make_salary_structure(salary_structure, "Monthly", employee=employee_doc.name, company="_Test Company")
make_salary_structure(salary_structure, "Monthly", employee=employee_doc.name, company="_Test Company", currency=company_doc.default_currency)
loan = create_loan(applicant, "Car Loan", 280000, "Repay Over Number of Periods", 20, posting_date=add_months(nowdate(), -1))
loan.repay_from_salary = 1
@@ -133,8 +155,8 @@ class TestPayrollEntry(unittest.TestCase):
dates = get_start_end_dates('Monthly', nowdate())
make_payroll_entry(company="_Test Company", start_date=dates.start_date,
end_date=dates.end_date, branch=branch, cost_center="Main - _TC", payment_account="Cash - _TC")
make_payroll_entry(company="_Test Company", start_date=dates.start_date, payable_account=company_doc.default_payroll_payable_account,
currency=company_doc.default_currency, end_date=dates.end_date, branch=branch, cost_center="Main - _TC", payment_account="Cash - _TC")
name = frappe.db.get_value('Salary Slip',
{'posting_date': nowdate(), 'employee': applicant}, 'name')
@@ -165,6 +187,9 @@ def make_payroll_entry(**args):
payroll_entry.payroll_frequency = "Monthly"
payroll_entry.branch = args.branch or None
payroll_entry.department = args.department or None
payroll_entry.payroll_payable_account = args.payable_account
payroll_entry.currency = args.currency
payroll_entry.exchange_rate = args.exchange_rate or 1
if args.cost_center:
payroll_entry.cost_center = args.cost_center

View File

@@ -9,45 +9,45 @@ QUnit.test("test: Set Salary Components", function (assert) {
() => {
var row = frappe.model.add_child(cur_frm.doc, "Salary Component Account", "accounts");
row.company = 'For Testing';
row.default_account = 'Salary - FT';
row.account = 'Salary - FT';
},
() => cur_frm.save(),
() => frappe.timeout(2),
() => assert.equal(cur_frm.doc.accounts[0].default_account, 'Salary - FT'),
() => assert.equal(cur_frm.doc.accounts[0].account, 'Salary - FT'),
() => frappe.set_route('Form', 'Salary Component', 'Basic'),
() => {
var row = frappe.model.add_child(cur_frm.doc, "Salary Component Account", "accounts");
row.company = 'For Testing';
row.default_account = 'Salary - FT';
row.account = 'Salary - FT';
},
() => cur_frm.save(),
() => frappe.timeout(2),
() => assert.equal(cur_frm.doc.accounts[0].default_account, 'Salary - FT'),
() => assert.equal(cur_frm.doc.accounts[0].account, 'Salary - FT'),
() => frappe.set_route('Form', 'Salary Component', 'Income Tax'),
() => {
var row = frappe.model.add_child(cur_frm.doc, "Salary Component Account", "accounts");
row.company = 'For Testing';
row.default_account = 'Salary - FT';
row.account = 'Salary - FT';
},
() => cur_frm.save(),
() => frappe.timeout(2),
() => assert.equal(cur_frm.doc.accounts[0].default_account, 'Salary - FT'),
() => assert.equal(cur_frm.doc.accounts[0].account, 'Salary - FT'),
() => frappe.set_route('Form', 'Salary Component', 'Arrear'),
() => {
var row = frappe.model.add_child(cur_frm.doc, "Salary Component Account", "accounts");
row.company = 'For Testing';
row.default_account = 'Salary - FT';
row.account = 'Salary - FT';
},
() => cur_frm.save(),
() => frappe.timeout(2),
() => assert.equal(cur_frm.doc.accounts[0].default_account, 'Salary - FT'),
() => assert.equal(cur_frm.doc.accounts[0].account, 'Salary - FT'),
() => frappe.set_route('Form', 'Company', 'For Testing'),
() => cur_frm.set_value('default_payroll_payable_account', 'Payroll Payable - FT'),

View File

@@ -3,7 +3,7 @@
frappe.ui.form.on('Salary Component', {
setup: function(frm) {
frm.set_query("default_account", "accounts", function(doc, cdt, cdn) {
frm.set_query("account", "accounts", function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
return {
filters: {

View File

@@ -31,7 +31,7 @@ class TestSalarySlip(unittest.TestCase):
frappe.db.set_value("Payroll Settings", None, "payroll_based_on", "Attendance")
frappe.db.set_value("Payroll Settings", None, "daily_wages_fraction_for_half_day", 0.75)
emp_id = make_employee("test_for_attendance@salary.com")
emp_id = make_employee("test_payment_days_based_on_attendance@salary.com")
frappe.db.set_value("Employee", emp_id, {"relieving_date": None, "status": "Active"})
frappe.db.set_value("Leave Type", "Leave Without Pay", "include_holiday", 0)
@@ -53,7 +53,7 @@ class TestSalarySlip(unittest.TestCase):
mark_attendance(emp_id, add_days(first_sunday, 4), 'On Leave', leave_type='Casual Leave', ignore_validate=True) # invalid lwp
mark_attendance(emp_id, add_days(first_sunday, 7), 'On Leave', leave_type='Leave Without Pay', ignore_validate=True) # invalid lwp
ss = make_employee_salary_slip("test_for_attendance@salary.com", "Monthly")
ss = make_employee_salary_slip("test_payment_days_based_on_attendance@salary.com", "Monthly", "Test Payment Based On Attendence")
self.assertEqual(ss.leave_without_pay, 1.25)
self.assertEqual(ss.absent_days, 1)
@@ -76,7 +76,7 @@ class TestSalarySlip(unittest.TestCase):
# Payroll based on attendance
frappe.db.set_value("Payroll Settings", None, "payroll_based_on", "Leave")
emp_id = make_employee("test_for_attendance@salary.com")
emp_id = make_employee("test_payment_days_based_on_leave_application@salary.com")
frappe.db.set_value("Employee", emp_id, {"relieving_date": None, "status": "Active"})
frappe.db.set_value("Leave Type", "Leave Without Pay", "include_holiday", 0)
@@ -93,7 +93,7 @@ class TestSalarySlip(unittest.TestCase):
make_leave_application(emp_id, first_sunday, add_days(first_sunday, 3), "Leave Without Pay")
ss = make_employee_salary_slip("test_for_attendance@salary.com", "Monthly")
ss = make_employee_salary_slip("test_payment_days_based_on_leave_application@salary.com", "Monthly", "Test Payment Based On Leave Application")
self.assertEqual(ss.leave_without_pay, 3)
@@ -112,12 +112,12 @@ class TestSalarySlip(unittest.TestCase):
def test_salary_slip_with_holidays_included(self):
no_of_days = self.get_no_of_days()
frappe.db.set_value("Payroll Settings", None, "include_holidays_in_total_working_days", 1)
make_employee("test_employee@salary.com")
make_employee("test_salary_slip_with_holidays_included@salary.com")
frappe.db.set_value("Employee", frappe.get_value("Employee",
{"employee_name":"test_employee@salary.com"}, "name"), "relieving_date", None)
{"employee_name":"test_salary_slip_with_holidays_included@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 = make_employee_salary_slip("test_employee@salary.com", "Monthly")
{"employee_name":"test_salary_slip_with_holidays_included@salary.com"}, "name"), "status", "Active")
ss = make_employee_salary_slip("test_salary_slip_with_holidays_included@salary.com", "Monthly", "Test Salary Slip With Holidays Included")
self.assertEqual(ss.total_working_days, no_of_days[0])
self.assertEqual(ss.payment_days, no_of_days[0])
@@ -128,12 +128,12 @@ class TestSalarySlip(unittest.TestCase):
def test_salary_slip_with_holidays_excluded(self):
no_of_days = self.get_no_of_days()
frappe.db.set_value("Payroll Settings", None, "include_holidays_in_total_working_days", 0)
make_employee("test_employee@salary.com")
make_employee("test_salary_slip_with_holidays_excluded@salary.com")
frappe.db.set_value("Employee", frappe.get_value("Employee",
{"employee_name":"test_employee@salary.com"}, "name"), "relieving_date", None)
{"employee_name":"test_salary_slip_with_holidays_excluded@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 = make_employee_salary_slip("test_employee@salary.com", "Monthly")
{"employee_name":"test_salary_slip_with_holidays_excluded@salary.com"}, "name"), "status", "Active")
ss = make_employee_salary_slip("test_salary_slip_with_holidays_excluded@salary.com", "Monthly", "Test Salary Slip With Holidays Excluded")
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])
@@ -148,7 +148,7 @@ class TestSalarySlip(unittest.TestCase):
frappe.db.set_value("Payroll Settings", None, "include_holidays_in_total_working_days", 1)
# set joinng date in the same month
make_employee("test_employee@salary.com")
make_employee("test_payment_days@salary.com")
if getdate(nowdate()).day >= 15:
relieving_date = getdate(add_days(nowdate(),-10))
date_of_joining = getdate(add_days(nowdate(),-10))
@@ -163,39 +163,39 @@ class TestSalarySlip(unittest.TestCase):
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)
{"employee_name":"test_payment_days@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)
{"employee_name":"test_payment_days@salary.com"}, "name"), "relieving_date", None)
frappe.db.set_value("Employee", frappe.get_value("Employee",
{"employee_name":"test_employee@salary.com"}, "name"), "status", "Active")
{"employee_name":"test_payment_days@salary.com"}, "name"), "status", "Active")
ss = make_employee_salary_slip("test_employee@salary.com", "Monthly")
ss = make_employee_salary_slip("test_payment_days@salary.com", "Monthly", "Test Payment Days")
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))
# set relieving date in the same month
frappe.db.set_value("Employee",frappe.get_value("Employee",
{"employee_name":"test_employee@salary.com"}, "name"), "date_of_joining", (add_days(nowdate(),-60)))
{"employee_name":"test_payment_days@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)
{"employee_name":"test_payment_days@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")
{"employee_name":"test_payment_days@salary.com"}, "name"), "status", "Left")
ss.save()
self.assertEqual(ss.total_working_days, no_of_days[0])
self.assertEqual(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)
{"employee_name":"test_payment_days@salary.com"}, "name"), "relieving_date", None)
frappe.db.set_value("Employee", frappe.get_value("Employee",
{"employee_name":"test_employee@salary.com"}, "name"), "status", "Active")
{"employee_name":"test_payment_days@salary.com"}, "name"), "status", "Active")
def test_employee_salary_slip_read_permission(self):
make_employee("test_employee@salary.com")
make_employee("test_employee_salary_slip_read_permission@salary.com")
salary_slip_test_employee = make_employee_salary_slip("test_employee@salary.com", "Monthly")
frappe.set_user("test_employee@salary.com")
salary_slip_test_employee = make_employee_salary_slip("test_employee_salary_slip_read_permission@salary.com", "Monthly", "Test Employee Salary Slip Read Permission")
frappe.set_user("test_employee_salary_slip_read_permission@salary.com")
self.assertTrue(salary_slip_test_employee.has_permission("read"))
def test_email_salary_slip(self):
@@ -203,8 +203,8 @@ class TestSalarySlip(unittest.TestCase):
frappe.db.set_value("Payroll Settings", None, "email_salary_slip_to_employee", 1)
make_employee("test_employee@salary.com")
ss = make_employee_salary_slip("test_employee@salary.com", "Monthly")
make_employee("test_email_salary_slip@salary.com")
ss = make_employee_salary_slip("test_email_salary_slip@salary.com", "Monthly", "Test Salary Slip Email")
ss.company = "_Test Company"
ss.save()
ss.submit()
@@ -215,8 +215,9 @@ class TestSalarySlip(unittest.TestCase):
def test_loan_repayment_salary_slip(self):
from erpnext.loan_management.doctype.loan.test_loan import create_loan_type, create_loan, make_loan_disbursement_entry, create_loan_accounts
from erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import process_loan_interest_accrual_for_term_loans
from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure
applicant = make_employee("test_loanemployee@salary.com", company="_Test Company")
applicant = make_employee("test_loan_repayment_salary_slip@salary.com", company="_Test Company")
create_loan_accounts()
@@ -228,6 +229,7 @@ class TestSalarySlip(unittest.TestCase):
interest_income_account='Interest Income Account - _TC',
penalty_income_account='Penalty Income Account - _TC')
make_salary_structure("Test Loan Repayment Salary Structure", "Monthly", employee=applicant, currency='INR')
loan = create_loan(applicant, "Car Loan", 11000, "Repay Over Number of Periods", 20, posting_date=add_months(nowdate(), -1))
loan.repay_from_salary = 1
loan.submit()
@@ -236,7 +238,7 @@ class TestSalarySlip(unittest.TestCase):
process_loan_interest_accrual_for_term_loans(posting_date=nowdate())
ss = make_employee_salary_slip("test_loanemployee@salary.com", "Monthly")
ss = make_employee_salary_slip("test_loan_repayment_salary_slip@salary.com", "Monthly", "Test Loan Repayment Salary Structure")
ss.submit()
self.assertEqual(ss.total_loan_repayment, 592)
@@ -249,7 +251,7 @@ class TestSalarySlip(unittest.TestCase):
for payroll_frequency in ["Monthly", "Bimonthly", "Fortnightly", "Weekly", "Daily"]:
make_employee(payroll_frequency + "_test_employee@salary.com")
ss = make_employee_salary_slip(payroll_frequency + "_test_employee@salary.com", payroll_frequency)
ss = make_employee_salary_slip(payroll_frequency + "_test_employee@salary.com", payroll_frequency, payroll_frequency + "_Test Payroll Frequency")
if payroll_frequency == "Monthly":
self.assertEqual(ss.end_date, m['month_end_date'])
elif payroll_frequency == "Bimonthly":
@@ -264,6 +266,19 @@ class TestSalarySlip(unittest.TestCase):
elif payroll_frequency == "Daily":
self.assertEqual(ss.end_date, nowdate())
def test_multi_currency_salary_slip(self):
from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure
applicant = make_employee("test_multi_currency_salary_slip@salary.com", company="_Test Company")
salary_structure = make_salary_structure("Test Multi Currency Salary Slip", "Monthly", employee=applicant, company="_Test Company", currency='USD')
salary_slip = make_salary_slip(salary_structure.name, employee = applicant)
salary_slip.exchange_rate = 70
salary_slip.calculate_net_pay()
# salary_slip.submit()
self.assertEqual(salary_slip.gross_pay, 78000)
self.assertEqual(salary_slip.base_gross_pay, 78000*70)
def test_tax_for_payroll_period(self):
data = {}
# test the impact of tax exemption declaration, tax exemption proof submission
@@ -384,7 +399,10 @@ def make_employee_salary_slip(user, payroll_frequency, salary_structure=None):
salary_structure = payroll_frequency + " Salary Structure Test for Salary Slip"
employee = frappe.db.get_value("Employee", {"user_id": user})
salary_structure_doc = make_salary_structure(salary_structure, payroll_frequency, employee)
if not frappe.db.exists('Salary Structure', salary_structure):
salary_structure_doc = make_salary_structure(salary_structure, payroll_frequency, employee)
else:
salary_structure_doc = frappe.get_doc('Salary Structure', salary_structure)
salary_slip = frappe.db.get_value("Salary Slip", {"employee": frappe.db.get_value("Employee", {"user_id": user})})
if not salary_slip:
@@ -434,7 +452,7 @@ def get_salary_component_account(sal_comp, company_list=None):
sal_comp.append("accounts", {
"company": d,
"default_account": create_account(account_name, d, parent_account)
"account": create_account(account_name, d, parent_account)
})
sal_comp.save()

View File

@@ -131,7 +131,7 @@ frappe.ui.form.on('Salary Structure', {
{fieldname:'department', fieldtype:'Link', options: 'Department', label: __('Department')},
{fieldname:'designation', fieldtype:'Link', options: 'Designation', label: __('Designation')},
{fieldname:"employee", fieldtype: "Link", options: "Employee", label: __("Employee")},
{fieldname:"default_payroll_payable_account", fieldtype: "Link", options: "Account", filters: {"company": frm.doc.company, "root_type": "Liability", "is_group": 0, "account_currency": frm.doc.currency}, label: __("Default Payroll Payable Account")},
{fieldname:"payroll_payable_account", fieldtype: "Link", options: "Account", filters: {"company": frm.doc.company, "root_type": "Liability", "is_group": 0, "account_currency": frm.doc.currency}, label: __("Payroll Payable Account")},
{fieldname:'base_variable', fieldtype:'Section Break'},
{fieldname:'from_date', fieldtype:'Date', label: __('From Date'), "reqd": 1},
{fieldname:'income_tax_slab', fieldtype:'Link', label: __('Income Tax Slab'), options: 'Income Tax Slab'},

View File

@@ -89,25 +89,25 @@ class SalaryStructure(Document):
@frappe.whitelist()
def assign_salary_structure(self, grade=None, department=None, designation=None,employee=None,
default_payroll_payable_account=None, from_date=None, base=None, variable=None, income_tax_slab=None):
payroll_payable_account=None, from_date=None, base=None, variable=None, income_tax_slab=None):
employees = self.get_employees(company= self.company, grade= grade,department= department,designation= designation,name=employee)
if employees:
if len(employees) > 20:
frappe.enqueue(assign_salary_structure_for_employees, timeout=600,
employees=employees, salary_structure=self,
default_payroll_payable_account=default_payroll_payable_account,
payroll_payable_account=payroll_payable_account,
from_date=from_date, base=base, variable=variable, income_tax_slab=income_tax_slab)
else:
assign_salary_structure_for_employees(employees, self,
default_payroll_payable_account=default_payroll_payable_account,
payroll_payable_account=payroll_payable_account,
from_date=from_date, base=base, variable=variable, income_tax_slab=income_tax_slab)
else:
frappe.msgprint(_("No Employee Found"))
def assign_salary_structure_for_employees(employees, salary_structure, default_payroll_payable_account=None, from_date=None, base=None, variable=None, income_tax_slab=None):
def assign_salary_structure_for_employees(employees, salary_structure, payroll_payable_account=None, from_date=None, base=None, variable=None, income_tax_slab=None):
salary_structures_assignments = []
existing_assignments_for = get_existing_assignments(employees, salary_structure, from_date)
count=0
@@ -117,7 +117,7 @@ def assign_salary_structure_for_employees(employees, salary_structure, default_p
count +=1
salary_structures_assignment = create_salary_structures_assignment(employee,
salary_structure, default_payroll_payable_account, from_date, base, variable, income_tax_slab)
salary_structure, payroll_payable_account, from_date, base, variable, income_tax_slab)
salary_structures_assignments.append(salary_structures_assignment)
frappe.publish_progress(count*100/len(set(employees) - set(existing_assignments_for)), title = _("Assigning Structures..."))
@@ -125,21 +125,21 @@ def assign_salary_structure_for_employees(employees, salary_structure, default_p
frappe.msgprint(_("Structures have been assigned successfully"))
def create_salary_structures_assignment(employee, salary_structure, default_payroll_payable_account, from_date, base, variable, income_tax_slab=None):
if not default_payroll_payable_account:
default_payroll_payable_account = frappe.db.get_value('Company', salary_structure.company, 'default_payroll_payable_account')
if not default_payroll_payable_account:
def create_salary_structures_assignment(employee, salary_structure, payroll_payable_account, from_date, base, variable, income_tax_slab=None):
if not payroll_payable_account:
payroll_payable_account = frappe.db.get_value('Company', salary_structure.company, 'payroll_payable_account')
if not payroll_payable_account:
frappe.throw(_('Please set "Default Payroll Payable Account" in Company Defaults'))
account_currency = frappe.db.get_value('Account', default_payroll_payable_account, 'account_currency')
account_currency = frappe.db.get_value('Account', payroll_payable_account, 'account_currency')
if account_currency != salary_structure.currency:
frappe.throw(_("Account currency of Account: {0} is different than what is specified in salary structure: {1}").format(default_payroll_payable_account, salary_structure))
frappe.throw(_("Account currency of Account: {0} is different than what is specified in salary structure: {1}").format(payroll_payable_account, salary_structure))
assignment = frappe.new_doc("Salary Structure Assignment")
assignment.employee = employee
assignment.salary_structure = salary_structure.name
assignment.company = salary_structure.company
assignment.currency = salary_structure.currency
assignment.default_payroll_payable_account = default_payroll_payable_account
assignment.payroll_payable_account = payroll_payable_account
assignment.from_date = from_date
assignment.base = base
assignment.variable = variable

View File

@@ -94,7 +94,8 @@ class TestSalaryStructure(unittest.TestCase):
self.assertFalse(("\n" in row.formula) or ("\n" in row.condition))
def test_salary_structures_assignment(self):
salary_structure = make_salary_structure("Salary Structure Sample", "Monthly")
company_currency = erpnext.get_default_currency()
salary_structure = make_salary_structure("Salary Structure Sample", "Monthly", currency=company_currency)
employee = "test_assign_stucture@salary.com"
employee_doc_name = make_employee(employee)
# clear the already assigned stuctures
@@ -107,8 +108,13 @@ class TestSalaryStructure(unittest.TestCase):
self.assertEqual(salary_structure_assignment.base, 5000)
self.assertEqual(salary_structure_assignment.variable, 200)
def test_multi_currency_salary_structure(self):
emp = make_employee("test_muti_currency_employee@salary.com")
sal_struct = make_salary_structure("Salary Structure Multi Currency", "Monthly", currency='USD')
self.assertEqual(sal_struct.currency, 'USD')
def make_salary_structure(salary_structure, payroll_frequency, employee=None, dont_submit=False, other_details=None,
test_tax=False, company=None):
test_tax=False, company=None, currency=erpnext.get_default_currency()):
if test_tax:
frappe.db.sql("""delete from `tabSalary Structure` where name=%s""",(salary_structure))
@@ -120,7 +126,8 @@ def make_salary_structure(salary_structure, payroll_frequency, employee=None, do
"earnings": make_earning_salary_component(test_tax=test_tax, company_list=["_Test Company"]),
"deductions": make_deduction_salary_component(test_tax=test_tax, company_list=["_Test Company"]),
"payroll_frequency": payroll_frequency,
"payment_account": get_random("Account")
"payment_account": get_random("Account", filters={'account_currency': currency}),
"currency": currency
}
if other_details and isinstance(other_details, dict):
details.update(other_details)
@@ -134,11 +141,11 @@ def make_salary_structure(salary_structure, payroll_frequency, employee=None, do
if employee and not frappe.db.get_value("Salary Structure Assignment",
{'employee':employee, 'docstatus': 1}) and salary_structure_doc.docstatus==1:
create_salary_structure_assignment(employee, salary_structure, company=company)
create_salary_structure_assignment(employee, salary_structure, company=company, currency=currency)
return salary_structure_doc
def create_salary_structure_assignment(employee, salary_structure, from_date=None, company=None):
def create_salary_structure_assignment(employee, salary_structure, from_date=None, company=None, currency=erpnext.get_default_currency()):
if frappe.db.exists("Salary Structure Assignment", {"employee": employee}):
frappe.db.sql("""delete from `tabSalary Structure Assignment` where employee=%s""",(employee))
@@ -151,8 +158,15 @@ def create_salary_structure_assignment(employee, salary_structure, from_date=Non
salary_structure_assignment.variable = 5000
salary_structure_assignment.from_date = from_date or add_days(nowdate(), -1)
salary_structure_assignment.salary_structure = salary_structure
salary_structure_assignment.currency = currency
salary_structure_assignment.payroll_payable_account = get_payable_account(company)
salary_structure_assignment.company = company or erpnext.get_default_company()
salary_structure_assignment.save(ignore_permissions=True)
salary_structure_assignment.income_tax_slab = "Tax Slab: _Test Payroll Period"
salary_structure_assignment.submit()
return salary_structure_assignment
def get_payable_account(company=None):
if not company:
company = erpnext.get_default_company()
return frappe.db.get_value("Company", company, "default_payroll_payable_account")

View File

@@ -29,7 +29,7 @@ frappe.ui.form.on('Salary Structure Assignment', {
};
});
frm.set_query("default_payroll_payable_account", function() {
frm.set_query("payroll_payable_account", function() {
var company_currency = erpnext.get_currency(frm.doc.company);
return {
filters: {

View File

@@ -11,7 +11,7 @@
"employee_name",
"department",
"company",
"default_payroll_payable_account",
"payroll_payable_account",
"column_break_6",
"designation",
"salary_structure",
@@ -123,13 +123,6 @@
"label": "Income Tax Slab",
"options": "Income Tax Slab"
},
{
"depends_on": "salary_structure",
"fieldname": "default_payroll_payable_account",
"fieldtype": "Link",
"label": "Payroll Payable Account",
"options": "Account"
},
{
"default": "Company:company:default_currency",
"depends_on": "eval:(doc.docstatus==1 || doc.salary_structure)",
@@ -141,11 +134,18 @@
"print_hide": 1,
"read_only": 1,
"reqd": 1
},
{
"depends_on": "salary_structure",
"fieldname": "payroll_payable_account",
"fieldtype": "Link",
"label": "Payroll Payable Account",
"options": "Account"
}
],
"is_submittable": 1,
"links": [],
"modified": "2020-10-21 22:43:55.208492",
"modified": "2020-10-23 13:20:29.906934",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Salary Structure Assignment",