From 46372e952ea52a37d66eb1bff9d18351714344f8 Mon Sep 17 00:00:00 2001 From: Geethu k Date: Tue, 7 Nov 2023 11:45:07 +0530 Subject: [PATCH] feat: When BOM Is created Assignment of BOM to Head of smith should be done --- .../design_analysis/design_analysis.js | 119 ++++++++++++++++++ .../design_analysis/design_analysis.json | 13 +- .../design_analysis/design_analysis.py | 29 ++++- 3 files changed, 155 insertions(+), 6 deletions(-) diff --git a/aumms/aumms/doctype/design_analysis/design_analysis.js b/aumms/aumms/doctype/design_analysis/design_analysis.js index 50cf3e78..888777d0 100644 --- a/aumms/aumms/doctype/design_analysis/design_analysis.js +++ b/aumms/aumms/doctype/design_analysis/design_analysis.js @@ -50,6 +50,10 @@ frappe.ui.form.on('Design Analysis', { }, refresh: function(frm){ create_custom_buttons(frm); + if(frm.doc.status == 'Approved' && !frm.doc.bom_created){ + create_bom_button(frm); + } + }, check_dr_required: function(frm){ @@ -76,6 +80,59 @@ let create_custom_buttons = function(frm){ request_for_approval(frm); } +let create_bom_button = function(frm){ + if(!frm.is_new()){ + frm.add_custom_button('Create BOM',() =>{ + create_bom(frm); + }, ); + } +} + +let make_request_for_bom = function(frm){ + let bo = new frappe.ui.Dialog({ + title: __('Create BOM'), + fields: [ + { + fieldtype: 'Link', + label: 'Head of Smith', + fieldname: 'head_of_smith', + options: 'Head of Smith', + get_query: function () { + return { + query : 'aumms.aumms.doctype.design_analysis.design_analysis.supervisor_user_query', + }; + }, + + } + ], + primary_action_label: __('Submit'), + primary_action(values) { + let head_of_smith = ''; + if(values.self_assign){ + head_of_smith = frappe.session.user; + } + if (head_of_smith) { + frappe.call({ + method: 'aumms.aumms.doctype.design_analysis.design_analysis.assign_design_analysis', + args: { + doctype: frm.doc.doctype, + docname: frm.doc.name, + head_of_smith: head_of_smith + }, + freeze: true, + callback: (r) => { + frm.reload_doc(); + bo.hide(); + } + }); + } else { + frappe.msgprint('Please select a "Head of Smith".'); + } + } + }); + bo.show(); +} + let request_for_verification = function(frm){ if(frm.doc.dr_required_check){ frappe.call({ @@ -185,12 +242,18 @@ let approve_design_analysis = function(frm) { frm.set_value("status","Approved") frm.save(); console.log('AuMMS Item Created:', r.message); + + } else { console.log('Failed to create AuMMS Item'); } + } + }); }, 'Actions'); + + frm.add_custom_button('Reject', () =>{ reject_design_analysis(frm) },'Actions'); @@ -236,6 +299,62 @@ let reject_design_analysis = function(frm){ d.show(); } +function create_bom(frm) { + + let bom_dia = new frappe.ui.Dialog({ + title: __('Request for BOM'), + fields: [ + { + fieldtype: 'Check', + label: 'Self Assign', + fieldname: 'self_assign', + default: 0, + onchange: function(e) { + d.toggle_enable('assign_to', !e.checked); + if (e.checked) { + d.set_value('assign_to', frappe.session.user); + } + } + }, + { + fieldtype: 'Link', + label: 'Assign To', + fieldname: 'assign_to', + options: 'User', + get_query: function () { + return { + query : 'aumms.aumms.doctype.design_analysis.design_analysis.head_of_smith_user_query', + }; + }, + depends_on: 'eval: !doc.self_assign' + } + ], + primary_action_label: __('Submit'), + primary_action(values) { + let assign_to = ''; + if(values.self_assign){ + assign_to = frappe.session.user; + } + else{ + assign_to = values.assign_to; + } + frappe.call({ + method: 'aumms.aumms.doctype.design_analysis.design_analysis.create_bom_function', + args: { + doctype: frm.doctype, + docname: frm.doc.name, + assign_to: assign_to + }, + freeze: true, + callback: (r) => { + frm.reload_doc(); + bom_dia.hide() + } + }); + } +}); +bom_dia.show() +} frappe.ui.form.on('Verified Item',{ item: function(frm,cdt,cdn){ diff --git a/aumms/aumms/doctype/design_analysis/design_analysis.json b/aumms/aumms/doctype/design_analysis/design_analysis.json index e96e97e9..ac218ad3 100644 --- a/aumms/aumms/doctype/design_analysis/design_analysis.json +++ b/aumms/aumms/doctype/design_analysis/design_analysis.json @@ -31,7 +31,8 @@ "calculated_stone_weight", "section_break_qpifr", "expected_weight", - "assigned_person" + "assigned_person", + "bom_created" ], "fields": [ { @@ -177,7 +178,6 @@ { "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" }, @@ -187,11 +187,18 @@ "hidden": 1, "label": "Assigned Person", "options": "User" + }, + { + "default": "0", + "fieldname": "bom_created", + "fieldtype": "Check", + "hidden": 1, + "label": "BOM created" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-11-04 09:49:21.108122", + "modified": "2023-11-07 11:34:45.343042", "modified_by": "Administrator", "module": "AuMMS", "name": "Design Analysis", diff --git a/aumms/aumms/doctype/design_analysis/design_analysis.py b/aumms/aumms/doctype/design_analysis/design_analysis.py index 6d1a1055..53803db4 100644 --- a/aumms/aumms/doctype/design_analysis/design_analysis.py +++ b/aumms/aumms/doctype/design_analysis/design_analysis.py @@ -11,9 +11,9 @@ def autoname(self): self.name = self.customer_name + '-' + self.item_code + '-' + frappe.utils.today() @frappe.whitelist() -def create_bom_function(design_analysis): - if frappe.db.exists('Design Analysis', design_analysis): - doc = frappe.get_doc('Design Analysis', design_analysis) +def create_bom_function(doctype, docname,assign_to): + if frappe.db.exists('Design Analysis', docname): + doc = frappe.get_doc('Design Analysis', docname) bom = frappe.new_doc('BOM') bom.item = doc.item for row in doc.verified_item: @@ -23,10 +23,33 @@ def create_bom_function(design_analysis): bom_row.qty = row.quantity bom.flags.ignore_mandatory = True bom.save(ignore_permissions=True) + frappe.db.set_value(doctype, docname, 'bom_created', 1) + assign_to_list = [assign_to] + add_assign({ + "assign_to": assign_to_list, + "doctype": bom.doctype, + "name": bom.name + }) return True + else: return False +@frappe.whitelist() +def head_of_smith_user_query(doctype, txt, searchfield, start, page_len, filters): + return frappe.db.sql(""" + SELECT + u.name + FROM + `tabUser`u , + `tabHas Role` r + WHERE + u.name = r.parent and + r.role = 'Head of Smith' and + u.enabled = 1 and + u.name like %s + """, ("%" + txt + "%")) + @frappe.whitelist() def create_aumms_item_from_design_analysis(customer_expected_weight, item, item_group, purity): #Calculate Item Code to set as docname