Delete old asset doctypes from Accounts module and minor changes (#11766)
diff --git a/erpnext/assets/doctype/asset/asset.json b/erpnext/assets/doctype/asset/asset.json
index e0ed56a..bce8851 100644
--- a/erpnext/assets/doctype/asset/asset.json
+++ b/erpnext/assets/doctype/asset/asset.json
@@ -185,7 +185,39 @@
"label": "Asset Owner",
"length": 0,
"no_copy": 0,
- "options": "Company\nSupplier\nCustomer",
+ "options": "\nCompany\nSupplier\nCustomer",
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 1,
+ "search_index": 0,
+ "set_only_once": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "depends_on": "eval:doc.asset_owner == \"Company\"",
+ "fieldname": "asset_owner_company",
+ "fieldtype": "Link",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Asset Owner Company",
+ "length": 0,
+ "no_copy": 0,
+ "options": "Company",
"permlevel": 0,
"precision": "",
"print_hide": 0,
@@ -1189,7 +1221,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2017-11-21 04:45:24.039059",
+ "modified": "2017-11-28 07:10:24.760982",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset",
diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py
index 9c3ed80..6521907 100644
--- a/erpnext/assets/doctype/asset/test_asset.py
+++ b/erpnext/assets/doctype/asset/test_asset.py
@@ -246,6 +246,7 @@
self.assertEqual(gle, expected_gle)
si.cancel()
+ frappe.delete_doc("Sales Invoice", si.name)
self.assertEqual(frappe.db.get_value("Asset", "Macbook Pro 1", "status"), "Partially Depreciated")
@@ -293,7 +294,8 @@
"next_depreciation_date": "2020-12-31",
"gross_purchase_amount": 100000,
"expected_value_after_useful_life": 10000,
- "warehouse": "_Test Warehouse - _TC"
+ "warehouse": "_Test Warehouse - _TC",
+ "asset_owner": "Company"
})
try:
asset.save()
diff --git a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.js b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.js
index 6a6e72f..ebac84c 100644
--- a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.js
+++ b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.js
@@ -3,13 +3,15 @@
frappe.ui.form.on('Asset Maintenance', {
setup: (frm) => {
- frm.fields_dict["asset_maintenance_tasks"].grid.get_field("assign_to").get_query = function(){
+ frm.set_query("assign_to", "asset_maintenance_tasks", function(doc) {
return {
+ query: "erpnext.assets.doctype.asset_maintenance.asset_maintenance.get_team_members",
filters: {
- parent: frm.doc.maintenance_team
+ maintenance_team: doc.maintenance_team
}
};
- },
+ });
+
frm.set_indicator_formatter('maintenance_status',
function(doc) {
let indicator = 'blue';
diff --git a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.json b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.json
index f526bb8..4d6a7cf 100644
--- a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.json
+++ b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.json
@@ -420,7 +420,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2017-11-21 04:42:54.893169",
+ "modified": "2017-11-29 04:42:54.893169",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset Maintenance",
diff --git a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.py b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.py
index 0ddb5d1..0c42a13 100644
--- a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.py
+++ b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.py
@@ -16,26 +16,43 @@
throw(_("Start date should be less than end date for task {0}").format(task.maintenance_task))
if getdate(task.next_due_date) < getdate(nowdate()):
task.maintenance_status = "Overdue"
- if not self.get("__islocal"):
- if not task.assign_to:
- task.assign_to = self.maintenance_manager
- if task.assign_to:
- self.assign_tasks(task)
+
+ def on_update(self):
+ self.sync_maintenance_tasks()
+
+ def after_insert(self):
+ for task in self.get('asset_maintenance_tasks'):
+ self.assign_tasks(task)
def assign_tasks(self, task):
- team_member = frappe.get_doc('User', task.assign_to).email
- args = {
- 'doctype' : self.doctype,
- 'assign_to' : team_member,
- 'name' : self.name,
- 'description' : task.maintenance_task,
- 'date' : task.next_due_date
- }
- if not frappe.db.sql("""select owner from `tabToDo`
- where reference_type=%(doctype)s and reference_name=%(name)s and status="Open"
- and owner=%(assign_to)s""", args):
- assign_to.add(args)
+ if not task.assign_to:
+ task.db_set("assign_to", self.maintenance_manager)
+ task.db_set("assign_to_name", self.maintenance_manager_name)
+ if task.assign_to:
+ team_member = frappe.get_doc('User', task.assign_to).email
+ args = {
+ 'doctype' : self.doctype,
+ 'assign_to' : team_member,
+ 'name' : self.name,
+ 'description' : task.maintenance_task,
+ 'date' : task.next_due_date
+ }
+ if not frappe.db.sql("""select owner from `tabToDo`
+ where reference_type=%(doctype)s and reference_name=%(name)s and status="Open"
+ and owner=%(assign_to)s""", args):
+ assign_to.add(args)
+ def sync_maintenance_tasks(self):
+ tasks_names = []
+ for task in self.get('asset_maintenance_tasks'):
+ tasks_names.append(task.name)
+ update_maintenance_log(asset_maintenance = self.name, item_code = self.item_code, item_name = self.item_name, task = task)
+ asset_maintenance_logs = frappe.get_all("Asset Maintenance Log", fields=["name"], filters = {"asset_maintenance": self.name,
+ "task": ("not in", tasks_names)})
+ if asset_maintenance_logs:
+ for asset_maintenance_log in asset_maintenance_logs:
+ maintenance_log = frappe.get_doc('Asset Maintenance Log', asset_maintenance_log.name)
+ maintenance_log.db_set('maintenance_status', 'Cancelled')
@frappe.whitelist()
def calculate_next_due_date(periodicity, start_date = None, end_date = None, last_completion_date = None, next_due_date = None):
@@ -44,7 +61,6 @@
if last_completion_date and (last_completion_date > start_date or not start_date):
start_date = last_completion_date
-
if periodicity == 'Daily':
next_due_date = add_days(start_date, 1)
if periodicity == 'Weekly':
@@ -61,11 +77,44 @@
next_due_date = ""
return next_due_date
+def update_maintenance_log(asset_maintenance, item_code, item_name, task):
+ asset_maintenance_log = frappe.get_value("Asset Maintenance Log", {"asset_maintenance": asset_maintenance,
+ "task": task.maintenance_task, "maintenance_status": ('in',['Planned','Overdue'])})
+
+ if not asset_maintenance_log:
+ asset_maintenance_log = frappe.get_doc({
+ "doctype": "Asset Maintenance Log",
+ "asset_maintenance": asset_maintenance,
+ "asset_name": asset_maintenance,
+ "item_code": item_code,
+ "item_name": item_name,
+ "task": task.maintenance_task,
+ "has_certificate": task.certificate_required,
+ "description": task.description,
+ "assign_to_name": task.assign_to_name,
+ "periodicity": str(task.periodicity),
+ "maintenance_type": task.maintenance_type,
+ "due_date": task.next_due_date
+ })
+ asset_maintenance_log.insert()
+ else:
+ maintenance_log = frappe.get_doc('Asset Maintenance Log', asset_maintenance_log)
+ maintenance_log.assign_to_name = task.assign_to_name
+ maintenance_log.has_certificate = task.certificate_required
+ maintenance_log.description = task.description
+ maintenance_log.periodicity = str(task.periodicity)
+ maintenance_log.maintenance_type = task.maintenance_type
+ maintenance_log.due_date = task.next_due_date
+ maintenance_log.save()
+
+@frappe.whitelist()
+def get_team_members(doctype, txt, searchfield, start, page_len, filters):
+ return frappe.db.get_values('Maintenance Team Member', {'parent':filters.get("maintenance_team")})
+
@frappe.whitelist()
def get_maintenance_log(asset_name):
return frappe.db.sql("""
select maintenance_status, count(asset_name) as count, asset_name
from `tabAsset Maintenance Log`
where asset_name=%s group by maintenance_status""",
- (asset_name), as_dict=1)
-
\ No newline at end of file
+ (asset_name), as_dict=1)
\ No newline at end of file
diff --git a/erpnext/assets/doctype/asset_maintenance/test_asset_maintenance.py b/erpnext/assets/doctype/asset_maintenance/test_asset_maintenance.py
index 139d202..57efd5b 100644
--- a/erpnext/assets/doctype/asset_maintenance/test_asset_maintenance.py
+++ b/erpnext/assets/doctype/asset_maintenance/test_asset_maintenance.py
@@ -67,7 +67,8 @@
"warehouse": "_Test Warehouse - _TC",
"company": "_Test Company",
"purchase_date": nowdate(),
- "maintenance_required": 1
+ "maintenance_required": 1,
+ "asset_owner": "Company"
}).insert()
def create_maintenance_team():
diff --git a/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.json b/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.json
index 61ce35a..b63f755 100644
--- a/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.json
+++ b/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.json
@@ -458,7 +458,7 @@
"label": "Maintenance Status",
"length": 0,
"no_copy": 0,
- "options": "Pending\nCompleted\nCancelled\nOverdue",
+ "options": "Planned\nCompleted\nCancelled\nOverdue",
"permlevel": 0,
"precision": "",
"print_hide": 0,
@@ -723,7 +723,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2017-10-29 08:38:55.707903",
+ "modified": "2017-11-28 13:15:01.689318",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset Maintenance Log",
diff --git a/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.py b/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.py
index 4e50751..7c21c24 100644
--- a/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.py
+++ b/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.py
@@ -11,14 +11,14 @@
class AssetMaintenanceLog(Document):
def validate(self):
- # if getdate(self.due_date) > getdate(nowdate()):
- # self.maintenance_status = "Overdue"
+ if getdate(self.due_date) < getdate(nowdate()):
+ self.maintenance_status = "Overdue"
if self.maintenance_status == "Completed" and not self.completion_date:
frappe.throw(_("Please select Completion Date for Completed Asset Maintenance Log"))
- # if self.maintenance_status != "Completed" and self.completion_date:
-# frappe.throw(_("Please select Maintenance Status as Completed or remove Completion Date"))
+ if self.maintenance_status != "Completed" and self.completion_date:
+ frappe.throw(_("Please select Maintenance Status as Completed or remove Completion Date"))
def on_submit(self):
if self.maintenance_status not in ['Completed', 'Cancelled']:
@@ -37,7 +37,8 @@
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()
@frappe.whitelist()
def get_maintenance_tasks(doctype, txt, searchfield, start, page_len, filters):
diff --git a/erpnext/assets/doctype/asset_maintenance_task/asset_maintenance_task.json b/erpnext/assets/doctype/asset_maintenance_task/asset_maintenance_task.json
index 7cf0fec..bdf9054 100644
--- a/erpnext/assets/doctype/asset_maintenance_task/asset_maintenance_task.json
+++ b/erpnext/assets/doctype/asset_maintenance_task/asset_maintenance_task.json
@@ -363,7 +363,7 @@
"label": "Assign To",
"length": 0,
"no_copy": 0,
- "options": "Maintenance Team Member",
+ "options": "User",
"permlevel": 0,
"precision": "",
"print_hide": 0,
@@ -625,7 +625,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
- "modified": "2017-10-25 21:51:38.931436",
+ "modified": "2017-11-28 12:22:34.151430",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset Maintenance Task",
diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.json b/erpnext/assets/doctype/asset_repair/asset_repair.json
index ccba908..edc17bd 100644
--- a/erpnext/assets/doctype/asset_repair/asset_repair.json
+++ b/erpnext/assets/doctype/asset_repair/asset_repair.json
@@ -18,7 +18,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
- "columns": 0,
+ "columns": 1,
"fieldname": "asset_name",
"fieldtype": "Link",
"hidden": 0,
@@ -200,7 +200,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
- "columns": 0,
+ "columns": 1,
"fieldname": "failure_date",
"fieldtype": "Datetime",
"hidden": 0,
@@ -208,7 +208,7 @@
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
- "in_list_view": 1,
+ "in_list_view": 0,
"in_standard_filter": 0,
"label": "Failure Date",
"length": 0,
@@ -361,7 +361,7 @@
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
- "in_list_view": 1,
+ "in_list_view": 0,
"in_standard_filter": 0,
"label": "Repair Status",
"length": 0,
@@ -541,7 +541,7 @@
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
- "in_list_view": 0,
+ "in_list_view": 1,
"in_standard_filter": 0,
"label": "Downtime",
"length": 0,
@@ -658,7 +658,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2017-10-24 16:55:03.424503",
+ "modified": "2017-11-29 00:49:11.172141",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset Repair",
diff --git a/erpnext/assets/doctype/asset_repair/asset_repair_list.js b/erpnext/assets/doctype/asset_repair/asset_repair_list.js
new file mode 100644
index 0000000..f36fd2f
--- /dev/null
+++ b/erpnext/assets/doctype/asset_repair/asset_repair_list.js
@@ -0,0 +1,13 @@
+frappe.listview_settings['Asset Repair'] = {
+ add_fields: ["repair_status"],
+ get_indicator: function(doc) {
+ if(doc.repair_status=="Pending") {
+ return [__("Pending"), "orange"];
+ } else if(doc.repair_status=="Completed") {
+ return [__("Completed"), "green"];
+ } else if(doc.repair_status=="Cancelled") {
+ return [__("Cancelled"), "red"];
+ }
+ }
+};
+
diff --git a/erpnext/config/accounts.py b/erpnext/config/accounts.py
index cf35ef9..9a71608 100644
--- a/erpnext/config/accounts.py
+++ b/erpnext/config/accounts.py
@@ -396,18 +396,6 @@
"items": [
{
"type": "report",
- "name": "Asset Depreciation Ledger",
- "doctype": "Asset",
- "is_query_report": True,
- },
- {
- "type": "report",
- "name": "Asset Depreciations and Balances",
- "doctype": "Asset",
- "is_query_report": True,
- },
- {
- "type": "report",
"name": "Trial Balance for Party",
"doctype": "GL Entry",
"is_query_report": True,
diff --git a/erpnext/docs/user/manual/en/asset/asset-maintenance.md b/erpnext/docs/user/manual/en/asset/asset-maintenance.md
index 7abb06b..7ad13a6 100644
--- a/erpnext/docs/user/manual/en/asset/asset-maintenance.md
+++ b/erpnext/docs/user/manual/en/asset/asset-maintenance.md
@@ -23,7 +23,7 @@
<img class="screenshot" alt="Asset" src="/docs/assets/img/asset/asset_maintenance.png">
### Asset Maintenance Log
-For each task in Asset Maintenance create a Asset Maintenance Log which will have status, completion date and actions performed. Based on completion date here, next due date is calculated automatically.
+For each task in Asset Maintenance, Asset Maintenance Log is auto created to keep track of the upcoming Maintenances. It will have status, completion date and actions performed. Based on completion date here, next due date is calculated automatically and new Asset Maintenance Log is created.
<img class="screenshot" alt="Asset" src="/docs/assets/img/asset/asset_maintenance_log.png">
### Asset Repair