fix(test): Fixed salary slip and sales analytics test cases

This commit is contained in:
Nabin Hait 2018-11-23 16:15:32 +05:30 committed by Nabin Hait
parent 2508d11097
commit 48e0e19b03
4 changed files with 80 additions and 123 deletions

View File

@ -36,10 +36,13 @@ class EmployeeBenefitClaim(Document):
frappe.throw(_("Maximum benefit amount of employee {0} exceeds {1}").format(self.employee, max_benefits))
def validate_max_benefit_for_component(self, payroll_period):
claimed_amount = self.claimed_amount
claimed_amount += get_previous_claimed_amount(self.employee, payroll_period, component = self.earning_component)
if claimed_amount > self.max_amount_eligible:
frappe.throw(_("Maximum amount eligible for the component {0} exceeds {1}").format(self.earning_component, self.max_amount_eligible))
if self.max_amount_eligible:
claimed_amount = self.claimed_amount
claimed_amount += get_previous_claimed_amount(self.employee,
payroll_period, component = self.earning_component)
if claimed_amount > self.max_amount_eligible:
frappe.throw(_("Maximum amount eligible for the component {0} exceeds {1}")
.format(self.earning_component, self.max_amount_eligible))
def validate_non_pro_rata_benefit_claim(self, max_benefits, payroll_period):
claimed_amount = self.claimed_amount

View File

@ -14,7 +14,7 @@ frappe.ui.form.on("Job Offer", {
refresh: function (frm) {
if ((!frm.doc.__islocal) && (frm.doc.status == 'Accepted')
&& (frm.doc.docstatus === 1) && (!frm.doc.__onload.employee)) {
&& (frm.doc.docstatus === 1) && (!frm.doc.__onload || !frm.doc.__onload.employee)) {
frm.add_custom_button(__('Make Employee'),
function () {
erpnext.job_offer.make_employee(frm);
@ -22,7 +22,7 @@ frappe.ui.form.on("Job Offer", {
);
}
if(frm.doc.__onload.employee) {
if(frm.doc.__onload && frm.doc.__onload.employee) {
frm.add_custom_button(__('Show Employee'),
function () {
frappe.set_route("Form", "Employee", frm.doc.__onload.employee);

View File

@ -26,6 +26,7 @@ class TestSalarySlip(unittest.TestCase):
self.make_holiday_list()
frappe.db.set_value("Company", erpnext.get_default_company(), "default_holiday_list", "Salary Slip Test Holiday List")
frappe.db.set_value("HR Settings", None, "email_salary_slip_to_employee", 0)
def tearDown(self):
frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 0)

View File

@ -8,10 +8,17 @@ from erpnext.selling.report.sales_analytics.sales_analytics import execute
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
class TestAnalytics(unittest.TestCase):
def test_sales_analytics(self):
frappe.db.sql("delete from `tabSales Order` where company='_Test Company 2'")
def test_by_entity(self):
create_sales_order()
create_sales_orders()
self.compare_result_for_customer()
self.compare_result_for_customer_group()
self.compare_result_for_customer_based_on_quantity()
def compare_result_for_customer(self):
filters = {
'doc_type': 'Sales Order',
'range': 'Monthly',
@ -42,23 +49,6 @@ class TestAnalytics(unittest.TestCase):
"mar": 0.0,
"total":2000.0
},
{
"entity": "_Test Customer 3",
"entity_name": "_Test Customer 3",
"apr": 0.0,
"may": 0.0,
"jun": 2000.0,
"jul": 1000.0,
"aug": 0.0,
"sep": 0.0,
"oct": 0.0,
"nov": 0.0,
"dec": 0.0,
"jan": 0.0,
"feb": 0.0,
"mar": 0.0,
"total": 3000.0
},
{
"entity": "_Test Customer 2",
"entity_name": "_Test Customer 2",
@ -75,12 +65,29 @@ class TestAnalytics(unittest.TestCase):
"feb": 0.0,
"mar": 0.0,
"total":2500.0
},
{
"entity": "_Test Customer 3",
"entity_name": "_Test Customer 3",
"apr": 0.0,
"may": 0.0,
"jun": 2000.0,
"jul": 1000.0,
"aug": 0.0,
"sep": 0.0,
"oct": 0.0,
"nov": 0.0,
"dec": 0.0,
"jan": 0.0,
"feb": 0.0,
"mar": 0.0,
"total": 3000.0
}
]
self.assertEqual(expected_data, report[1])
result = sorted(report[1], key=lambda k: k['entity'])
self.assertEqual(expected_data, result)
def test_by_group(self):
def compare_result_for_customer_group(self):
filters = {
'doc_type': 'Sales Order',
'range': 'Monthly',
@ -93,80 +100,26 @@ class TestAnalytics(unittest.TestCase):
report = execute(filters)
expected_data = [
{
"entity": "All Customer Groups",
"indent": 0,
"apr": 0.0,
"may": 0.0,
"jun": 2000.0,
"jul": 1000.0,
"aug": 0.0,
"sep": 1500.0,
"oct": 1000.0,
"nov": 0.0,
"dec": 0.0,
"jan": 0.0,
"feb": 2000.0,
"mar": 0.0,
"total":7500.0
},
{
"entity": "Individual",
"indent": 1,
"apr": 0.0,
"may": 0.0,
"jun": 0.0,
"jul": 0.0,
"aug": 0.0,
"sep": 0.0,
"oct": 0.0,
"nov": 0.0,
"dec": 0.0,
"jan": 0.0,
"feb": 0.0,
"mar": 0.0,
"total": 0.0
},
{
"entity": "_Test Customer Group",
"indent": 1,
"apr": 0.0,
"may": 0.0,
"jun": 0.0,
"jul": 0.0,
"aug": 0.0,
"sep": 0.0,
"oct": 0.0,
"nov": 0.0,
"dec": 0.0,
"jan": 0.0,
"feb": 0.0,
"mar": 0.0,
"total":0.0
},
{
"entity": "_Test Customer Group 1",
"indent": 1,
"apr": 0.0,
"may": 0.0,
"jun": 0.0,
"jul": 0.0,
"aug": 0.0,
"sep": 0.0,
"oct": 0.0,
"nov": 0.0,
"dec": 0.0,
"jan": 0.0,
"feb": 0.0,
"mar": 0.0,
"total":0.0
}
]
self.assertEqual(expected_data, report[1])
def test_by_quantity(self):
expected_first_row = {
"entity": "All Customer Groups",
"indent": 0,
"apr": 0.0,
"may": 0.0,
"jun": 2000.0,
"jul": 1000.0,
"aug": 0.0,
"sep": 1500.0,
"oct": 1000.0,
"nov": 0.0,
"dec": 0.0,
"jan": 0.0,
"feb": 2000.0,
"mar": 0.0,
"total":7500.0
}
self.assertEqual(expected_first_row, report[1][0])
def compare_result_for_customer_based_on_quantity(self):
filters = {
'doc_type': 'Sales Order',
'range': 'Monthly',
@ -197,23 +150,6 @@ class TestAnalytics(unittest.TestCase):
"mar": 0.0,
"total":20.0
},
{
"entity": "_Test Customer 3",
"entity_name": "_Test Customer 3",
"apr": 0.0,
"may": 0.0,
"jun": 20.0,
"jul": 10.0,
"aug": 0.0,
"sep": 0.0,
"oct": 0.0,
"nov": 0.0,
"dec": 0.0,
"jan": 0.0,
"feb": 0.0,
"mar": 0.0,
"total": 30.0
},
{
"entity": "_Test Customer 2",
"entity_name": "_Test Customer 2",
@ -230,11 +166,29 @@ class TestAnalytics(unittest.TestCase):
"feb": 0.0,
"mar": 0.0,
"total":25.0
},
{
"entity": "_Test Customer 3",
"entity_name": "_Test Customer 3",
"apr": 0.0,
"may": 0.0,
"jun": 20.0,
"jul": 10.0,
"aug": 0.0,
"sep": 0.0,
"oct": 0.0,
"nov": 0.0,
"dec": 0.0,
"jan": 0.0,
"feb": 0.0,
"mar": 0.0,
"total": 30.0
}
]
self.assertEqual(expected_data, report[1])
result = sorted(report[1], key=lambda k: k['entity'])
self.assertEqual(expected_data, result)
def create_sales_order():
def create_sales_orders():
frappe.set_user("Administrator")
make_sales_order(company="_Test Company 2", qty=10,
@ -260,16 +214,15 @@ def create_sales_order():
transaction_date='2017-09-23',
warehouse='Finished Goods - _TC2',
currency = 'EUR')
make_sales_order(company="_Test Company 2",
qty=20, customer = "_Test Customer 3",
transaction_date='2017-06-15',
warehouse='Finished Goods - _TC2',
currency = 'EUR')
make_sales_order(company="_Test Company 2",
qty=10, customer = "_Test Customer 3",
transaction_date='2017-07-10',
warehouse='Finished Goods - _TC2',
currency = 'EUR')