From 83802531784d5fa35e52641adef9ec77c53f9761 Mon Sep 17 00:00:00 2001 From: KanchanChauhan Date: Fri, 1 Dec 2017 16:14:05 +0530 Subject: [PATCH] On changing assign_to assign maintenance task in Asset Maintenance (#11804) --- erpnext/assets/doctype/asset/asset.json | 22 +++++++++- erpnext/assets/doctype/asset/asset.py | 8 ++-- .../asset_category/asset_category.json | 22 +++++++++- .../asset_maintenance/asset_maintenance.js | 12 ++++++ .../asset_maintenance/asset_maintenance.json | 22 +++++++++- .../asset_maintenance/asset_maintenance.py | 42 +++++++++---------- .../asset_maintenance_team.json | 4 +- 7 files changed, 101 insertions(+), 31 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.json b/erpnext/assets/doctype/asset/asset.json index bce8851fda..573832c44c 100644 --- a/erpnext/assets/doctype/asset/asset.json +++ b/erpnext/assets/doctype/asset/asset.json @@ -1221,7 +1221,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2017-11-28 07:10:24.760982", + "modified": "2017-12-01 15:11:47.466859", "modified_by": "Administrator", "module": "Assets", "name": "Asset", @@ -1247,6 +1247,26 @@ "share": 1, "submit": 1, "write": 1 + }, + { + "amend": 0, + "apply_user_permissions": 0, + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "if_owner": 0, + "import": 0, + "permlevel": 0, + "print": 1, + "read": 1, + "report": 1, + "role": "Quality Manager", + "set_user_permissions": 0, + "share": 1, + "submit": 1, + "write": 1 } ], "quick_entry": 0, diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 97cb876930..e5b545e585 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -17,12 +17,12 @@ class Asset(Document): self.validate_item() self.set_missing_values() self.validate_asset_values() - self.make_depreciation_schedule() - self.set_accumulated_depreciation() + if self.calculate_depreciation: + self.make_depreciation_schedule() + self.set_accumulated_depreciation() + get_depreciation_accounts(self) if self.get("schedules"): self.validate_expected_value_after_useful_life() - # Validate depreciation related accounts - get_depreciation_accounts(self) def on_submit(self): self.set_status() diff --git a/erpnext/assets/doctype/asset_category/asset_category.json b/erpnext/assets/doctype/asset_category/asset_category.json index 39b3978383..087b83d910 100644 --- a/erpnext/assets/doctype/asset_category/asset_category.json +++ b/erpnext/assets/doctype/asset_category/asset_category.json @@ -236,7 +236,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2017-10-19 16:08:02.114363", + "modified": "2017-12-01 15:14:25.645077", "modified_by": "Administrator", "module": "Assets", "name": "Asset Category", @@ -282,6 +282,26 @@ "share": 1, "submit": 0, "write": 1 + }, + { + "amend": 0, + "apply_user_permissions": 0, + "cancel": 0, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "if_owner": 0, + "import": 0, + "permlevel": 0, + "print": 1, + "read": 1, + "report": 1, + "role": "Quality Manager", + "set_user_permissions": 0, + "share": 1, + "submit": 0, + "write": 1 } ], "quick_entry": 0, diff --git a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.js b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.js index ebac84cb29..1583daf9ee 100644 --- a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.js +++ b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.js @@ -74,11 +74,23 @@ frappe.ui.form.on('Asset Maintenance Task', { get_next_due_date(frm, cdt, cdn); }, assign_to: (frm, cdt, cdn) => { + var d = locals[cdt][cdn]; if (frm.doc.__islocal) { frappe.model.set_value(cdt, cdn, "assign_to", ""); frappe.model.set_value(cdt, cdn, "assign_to_name", ""); frappe.throw(__("Please save before assigning task.")); } + if (d.assign_to) { + return frappe.call({ + method: 'erpnext.assets.doctype.asset_maintenance.asset_maintenance.assign_tasks', + args: { + asset_maintenance_name: frm.doc.name, + assign_to_member: d.assign_to, + maintenance_task: d.maintenance_task, + next_due_date: d.next_due_date + } + }); + } } }); diff --git a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.json b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.json index 4d6a7cf715..72d96b0db0 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-29 04:42:54.893169", + "modified": "2017-12-01 15:13:29.816396", "modified_by": "Administrator", "module": "Assets", "name": "Asset Maintenance", @@ -446,6 +446,26 @@ "share": 1, "submit": 0, "write": 1 + }, + { + "amend": 0, + "apply_user_permissions": 0, + "cancel": 0, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "if_owner": 0, + "import": 0, + "permlevel": 0, + "print": 1, + "read": 1, + "report": 1, + "role": "Manufacturing User", + "set_user_permissions": 0, + "share": 1, + "submit": 0, + "write": 1 } ], "quick_entry": 0, diff --git a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.py b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.py index 0c42a13440..7551eae229 100644 --- a/erpnext/assets/doctype/asset_maintenance/asset_maintenance.py +++ b/erpnext/assets/doctype/asset_maintenance/asset_maintenance.py @@ -18,29 +18,12 @@ class AssetMaintenance(Document): task.maintenance_status = "Overdue" 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): - 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) + if not task.assign_to: + task.db_set("assign_to", self.maintenance_manager) + task.db_set("assign_to_name", self.maintenance_manager_name) + assign_tasks(self.name, task.assign_to, task.maintenance_task, task.next_due_date) + self.sync_maintenance_tasks() def sync_maintenance_tasks(self): tasks_names = [] @@ -54,6 +37,21 @@ class AssetMaintenance(Document): maintenance_log = frappe.get_doc('Asset Maintenance Log', asset_maintenance_log.name) maintenance_log.db_set('maintenance_status', 'Cancelled') +@frappe.whitelist() +def assign_tasks(asset_maintenance_name, assign_to_member, maintenance_task, next_due_date): + team_member = frappe.get_doc('User', assign_to_member).email + args = { + 'doctype' : 'Asset Maintenance', + 'assign_to' : team_member, + 'name' : asset_maintenance_name, + 'description' : maintenance_task, + 'date' : 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) + @frappe.whitelist() def calculate_next_due_date(periodicity, start_date = None, end_date = None, last_completion_date = None, next_due_date = None): if not start_date and not last_completion_date: diff --git a/erpnext/assets/doctype/asset_maintenance_team/asset_maintenance_team.json b/erpnext/assets/doctype/asset_maintenance_team/asset_maintenance_team.json index 28836b5062..3405a7ddb5 100644 --- a/erpnext/assets/doctype/asset_maintenance_team/asset_maintenance_team.json +++ b/erpnext/assets/doctype/asset_maintenance_team/asset_maintenance_team.json @@ -236,7 +236,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2017-10-25 12:59:19.133235", + "modified": "2017-12-01 15:13:00.374360", "modified_by": "Administrator", "module": "Assets", "name": "Asset Maintenance Team", @@ -257,7 +257,7 @@ "print": 1, "read": 1, "report": 1, - "role": "System Manager", + "role": "Manufacturing User", "set_user_permissions": 0, "share": 1, "submit": 0,