Skip to content

Commit

Permalink
test: fix bad test data (#37773)
Browse files Browse the repository at this point in the history
* test(stock): fix bad test data

* test(asset): fix bad test data

* test(stock): fix bad test data

* test(manufacturing): fix bad test data
  • Loading branch information
blaggacao authored Oct 31, 2023
1 parent d758fc1 commit 139a68f
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 113 deletions.
133 changes: 24 additions & 109 deletions erpnext/assets/doctype/asset_maintenance/test_asset_maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,22 @@
class TestAssetMaintenance(unittest.TestCase):
def setUp(self):
set_depreciation_settings_in_company()
create_asset_data()
create_maintenance_team()

def test_create_asset_maintenance(self):
pr = make_purchase_receipt(
self.pr = make_purchase_receipt(
item_code="Photocopier", qty=1, rate=100000.0, location="Test Location"
)
self.asset_name = frappe.db.get_value("Asset", {"purchase_receipt": self.pr.name}, "name")
self.asset_doc = frappe.get_doc("Asset", self.asset_name)

asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, "name")
asset_doc = frappe.get_doc("Asset", asset_name)
def test_create_asset_maintenance_with_log(self):
month_end_date = get_last_day(nowdate())

purchase_date = nowdate() if nowdate() != month_end_date else add_days(nowdate(), -15)

asset_doc.available_for_use_date = purchase_date
asset_doc.purchase_date = purchase_date
self.asset_doc.available_for_use_date = purchase_date
self.asset_doc.purchase_date = purchase_date

asset_doc.calculate_depreciation = 1
asset_doc.append(
self.asset_doc.calculate_depreciation = 1
self.asset_doc.append(
"finance_books",
{
"expected_value_after_useful_life": 200,
Expand All @@ -42,97 +39,32 @@ def test_create_asset_maintenance(self):
},
)

asset_doc.save()

if not frappe.db.exists("Asset Maintenance", "Photocopier"):
asset_maintenance = frappe.get_doc(
{
"doctype": "Asset Maintenance",
"asset_name": "Photocopier",
"maintenance_team": "Team Awesome",
"company": "_Test Company",
"asset_maintenance_tasks": get_maintenance_tasks(),
}
).insert()

next_due_date = calculate_next_due_date(nowdate(), "Monthly")
self.assertEqual(asset_maintenance.asset_maintenance_tasks[0].next_due_date, next_due_date)

def test_create_asset_maintenance_log(self):
if not frappe.db.exists("Asset Maintenance Log", "Photocopier"):
asset_maintenance_log = frappe.get_doc(
{
"doctype": "Asset Maintenance Log",
"asset_maintenance": "Photocopier",
"task": "Change Oil",
"completion_date": add_days(nowdate(), 2),
"maintenance_status": "Completed",
}
).insert()
asset_maintenance = frappe.get_doc("Asset Maintenance", "Photocopier")
next_due_date = calculate_next_due_date(asset_maintenance_log.completion_date, "Monthly")
self.assertEqual(asset_maintenance.asset_maintenance_tasks[0].next_due_date, next_due_date)


def create_asset_data():
if not frappe.db.exists("Asset Category", "Equipment"):
create_asset_category()
self.asset_doc.save()

if not frappe.db.exists("Location", "Test Location"):
frappe.get_doc({"doctype": "Location", "location_name": "Test Location"}).insert()

if not frappe.db.exists("Item", "Photocopier"):
meta = frappe.get_meta("Asset")
naming_series = meta.get_field("naming_series").options
frappe.get_doc(
asset_maintenance = frappe.get_doc(
{
"doctype": "Item",
"item_code": "Photocopier",
"item_name": "Photocopier",
"item_group": "All Item Groups",
"doctype": "Asset Maintenance",
"asset_name": self.asset_name,
"maintenance_team": "Team Awesome",
"company": "_Test Company",
"is_fixed_asset": 1,
"is_stock_item": 0,
"asset_category": "Equipment",
"auto_create_assets": 1,
"asset_naming_series": naming_series,
"asset_maintenance_tasks": get_maintenance_tasks(),
}
).insert()

next_due_date = calculate_next_due_date(nowdate(), "Monthly")
self.assertEqual(asset_maintenance.asset_maintenance_tasks[0].next_due_date, next_due_date)

def create_maintenance_team():
user_list = ["marcus@abc.com", "thalia@abc.com", "mathias@abc.com"]
if not frappe.db.exists("Role", "Technician"):
frappe.get_doc({"doctype": "Role", "role_name": "Technician"}).insert()
for user in user_list:
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": "Technician"}],
}
).insert()

if not frappe.db.exists("Asset Maintenance Team", "Team Awesome"):
frappe.get_doc(
asset_maintenance_log = frappe.get_doc(
{
"doctype": "Asset Maintenance Team",
"maintenance_manager": "marcus@abc.com",
"maintenance_team_name": "Team Awesome",
"company": "_Test Company",
"maintenance_team_members": get_maintenance_team(user_list),
"doctype": "Asset Maintenance Log",
"asset_maintenance": self.asset_name,
"task": "Change Oil",
"completion_date": add_days(nowdate(), 2),
"maintenance_status": "Completed",
}
).insert()


def get_maintenance_team(user_list):
return [
{"team_member": user, "full_name": user, "maintenance_role": "Technician"}
for user in user_list[1:]
]
next_due_date = calculate_next_due_date(asset_maintenance_log.completion_date, "Monthly")
self.assertEqual(asset_maintenance.asset_maintenance_tasks[0].next_due_date, next_due_date)


def get_maintenance_tasks():
Expand All @@ -156,23 +88,6 @@ def get_maintenance_tasks():
]


def create_asset_category():
asset_category = frappe.new_doc("Asset Category")
asset_category.asset_category_name = "Equipment"
asset_category.total_number_of_depreciations = 3
asset_category.frequency_of_depreciation = 3
asset_category.append(
"accounts",
{
"company_name": "_Test Company",
"fixed_asset_account": "_Test Fixed Asset - _TC",
"accumulated_depreciation_account": "_Test Accumulated Depreciations - _TC",
"depreciation_expense_account": "_Test Depreciations - _TC",
},
)
asset_category.insert()


def set_depreciation_settings_in_company():
company = frappe.get_doc("Company", "_Test Company")
company.accumulated_depreciation_account = "_Test Accumulated Depreciations - _TC"
Expand Down
68 changes: 68 additions & 0 deletions erpnext/assets/doctype/asset_maintenance/test_records.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[
{
"doctype": "Asset Category",
"asset_category_name": "Equipment",
"total_number_of_depreciations": 3,
"frequency_of_depreciation": 3,
"accounts": [
{
"company_name": "_Test Company",
"fixed_asset_account": "_Test Fixed Asset - _TC",
"accumulated_depreciation_account": "_Test Accumulated Depreciations - _TC",
"depreciation_expense_account": "_Test Depreciations - _TC"
}
]
},
{
"doctype": "Location",
"location_name": "Test Location"
},
{
"doctype": "Role",
"role_name": "Technician"
},
{
"doctype": "User",
"email": "marcus@abc.com",
"first_name": "marcus@abc.com",
"new_password": "password",
"roles": [{"doctype": "Has Role", "role": "Technician"}]
},
{
"doctype": "User",
"email": "thalia@abc.com",
"first_name": "thalia@abc.com",
"new_password": "password",
"roles": [{"doctype": "Has Role", "role": "Technician"}]
},
{
"doctype": "User",
"email": "mathias@abc.com",
"first_name": "mathias@abc.com",
"new_password": "password",
"roles": [{"doctype": "Has Role", "role": "Technician"}]
},
{
"doctype": "Asset Maintenance Team",
"maintenance_manager": "marcus@abc.com",
"maintenance_team_name": "Team Awesome",
"company": "_Test Company",
"maintenance_team_members": [
{"team_member": "marcus@abc.com", "full_name": "marcus@abc.com", "maintenance_role": "Technician"},
{"team_member": "thalia@abc.com", "full_name": "thalia@abc.com", "maintenance_role": "Technician"},
{"team_member": "mathias@abc.com", "full_name": "mathias@abc.com", "maintenance_role": "Technician"}
]
},
{
"doctype": "Item",
"item_code": "Photocopier",
"item_name": "Photocopier",
"item_group": "All Item Groups",
"company": "_Test Company",
"is_fixed_asset": 1,
"is_stock_item": 0,
"asset_category": "Equipment",
"auto_create_assets": 1,
"asset_naming_series": "ABC.###"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ def test_job_card(self):
"from_time": row.from_time,
"to_time": row.to_time,
"time_in_mins": row.time_in_mins,
"completed_qty": 0,
},
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[
{
"doctype": "Quality Inspection Parameter",
"parameter" : "_Test Param"
},
{
"quality_inspection_template_name" : "_Test Quality Inspection Template",
"doctype": "Quality Inspection Template",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ def _assert_status(doc, status):
item_code="_Test Item",
warehouse="_Test Warehouse - _TC",
based_on="Item and Warehouse",
voucher_type="Sales Invoice",
voucher_no="SI-1",
posting_date="2021-01-02",
posting_time="00:01:00",
)
Expand All @@ -148,8 +146,6 @@ def _assert_status(doc, status):
riv1.flags.dont_run_in_test = True
riv1.submit()
_assert_status(riv1, "Queued")
self.assertEqual(riv1.voucher_type, "Sales Invoice") # traceability
self.assertEqual(riv1.voucher_no, "SI-1")

# newer than existing duplicate - riv1
riv2 = frappe.get_doc(riv_args.update({"posting_date": "2021-01-03"}))
Expand Down

0 comments on commit 139a68f

Please sign in to comment.