def test_create_asset_maintenance(self): pr = make_purchase_receipt(item_code="Photocopier", qty=1, rate=100000.0, location="Test Location") asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset_doc = frappe.get_doc('Asset', asset_name) 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 asset_doc.calculate_depreciation = 1 asset_doc.append("finance_books", { "expected_value_after_useful_life": 200, "depreciation_method": "Straight Line", "total_number_of_depreciations": 3, "frequency_of_depreciation": 10, "depreciation_start_date": month_end_date }) 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(self): pr = make_purchase_receipt(item_code="Photocopier", qty=1, rate=100000.0, location="Test Location") asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') asset_doc = frappe.get_doc('Asset', asset_name) 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 asset_doc.calculate_depreciation = 1 asset_doc.append("finance_books", { "expected_value_after_useful_life": 200, "depreciation_method": "Straight Line", "total_number_of_depreciations": 3, "frequency_of_depreciation": 10, "depreciation_start_date": month_end_date }) 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 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 test_create_asset_maintenance(self): 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 update_maintenance_task(self): asset_maintenance_doc = frappe.get_doc('Asset Maintenance Task', self.task) if self.maintenance_status == "Completed": if asset_maintenance_doc.last_completion_date != self.completion_date: next_due_date = calculate_next_due_date(periodicity = self.periodicity, last_completion_date = self.completion_date) asset_maintenance_doc.last_completion_date = self.completion_date asset_maintenance_doc.next_due_date = next_due_date asset_maintenance_doc.maintenance_status = "Planned" asset_maintenance_doc.save() if self.maintenance_status == "Cancelled": asset_maintenance_doc.maintenance_status = "Cancelled" asset_maintenance_doc.save() asset_maintenance_doc = frappe.get_doc('Asset Maintenance', self.asset_maintenance) asset_maintenance_doc.save()