On changing assign_to assign maintenance task in Asset Maintenance (#11804)

This commit is contained in:
KanchanChauhan 2017-12-01 16:14:05 +05:30 committed by Nabin Hait
parent 34a0e90115
commit 8380253178
7 changed files with 101 additions and 31 deletions

View File

@ -1221,7 +1221,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2017-11-28 07:10:24.760982", "modified": "2017-12-01 15:11:47.466859",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Assets", "module": "Assets",
"name": "Asset", "name": "Asset",
@ -1247,6 +1247,26 @@
"share": 1, "share": 1,
"submit": 1, "submit": 1,
"write": 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, "quick_entry": 0,

View File

@ -17,12 +17,12 @@ class Asset(Document):
self.validate_item() self.validate_item()
self.set_missing_values() self.set_missing_values()
self.validate_asset_values() self.validate_asset_values()
self.make_depreciation_schedule() if self.calculate_depreciation:
self.set_accumulated_depreciation() self.make_depreciation_schedule()
self.set_accumulated_depreciation()
get_depreciation_accounts(self)
if self.get("schedules"): if self.get("schedules"):
self.validate_expected_value_after_useful_life() self.validate_expected_value_after_useful_life()
# Validate depreciation related accounts
get_depreciation_accounts(self)
def on_submit(self): def on_submit(self):
self.set_status() self.set_status()

View File

@ -236,7 +236,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2017-10-19 16:08:02.114363", "modified": "2017-12-01 15:14:25.645077",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Assets", "module": "Assets",
"name": "Asset Category", "name": "Asset Category",
@ -282,6 +282,26 @@
"share": 1, "share": 1,
"submit": 0, "submit": 0,
"write": 1 "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, "quick_entry": 0,

View File

@ -74,11 +74,23 @@ frappe.ui.form.on('Asset Maintenance Task', {
get_next_due_date(frm, cdt, cdn); get_next_due_date(frm, cdt, cdn);
}, },
assign_to: (frm, cdt, cdn) => { assign_to: (frm, cdt, cdn) => {
var d = locals[cdt][cdn];
if (frm.doc.__islocal) { if (frm.doc.__islocal) {
frappe.model.set_value(cdt, cdn, "assign_to", ""); frappe.model.set_value(cdt, cdn, "assign_to", "");
frappe.model.set_value(cdt, cdn, "assign_to_name", ""); frappe.model.set_value(cdt, cdn, "assign_to_name", "");
frappe.throw(__("Please save before assigning task.")); 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
}
});
}
} }
}); });

View File

@ -420,7 +420,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2017-11-29 04:42:54.893169", "modified": "2017-12-01 15:13:29.816396",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Assets", "module": "Assets",
"name": "Asset Maintenance", "name": "Asset Maintenance",
@ -446,6 +446,26 @@
"share": 1, "share": 1,
"submit": 0, "submit": 0,
"write": 1 "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, "quick_entry": 0,

View File

@ -18,29 +18,12 @@ class AssetMaintenance(Document):
task.maintenance_status = "Overdue" task.maintenance_status = "Overdue"
def on_update(self): def on_update(self):
self.sync_maintenance_tasks()
def after_insert(self):
for task in self.get('asset_maintenance_tasks'): for task in self.get('asset_maintenance_tasks'):
self.assign_tasks(task) if not task.assign_to:
task.db_set("assign_to", self.maintenance_manager)
def assign_tasks(self, task): task.db_set("assign_to_name", self.maintenance_manager_name)
if not task.assign_to: assign_tasks(self.name, task.assign_to, task.maintenance_task, task.next_due_date)
task.db_set("assign_to", self.maintenance_manager) self.sync_maintenance_tasks()
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): def sync_maintenance_tasks(self):
tasks_names = [] tasks_names = []
@ -54,6 +37,21 @@ class AssetMaintenance(Document):
maintenance_log = frappe.get_doc('Asset Maintenance Log', asset_maintenance_log.name) maintenance_log = frappe.get_doc('Asset Maintenance Log', asset_maintenance_log.name)
maintenance_log.db_set('maintenance_status', 'Cancelled') 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() @frappe.whitelist()
def calculate_next_due_date(periodicity, start_date = None, end_date = None, last_completion_date = None, next_due_date = None): 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: if not start_date and not last_completion_date:

View File

@ -236,7 +236,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2017-10-25 12:59:19.133235", "modified": "2017-12-01 15:13:00.374360",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Assets", "module": "Assets",
"name": "Asset Maintenance Team", "name": "Asset Maintenance Team",
@ -257,7 +257,7 @@
"print": 1, "print": 1,
"read": 1, "read": 1,
"report": 1, "report": 1,
"role": "System Manager", "role": "Manufacturing User",
"set_user_permissions": 0, "set_user_permissions": 0,
"share": 1, "share": 1,
"submit": 0, "submit": 0,