mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-18 12:39:18 +00:00
* test: fix test due to rename change
* test: fix attendance request tests
- Use `frappe.db.get_value` instead of `get_doc` for asserting values
- Get values after cancellation as reloading attendance doc breaks due to stale doc (primary key changed after cancel of attendance request)
- rollback everything on tearDown
* test: fix Shift Request test
- Use `get_value` instead of `get_doc`
- Remove unnecessary loop, only one shift assignment is made against a shift request
- Get value after cancel again. Get doc is not reliable since primary key changed after cancel
* test: fix POS Closing Entry Test
- Separated into two tests, one checks if SI cancelling is blocked, the other checks PCE cancel impact
- This is done because after cancel via assertRaises, damage done by cancel still exists or is partially comitted
- Dont use this partially cancelled doc for any assertions further, end test at exception assertion
- Use `get_value` to check SI docstatus, as its primary key changes after cancel
* test: fixed asset movement tests
- set cwip account in company to avoid value missing
- removed unused statement
- removed trailing spaces
* Revert "test: fix POS Closing Entry Test"
This reverts commit 8f1a3aef2e.
Co-authored-by: marination <maricadsouza221197@gmail.com>
This commit is contained in:
@@ -15,6 +15,7 @@ from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_pu
|
|||||||
|
|
||||||
class TestAssetMovement(unittest.TestCase):
|
class TestAssetMovement(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
frappe.db.set_value("Company", "_Test Company", "capital_work_in_progress_account", "CWIP Account - _TC")
|
||||||
create_asset_data()
|
create_asset_data()
|
||||||
make_location()
|
make_location()
|
||||||
|
|
||||||
@@ -45,12 +46,12 @@ class TestAssetMovement(unittest.TestCase):
|
|||||||
'location_name': 'Test Location 2'
|
'location_name': 'Test Location 2'
|
||||||
}).insert()
|
}).insert()
|
||||||
|
|
||||||
movement1 = create_asset_movement(purpose = 'Transfer', company = asset.company,
|
movement1 = create_asset_movement(purpose = 'Transfer', company = asset.company,
|
||||||
assets = [{ 'asset': asset.name , 'source_location': 'Test Location', 'target_location': 'Test Location 2'}],
|
assets = [{ 'asset': asset.name , 'source_location': 'Test Location', 'target_location': 'Test Location 2'}],
|
||||||
reference_doctype = 'Purchase Receipt', reference_name = pr.name)
|
reference_doctype = 'Purchase Receipt', reference_name = pr.name)
|
||||||
self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location 2")
|
self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location 2")
|
||||||
|
|
||||||
movement2 = create_asset_movement(purpose = 'Transfer', company = asset.company,
|
create_asset_movement(purpose = 'Transfer', company = asset.company,
|
||||||
assets = [{ 'asset': asset.name , 'source_location': 'Test Location 2', 'target_location': 'Test Location'}],
|
assets = [{ 'asset': asset.name , 'source_location': 'Test Location 2', 'target_location': 'Test Location'}],
|
||||||
reference_doctype = 'Purchase Receipt', reference_name = pr.name)
|
reference_doctype = 'Purchase Receipt', reference_name = pr.name)
|
||||||
self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location")
|
self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location")
|
||||||
@@ -59,18 +60,18 @@ class TestAssetMovement(unittest.TestCase):
|
|||||||
self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location")
|
self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location")
|
||||||
|
|
||||||
employee = make_employee("testassetmovemp@example.com", company="_Test Company")
|
employee = make_employee("testassetmovemp@example.com", company="_Test Company")
|
||||||
movement3 = create_asset_movement(purpose = 'Issue', company = asset.company,
|
create_asset_movement(purpose = 'Issue', company = asset.company,
|
||||||
assets = [{ 'asset': asset.name , 'source_location': 'Test Location', 'to_employee': employee}],
|
assets = [{ 'asset': asset.name , 'source_location': 'Test Location', 'to_employee': employee}],
|
||||||
reference_doctype = 'Purchase Receipt', reference_name = pr.name)
|
reference_doctype = 'Purchase Receipt', reference_name = pr.name)
|
||||||
|
|
||||||
# after issuing asset should belong to an employee not at a location
|
# after issuing asset should belong to an employee not at a location
|
||||||
self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), None)
|
self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), None)
|
||||||
self.assertEqual(frappe.db.get_value("Asset", asset.name, "custodian"), employee)
|
self.assertEqual(frappe.db.get_value("Asset", asset.name, "custodian"), employee)
|
||||||
|
|
||||||
def test_last_movement_cancellation(self):
|
def test_last_movement_cancellation(self):
|
||||||
pr = make_purchase_receipt(item_code="Macbook Pro",
|
pr = make_purchase_receipt(item_code="Macbook Pro",
|
||||||
qty=1, rate=100000.0, location="Test Location")
|
qty=1, rate=100000.0, location="Test Location")
|
||||||
|
|
||||||
asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name')
|
asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name')
|
||||||
asset = frappe.get_doc('Asset', asset_name)
|
asset = frappe.get_doc('Asset', asset_name)
|
||||||
asset.calculate_depreciation = 1
|
asset.calculate_depreciation = 1
|
||||||
@@ -85,17 +86,17 @@ class TestAssetMovement(unittest.TestCase):
|
|||||||
})
|
})
|
||||||
if asset.docstatus == 0:
|
if asset.docstatus == 0:
|
||||||
asset.submit()
|
asset.submit()
|
||||||
|
|
||||||
if not frappe.db.exists("Location", "Test Location 2"):
|
if not frappe.db.exists("Location", "Test Location 2"):
|
||||||
frappe.get_doc({
|
frappe.get_doc({
|
||||||
'doctype': 'Location',
|
'doctype': 'Location',
|
||||||
'location_name': 'Test Location 2'
|
'location_name': 'Test Location 2'
|
||||||
}).insert()
|
}).insert()
|
||||||
|
|
||||||
movement = frappe.get_doc({'doctype': 'Asset Movement', 'reference_name': pr.name })
|
movement = frappe.get_doc({'doctype': 'Asset Movement', 'reference_name': pr.name })
|
||||||
self.assertRaises(frappe.ValidationError, movement.cancel)
|
self.assertRaises(frappe.ValidationError, movement.cancel)
|
||||||
|
|
||||||
movement1 = create_asset_movement(purpose = 'Transfer', company = asset.company,
|
movement1 = create_asset_movement(purpose = 'Transfer', company = asset.company,
|
||||||
assets = [{ 'asset': asset.name , 'source_location': 'Test Location', 'target_location': 'Test Location 2'}],
|
assets = [{ 'asset': asset.name , 'source_location': 'Test Location', 'target_location': 'Test Location 2'}],
|
||||||
reference_doctype = 'Purchase Receipt', reference_name = pr.name)
|
reference_doctype = 'Purchase Receipt', reference_name = pr.name)
|
||||||
self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location 2")
|
self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location 2")
|
||||||
|
|||||||
@@ -15,7 +15,11 @@ class TestAttendanceRequest(unittest.TestCase):
|
|||||||
for doctype in ["Attendance Request", "Attendance"]:
|
for doctype in ["Attendance Request", "Attendance"]:
|
||||||
frappe.db.sql("delete from `tab{doctype}`".format(doctype=doctype))
|
frappe.db.sql("delete from `tab{doctype}`".format(doctype=doctype))
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
frappe.db.rollback()
|
||||||
|
|
||||||
def test_on_duty_attendance_request(self):
|
def test_on_duty_attendance_request(self):
|
||||||
|
"Test creation/updation of Attendace from Attendance Request, on duty."
|
||||||
today = nowdate()
|
today = nowdate()
|
||||||
employee = get_employee()
|
employee = get_employee()
|
||||||
attendance_request = frappe.new_doc("Attendance Request")
|
attendance_request = frappe.new_doc("Attendance Request")
|
||||||
@@ -26,17 +30,36 @@ class TestAttendanceRequest(unittest.TestCase):
|
|||||||
attendance_request.company = "_Test Company"
|
attendance_request.company = "_Test Company"
|
||||||
attendance_request.insert()
|
attendance_request.insert()
|
||||||
attendance_request.submit()
|
attendance_request.submit()
|
||||||
attendance = frappe.get_doc('Attendance', {
|
|
||||||
'employee': employee.name,
|
attendance = frappe.db.get_value(
|
||||||
'attendance_date': date(date.today().year, 1, 1),
|
"Attendance",
|
||||||
'docstatus': 1
|
filters={
|
||||||
})
|
"attendance_request": attendance_request.name,
|
||||||
self.assertEqual(attendance.status, 'Present')
|
"attendance_date": date(date.today().year, 1, 1)
|
||||||
|
},
|
||||||
|
fieldname=["status", "docstatus"],
|
||||||
|
as_dict=True
|
||||||
|
)
|
||||||
|
self.assertEqual(attendance.status, "Present")
|
||||||
|
self.assertEqual(attendance.docstatus, 1)
|
||||||
|
|
||||||
|
# cancelling attendance request cancels linked attendances
|
||||||
attendance_request.cancel()
|
attendance_request.cancel()
|
||||||
attendance.reload()
|
|
||||||
self.assertEqual(attendance.docstatus, 2)
|
# cancellation alters docname
|
||||||
|
# fetch attendance value again to avoid stale docname
|
||||||
|
attendance_docstatus = frappe.db.get_value(
|
||||||
|
"Attendance",
|
||||||
|
filters={
|
||||||
|
"attendance_request": attendance_request.name,
|
||||||
|
"attendance_date": date(date.today().year, 1, 1)
|
||||||
|
},
|
||||||
|
fieldname="docstatus"
|
||||||
|
)
|
||||||
|
self.assertEqual(attendance_docstatus, 2)
|
||||||
|
|
||||||
def test_work_from_home_attendance_request(self):
|
def test_work_from_home_attendance_request(self):
|
||||||
|
"Test creation/updation of Attendace from Attendance Request, work from home."
|
||||||
today = nowdate()
|
today = nowdate()
|
||||||
employee = get_employee()
|
employee = get_employee()
|
||||||
attendance_request = frappe.new_doc("Attendance Request")
|
attendance_request = frappe.new_doc("Attendance Request")
|
||||||
@@ -47,15 +70,30 @@ class TestAttendanceRequest(unittest.TestCase):
|
|||||||
attendance_request.company = "_Test Company"
|
attendance_request.company = "_Test Company"
|
||||||
attendance_request.insert()
|
attendance_request.insert()
|
||||||
attendance_request.submit()
|
attendance_request.submit()
|
||||||
attendance = frappe.get_doc('Attendance', {
|
|
||||||
'employee': employee.name,
|
attendance_status = frappe.db.get_value(
|
||||||
'attendance_date': date(date.today().year, 1, 1),
|
"Attendance",
|
||||||
'docstatus': 1
|
filters={
|
||||||
})
|
"attendance_request": attendance_request.name,
|
||||||
self.assertEqual(attendance.status, 'Work From Home')
|
"attendance_date": date(date.today().year, 1, 1)
|
||||||
|
},
|
||||||
|
fieldname="status"
|
||||||
|
)
|
||||||
|
self.assertEqual(attendance_status, 'Work From Home')
|
||||||
|
|
||||||
attendance_request.cancel()
|
attendance_request.cancel()
|
||||||
attendance.reload()
|
|
||||||
self.assertEqual(attendance.docstatus, 2)
|
# cancellation alters docname
|
||||||
|
# fetch attendance value again to avoid stale docname
|
||||||
|
attendance_docstatus = frappe.db.get_value(
|
||||||
|
"Attendance",
|
||||||
|
filters={
|
||||||
|
"attendance_request": attendance_request.name,
|
||||||
|
"attendance_date": date(date.today().year, 1, 1)
|
||||||
|
},
|
||||||
|
fieldname="docstatus"
|
||||||
|
)
|
||||||
|
self.assertEqual(attendance_docstatus, 2)
|
||||||
|
|
||||||
def get_employee():
|
def get_employee():
|
||||||
return frappe.get_doc("Employee", "_T-Employee-00001")
|
return frappe.get_doc("Employee", "_T-Employee-00001")
|
||||||
|
|||||||
@@ -15,24 +15,35 @@ class TestShiftRequest(unittest.TestCase):
|
|||||||
for doctype in ["Shift Request", "Shift Assignment"]:
|
for doctype in ["Shift Request", "Shift Assignment"]:
|
||||||
frappe.db.sql("delete from `tab{doctype}`".format(doctype=doctype))
|
frappe.db.sql("delete from `tab{doctype}`".format(doctype=doctype))
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
frappe.db.rollback()
|
||||||
|
|
||||||
def test_make_shift_request(self):
|
def test_make_shift_request(self):
|
||||||
|
"Test creation/updation of Shift Assignment from Shift Request."
|
||||||
department = frappe.get_value("Employee", "_T-Employee-00001", 'department')
|
department = frappe.get_value("Employee", "_T-Employee-00001", 'department')
|
||||||
set_shift_approver(department)
|
set_shift_approver(department)
|
||||||
approver = frappe.db.sql("""select approver from `tabDepartment Approver` where parent= %s and parentfield = 'shift_request_approver'""", (department))[0][0]
|
approver = frappe.db.sql("""select approver from `tabDepartment Approver` where parent= %s and parentfield = 'shift_request_approver'""", (department))[0][0]
|
||||||
|
|
||||||
shift_request = make_shift_request(approver)
|
shift_request = make_shift_request(approver)
|
||||||
|
|
||||||
shift_assignments = frappe.db.sql('''
|
# Only one shift assignment is created against a shift request
|
||||||
SELECT shift_request, employee
|
shift_assignment = frappe.db.get_value(
|
||||||
FROM `tabShift Assignment`
|
"Shift Assignment",
|
||||||
WHERE shift_request = '{0}'
|
filters={"shift_request": shift_request.name},
|
||||||
'''.format(shift_request.name), as_dict=1)
|
fieldname=["employee", "docstatus"],
|
||||||
for d in shift_assignments:
|
as_dict=True
|
||||||
employee = d.get('employee')
|
)
|
||||||
self.assertEqual(shift_request.employee, employee)
|
self.assertEqual(shift_request.employee, shift_assignment.employee)
|
||||||
shift_request.cancel()
|
self.assertEqual(shift_assignment.docstatus, 1)
|
||||||
shift_assignment_doc = frappe.get_doc("Shift Assignment", {"shift_request": d.get('shift_request')})
|
|
||||||
self.assertEqual(shift_assignment_doc.docstatus, 2)
|
shift_request.cancel()
|
||||||
|
|
||||||
|
shift_assignment_docstatus = frappe.db.get_value(
|
||||||
|
"Shift Assignment",
|
||||||
|
filters={"shift_request": shift_request.name},
|
||||||
|
fieldname="docstatus"
|
||||||
|
)
|
||||||
|
self.assertEqual(shift_assignment_docstatus, 2)
|
||||||
|
|
||||||
def test_shift_request_approver_perms(self):
|
def test_shift_request_approver_perms(self):
|
||||||
employee = frappe.get_doc("Employee", "_T-Employee-00001")
|
employee = frappe.get_doc("Employee", "_T-Employee-00001")
|
||||||
|
|||||||
@@ -673,6 +673,8 @@ class TestSalesOrder(unittest.TestCase):
|
|||||||
|
|
||||||
so.cancel()
|
so.cancel()
|
||||||
|
|
||||||
|
dn.load_from_db()
|
||||||
|
|
||||||
self.assertRaises(frappe.CancelledLinkError, dn.submit)
|
self.assertRaises(frappe.CancelledLinkError, dn.submit)
|
||||||
|
|
||||||
def test_service_type_product_bundle(self):
|
def test_service_type_product_bundle(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user