* Fix Purchase Receipt tests

* Fix Item test

* Fix daily work summary test

* Modify currency exchange test cases

* Fix Leave Application test

* Update working hours when making salary slip from timesheet

* Replace fixer.io with exchangeratesapi

* Fix codacy
This commit is contained in:
Shreya Shah
2018-06-05 12:56:10 +05:30
committed by Nabin Hait
parent 81d12cc9c8
commit 630721aacc
11 changed files with 35 additions and 22 deletions

View File

@@ -43,7 +43,6 @@ class TestTaxRule(unittest.TestCase):
tax_rule1 = make_tax_rule(customer_group= "All Customer Groups", tax_rule1 = make_tax_rule(customer_group= "All Customer Groups",
sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority = 1, from_date = "2015-01-01") sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority = 1, from_date = "2015-01-01")
tax_rule1.save() tax_rule1.save()
self.assertEqual(get_tax_template("2015-01-01", {"customer_group" : "Commercial", "use_for_shopping_cart":0}), self.assertEqual(get_tax_template("2015-01-01", {"customer_group" : "Commercial", "use_for_shopping_cart":0}),
"_Test Sales Taxes and Charges Template - _TC") "_Test Sales Taxes and Charges Template - _TC")

View File

@@ -15,6 +15,7 @@ class TestDailyWorkSummary(unittest.TestCase):
self.setup_and_prepare_test() self.setup_and_prepare_test()
for d in self.users: for d in self.users:
# check that email is sent to users # check that email is sent to users
if d.message:
self.assertTrue(d.email in [d.recipient for d in self.emails self.assertTrue(d.email in [d.recipient for d in self.emails
if self.groups.subject in d.message]) if self.groups.subject in d.message])

View File

@@ -241,7 +241,6 @@ class TestLeaveApplication(unittest.TestCase):
employee = get_employee() employee = get_employee()
frappe.db.set_value('Leave Period', leave_period.name, 'optional_holiday_list', holiday_list.name) frappe.db.set_value('Leave Period', leave_period.name, 'optional_holiday_list', holiday_list.name)
leave_type = frappe.get_doc(dict( leave_type = frappe.get_doc(dict(
leave_type_name = 'Test Optional Type', leave_type_name = 'Test Optional Type',
doctype = 'Leave Type', doctype = 'Leave Type',
@@ -320,9 +319,8 @@ class TestLeaveApplication(unittest.TestCase):
doctype = 'Leave Type', doctype = 'Leave Type',
applicable_after = 15 applicable_after = 15
)).insert() )).insert()
date = add_days(nowdate(), -7) date = add_days(nowdate(), -7)
frappe.db.set_value('Employee', employee.name, "date_of_joining", date)
allocate_leaves(employee, leave_period, leave_type.name, 10) allocate_leaves(employee, leave_period, leave_type.name, 10)
leave_application = frappe.get_doc(dict( leave_application = frappe.get_doc(dict(
@@ -358,6 +356,7 @@ class TestLeaveApplication(unittest.TestCase):
)) ))
self.assertTrue(leave_application.insert()) self.assertTrue(leave_application.insert())
frappe.db.set_value('Employee', employee.name, "date_of_joining", "2010-01-01")
def test_max_continuous_leaves(self): def test_max_continuous_leaves(self):
employee = get_employee() employee = get_employee()

View File

@@ -6,7 +6,7 @@ from __future__ import unicode_literals
import frappe import frappe
import erpnext import erpnext
import unittest import unittest
from frappe.utils import nowdate from frappe.utils import nowdate, add_days
from erpnext.hr.doctype.salary_structure.test_salary_structure import make_employee from erpnext.hr.doctype.salary_structure.test_salary_structure import make_employee
class TestLoan(unittest.TestCase): class TestLoan(unittest.TestCase):
@@ -58,6 +58,8 @@ def create_loan(applicant, loan_type, loan_amount, repayment_method, repayment_p
"repayment_method": repayment_method, "repayment_method": repayment_method,
"repayment_periods": repayment_periods, "repayment_periods": repayment_periods,
"disbursement_date": nowdate(), "disbursement_date": nowdate(),
"repayment_start_date": add_days(nowdate(), 10),
"status": "Disbursed",
"mode_of_payment": frappe.db.get_value('Mode of Payment', {'type': 'Cash'}, 'name'), "mode_of_payment": frappe.db.get_value('Mode of Payment', {'type': 'Cash'}, 'name'),
"payment_account": frappe.db.get_value('Account', {'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name"), "payment_account": frappe.db.get_value('Account', {'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name"),
"loan_account": frappe.db.get_value('Account', {'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name"), "loan_account": frappe.db.get_value('Account', {'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name"),

View File

@@ -279,7 +279,6 @@ def make_salary_structure(sal_struct, payroll_frequency, employee):
"payroll_frequency": payroll_frequency, "payroll_frequency": payroll_frequency,
"payment_account": get_random("Account") "payment_account": get_random("Account")
}).insert() }).insert()
create_salary_structure_assignment(employee, salary_structure) create_salary_structure_assignment(employee, salary_structure)
elif not frappe.db.get_value("Salary Structure Assignment",{'salary_structure':sal_struct, 'employee':employee},'name'): elif not frappe.db.get_value("Salary Structure Assignment",{'salary_structure':sal_struct, 'employee':employee},'name'):

View File

@@ -381,6 +381,11 @@ def set_missing_values(time_sheet, target):
target.start_date = doc.start_date target.start_date = doc.start_date
target.end_date = doc.end_date target.end_date = doc.end_date
target.posting_date = doc.modified target.posting_date = doc.modified
target.total_working_hours = doc.total_hours
target.append('timesheets', {
'time_sheet': doc.name,
'working_hours': doc.total_hours
})
@frappe.whitelist() @frappe.whitelist()
def get_activity_cost(employee=None, activity_type=None): def get_activity_cost(employee=None, activity_type=None):

View File

@@ -2,6 +2,7 @@
# License: GNU General Public License v3. See license.txt # License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe, unittest import frappe, unittest
from frappe.utils import flt
from erpnext.setup.utils import get_exchange_rate from erpnext.setup.utils import get_exchange_rate
test_records = frappe.get_test_records('Currency Exchange') test_records = frappe.get_test_records('Currency Exchange')
@@ -44,7 +45,7 @@ class TestCurrencyExchange(unittest.TestCase):
# Start with allow_stale is True # Start with allow_stale is True
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-01") exchange_rate = get_exchange_rate("USD", "INR", "2016-01-01")
self.assertEqual(exchange_rate, 60.0) self.assertEqual(flt(exchange_rate, 3), 60.0)
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15") exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15")
self.assertEqual(exchange_rate, 65.1) self.assertEqual(exchange_rate, 65.1)
@@ -56,7 +57,7 @@ class TestCurrencyExchange(unittest.TestCase):
self.clear_cache() self.clear_cache()
exchange_rate = get_exchange_rate("USD", "INR", "2015-12-15") exchange_rate = get_exchange_rate("USD", "INR", "2015-12-15")
self.assertFalse(exchange_rate == 60) self.assertFalse(exchange_rate == 60)
self.assertEqual(exchange_rate, 66.894) self.assertEqual(flt(exchange_rate, 3), 66.894)
def test_exchange_rate_strict(self): def test_exchange_rate_strict(self):
# strict currency settings # strict currency settings
@@ -69,7 +70,7 @@ class TestCurrencyExchange(unittest.TestCase):
# Will fetch from fixer.io # Will fetch from fixer.io
self.clear_cache() self.clear_cache()
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15") exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15")
self.assertEqual(exchange_rate, 67.79) self.assertEqual(flt(exchange_rate, 3), 67.79)
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-30") exchange_rate = get_exchange_rate("USD", "INR", "2016-01-30")
self.assertEqual(exchange_rate, 62.9) self.assertEqual(exchange_rate, 62.9)
@@ -77,7 +78,7 @@ class TestCurrencyExchange(unittest.TestCase):
# Exchange rate as on 15th Dec, 2015, should be fetched from fixer.io # Exchange rate as on 15th Dec, 2015, should be fetched from fixer.io
self.clear_cache() self.clear_cache()
exchange_rate = get_exchange_rate("USD", "INR", "2015-12-15") exchange_rate = get_exchange_rate("USD", "INR", "2015-12-15")
self.assertEqual(exchange_rate, 66.894) self.assertEqual(flt(exchange_rate, 3), 66.894)
exchange_rate = get_exchange_rate("INR", "NGN", "2016-01-10") exchange_rate = get_exchange_rate("INR", "NGN", "2016-01-10")
self.assertEqual(exchange_rate, 65.1) self.assertEqual(exchange_rate, 65.1)
@@ -100,4 +101,4 @@ class TestCurrencyExchange(unittest.TestCase):
# Will fetch from fixer.io # Will fetch from fixer.io
self.clear_cache() self.clear_cache()
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15") exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15")
self.assertEqual(exchange_rate, 67.79) self.assertEqual(flt(exchange_rate, 3), 67.79)

View File

@@ -97,7 +97,7 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No
if not value: if not value:
import requests import requests
api_url = "http://api.fixer.io/{0}".format(transaction_date) api_url = "https://exchangeratesapi.io/api/{0}".format(transaction_date)
response = requests.get(api_url, params={ response = requests.get(api_url, params={
"base": from_currency, "base": from_currency,
"symbols": to_currency "symbols": to_currency

View File

@@ -110,7 +110,6 @@ class TestShoppingCart(unittest.TestCase):
tax_rule_master = set_taxes(quotation.customer, "Customer", \ tax_rule_master = set_taxes(quotation.customer, "Customer", \
quotation.transaction_date, quotation.company, None, None, \ quotation.transaction_date, quotation.company, None, None, \
quotation.customer_address, quotation.shipping_address_name, 1) quotation.customer_address, quotation.shipping_address_name, 1)
self.assertEqual(quotation.taxes_and_charges, tax_rule_master) self.assertEqual(quotation.taxes_and_charges, tax_rule_master)
self.assertEqual(quotation.total_taxes_and_charges, 1000.0) self.assertEqual(quotation.total_taxes_and_charges, 1000.0)

View File

@@ -66,7 +66,7 @@ class TestItem(unittest.TestCase):
"warehouse": "_Test Warehouse - _TC", "warehouse": "_Test Warehouse - _TC",
"income_account": "Sales - _TC", "income_account": "Sales - _TC",
"expense_account": "_Test Account Cost for Goods Sold - _TC", "expense_account": "_Test Account Cost for Goods Sold - _TC",
"cost_center": "_Test Cost Center 2 - _TC", "cost_center": "_Test Cost Center - _TC",
"qty": 1.0, "qty": 1.0,
"price_list_rate": 100.0, "price_list_rate": 100.0,
"base_price_list_rate": 0.0, "base_price_list_rate": 0.0,
@@ -144,15 +144,15 @@ class TestItem(unittest.TestCase):
}) })
item_attribute.save() item_attribute.save()
template = frappe.get_doc('Item', '_Test Variant Item')
template.item_group = "_Test Item Group D"
template.save()
variant = create_variant("_Test Variant Item", {"Test Size": "Extra Large"}) variant = create_variant("_Test Variant Item", {"Test Size": "Extra Large"})
variant.item_code = "_Test Variant Item-XL" variant.item_code = "_Test Variant Item-XL"
variant.item_name = "_Test Variant Item-XL" variant.item_name = "_Test Variant Item-XL"
variant.save() variant.save()
template = frappe.get_doc('Item', '_Test Variant Item')
template.item_group = "_Test Item Group D"
template.save()
variant = frappe.get_doc('Item', '_Test Variant Item-XL') variant = frappe.get_doc('Item', '_Test Variant Item-XL')
for fieldname in allow_fields: for fieldname in allow_fields:
self.assertEqual(template.get(fieldname), variant.get(fieldname)) self.assertEqual(template.get(fieldname), variant.get(fieldname))

View File

@@ -273,7 +273,7 @@ class TestPurchaseReceipt(unittest.TestCase):
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note
item_code = frappe.db.get_value('Item', {'has_serial_no': 1}) item_code = frappe.db.get_value('Item', {'has_serial_no': 1, 'is_fixed_asset': 0})
if not item_code: if not item_code:
item = make_item("Test Serial Item 1", dict(has_serial_no=1)) item = make_item("Test Serial Item 1", dict(has_serial_no=1))
item_code = item.name item_code = item.name
@@ -319,6 +319,12 @@ class TestPurchaseReceipt(unittest.TestCase):
'stock_uom': 'Box', 'is_fixed_asset': 1, 'has_serial_no': 1, 'stock_uom': 'Box', 'is_fixed_asset': 1, 'has_serial_no': 1,
'asset_category': asset_category, 'serial_no_series': 'ABC.###'}) 'asset_category': asset_category, 'serial_no_series': 'ABC.###'})
if not frappe.db.exists('Location', 'Test Location'):
frappe.get_doc({
'doctype': 'Location',
'location_name': 'Test Location'
}).insert()
pr = make_purchase_receipt(item_code=asset_item, qty=3) pr = make_purchase_receipt(item_code=asset_item, qty=3)
asset = frappe.db.get_value('Asset', {'purchase_receipt': pr.name}, 'name') asset = frappe.db.get_value('Asset', {'purchase_receipt': pr.name}, 'name')
asset_movement = frappe.db.get_value('Asset Movement', {'reference_name': pr.name}, 'name') asset_movement = frappe.db.get_value('Asset Movement', {'reference_name': pr.name}, 'name')
@@ -328,6 +334,7 @@ class TestPurchaseReceipt(unittest.TestCase):
pr.cancel() pr.cancel()
serial_nos = frappe.get_all('Serial No', {'asset': asset}, 'name') or [] serial_nos = frappe.get_all('Serial No', {'asset': asset}, 'name') or []
self.assertEquals(len(serial_nos), 0) self.assertEquals(len(serial_nos), 0)
frappe.db.sql("delete from `tabLocation")
frappe.db.sql("delete from `tabAsset Category`") frappe.db.sql("delete from `tabAsset Category`")
frappe.db.sql("delete from `tabAsset`") frappe.db.sql("delete from `tabAsset`")
@@ -365,7 +372,8 @@ def make_purchase_receipt(**args):
"conversion_factor": args.conversion_factor or 1.0, "conversion_factor": args.conversion_factor or 1.0,
"serial_no": args.serial_no, "serial_no": args.serial_no,
"stock_uom": args.stock_uom or "_Test UOM", "stock_uom": args.stock_uom or "_Test UOM",
"uom": args.uom or "_Test UOM" "uom": args.uom or "_Test UOM",
"asset_location": "Test Location" if args.item_code == "Test Serialized Asset Item" else ""
}) })
if not args.do_not_save: if not args.do_not_save: