Skip to content

Commit

Permalink
Merge pull request #173 from efeone/bom_assignment
Browse files Browse the repository at this point in the history
feat: When BOM Is created Assignment of BOM to Head of smith.
  • Loading branch information
muhammadmp authored Nov 7, 2023
2 parents c49ef56 + 46372e9 commit 24147fd
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 6 deletions.
119 changes: 119 additions & 0 deletions aumms/aumms/doctype/design_analysis/design_analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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({
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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){
Expand Down
13 changes: 10 additions & 3 deletions aumms/aumms/doctype/design_analysis/design_analysis.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"calculated_stone_weight",
"section_break_qpifr",
"expected_weight",
"assigned_person"
"assigned_person",
"bom_created"
],
"fields": [
{
Expand Down Expand Up @@ -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"
},
Expand All @@ -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",
Expand Down
29 changes: 26 additions & 3 deletions aumms/aumms/doctype/design_analysis/design_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 24147fd

Please sign in to comment.