diff --git a/aumms/aumms/doctype/design_analysis/design_analysis.js b/aumms/aumms/doctype/design_analysis/design_analysis.js index d8a7dfcc..50cf3e78 100644 --- a/aumms/aumms/doctype/design_analysis/design_analysis.js +++ b/aumms/aumms/doctype/design_analysis/design_analysis.js @@ -49,15 +49,7 @@ frappe.ui.form.on('Design Analysis', { } }, refresh: function(frm){ - if(frm.doc.status == 'Draft'){ - create_custom_buttons(frm); - } - if(frm.doc.status == 'Request For Verification'){ - request_for_approval(frm); - } - if(frm.doc.status == 'Request For Approval'){ - approve_design_analysis(frm) - } + create_custom_buttons(frm); }, check_dr_required: function(frm){ @@ -75,11 +67,13 @@ frappe.ui.form.on('Design Analysis', { }); let create_custom_buttons = function(frm){ - if(!frm.is_new()){ + if(!frm.is_new() && frm.doc.status=='Draft'){ frm.add_custom_button('Request For Verification',() =>{ request_for_verification(frm); }, 'Actions'); } + approve_design_analysis(frm); + request_for_approval(frm); } let request_for_verification = function(frm){ @@ -103,7 +97,7 @@ let request_for_verification = function(frm){ } let request_for_approval = function(frm){ - if(frm.doc.status == "Request For Verification"){ + if((frm.doc.status == "Request For Verification" ) || (frm.doc.dr_required_check == 0 && frm.doc.verified_item.length>0 && frm.doc.status != 'Request For Approval' && frm.doc.status != 'Approved')){ frm.add_custom_button('Request For Approval', () =>{ make_request_for_approval(frm); },'Actions'); @@ -169,7 +163,7 @@ let make_request_for_approval = function(frm){ // Check if the logged-in user is a supervisor const isSupervisor = frappe.user_roles.includes('Supervisor'); let approve_design_analysis = function(frm) { - if (frm.doc.status === "Request For Approval") { + if (frm.doc.status == "Request For Approval") { if (isSupervisor) { frm.add_custom_button('Approve', () => { const item_code = frm.doc.item_code; @@ -198,11 +192,51 @@ let approve_design_analysis = function(frm) { }); }, 'Actions'); frm.add_custom_button('Reject', () =>{ + reject_design_analysis(frm) },'Actions'); } } } +let reject_design_analysis = function(frm){ + let d = new frappe.ui.Dialog({ + title: 'Reason for Rejection', + fields: [ + { + label: 'Comment', + fieldname: 'comment', + fieldtype: 'Small Text', + reqd: 1 + }, + ], + size: 'small', + primary_action_label: 'Add comment', + primary_action(values) { + frappe.call({ + method: 'aumms.aumms.utils.rejection_action', + args: { + 'doctype': frm.doc.doctype, + 'doc':frm.doc.name, + 'comment':values.comment + }, + callback: function(r) { + if (r.message){ + frm.set_value("status","Rejected") + frm.save() + frappe.show_alert({ + message:__('Rejected........'), + indicator:'red' + }, 5); + } + } + }) + d.hide(); + } +}); + +d.show(); +} + frappe.ui.form.on('Verified Item',{ item: function(frm,cdt,cdn){ let d = locals[cdt][cdn]; @@ -212,7 +246,7 @@ frappe.ui.form.on('Verified Item',{ frm.doc.verified_item.forEach(function(d){ gold_weight += d.gold_wt; expected_weight += d.net_wt; - calculated_stone_weight += d.stone_wt; + calculated_stone_weight += d.stone_wt; }) frm.set_value('gold_weight',gold_weight), frm.set_value('expected_weight',expected_weight), diff --git a/aumms/aumms/doctype/design_analysis/design_analysis.json b/aumms/aumms/doctype/design_analysis/design_analysis.json index 9b125ab6..e96e97e9 100644 --- a/aumms/aumms/doctype/design_analysis/design_analysis.json +++ b/aumms/aumms/doctype/design_analysis/design_analysis.json @@ -177,6 +177,7 @@ { "fieldname": "status", "fieldtype": "Select", + "in_list_view": 1, "label": "Status", "options": "Draft\nRequest For Verification\nRequest For Approval\nApproved\nHold\nRejected\nBOM Created\nWorkorder Created" }, @@ -190,7 +191,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-11-03 17:23:27.828034", + "modified": "2023-11-04 09:49:21.108122", "modified_by": "Administrator", "module": "AuMMS", "name": "Design Analysis", diff --git a/aumms/aumms/utils.py b/aumms/aumms/utils.py index c3cbb37f..23babf69 100644 --- a/aumms/aumms/utils.py +++ b/aumms/aumms/utils.py @@ -288,4 +288,11 @@ def create_notification_log(doctype, docname, recipient, subject, content=None, notification_log.subject = subject if content: notification_log.email_content = content - notification_log.save(ignore_permissions=True) \ No newline at end of file + notification_log.save(ignore_permissions=True) + +@frappe.whitelist() +def rejection_action(doctype,doc,comment): + doc = frappe.get_doc(doctype,doc) + if comment: + doc.add_comment('Comment', comment) + return True