Skip to content

Commit

Permalink
Merge pull request #137 from efeone/DR_ASSIGN
Browse files Browse the repository at this point in the history
feat: Hide Assign button after assigning
  • Loading branch information
muhammadmp authored Aug 22, 2023
2 parents a12b796 + 7fc5e7d commit 956ddf0
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 73 deletions.
128 changes: 61 additions & 67 deletions aumms/aumms/doctype/design_request/design_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,81 @@
// For license information, please see license.txt

frappe.ui.form.on('Design Request', {

setup:function(frm){
frm.set_query('unit_of_measure', 'design_details', ()=> {
return{
filters: {
"is_purity_uom":1
}
}
});
return{
filters: {
"is_purity_uom":1
}
}
});
},

// Delivery date valdation
delivery_date: function(frm){
if (frm.doc.delivery_date < frappe.datetime.get_today()){
frm.set_value('delivery_date', null)
frm.set_value('delivery_date', )
frappe.throw(__('Delivery date cannot be in the past'))
}
},
refresh: function(frm) {
frm.add_custom_button(__('Assign'), () => {
let d = new frappe.ui.Dialog({
title: __('Assign Design Request'),
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', null); // Clear value when Self Assign is checked
if(!frm.doc.assigned_person && !frm.is_new()) {
frm.add_custom_button(__('Assign'), () => {
let d = new frappe.ui.Dialog({
title: __('Assign Design Request'),
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); // Clear value when Self Assign is checked
}
}
}
},
{
fieldtype: 'Link',
label: 'Assign To',
fieldname: 'assign_to',
options: 'User',
get_query: function () {
return {
query : 'aumms.aumms.doctype.design_request.design_request.design_analyst_user_query',
};
},
depends_on: 'eval: !doc.self_assign' // Show the field only when Self Assign is not checked
}
],
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;
{
fieldtype: 'Link',
label: 'Assign To',
fieldname: 'assign_to',
options: 'User',
get_query: function () {
return {
query : 'aumms.aumms.doctype.design_request.design_request.design_analyst_user_query',
};
},
depends_on: 'eval: !doc.self_assign' // Show the field only when Self Assign is not checked
}
],
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_request.design_request.assign_design_request',
args: {
doctype: frm.doc.doctype,
docname: frm.doc.name,
assign_to: assign_to
},
freeze: true,
callback: (r) => {
frm.reload_doc();
d.hide()
}
});
}
frappe.call({
method: 'frappe.desk.form.assign_to.add',
args: {
doctype: frm.doc.doctype,
name: frm.doc.name,
assign_to: [assign_to]
},
freeze: true,
callback: (r) => {
console.log(r);
// on success
},
})
// Update the button text after successful assignment
let assignButton = document.getElementById('assignButton');
assignButton.textContent = 'Assigned';
frappe.msgprint(__('Design Request has been assigned.'));
d.hide();
}
});
// Show the dialog
d.show();
});

// Show the dialog
d.show();
});
}
}
});

Expand Down
10 changes: 9 additions & 1 deletion aumms/aumms/doctype/design_request/design_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"column_break_ey72q",
"design_title",
"delivery_date",
"assigned_person",
"section_break_cjewr",
"design_details",
"comment",
Expand Down Expand Up @@ -110,12 +111,19 @@
"fieldtype": "Image",
"label": "Image",
"options": "attachment"
},
{
"fieldname": "assigned_person",
"fieldtype": "Link",
"hidden": 1,
"label": "Assigned Person",
"options": "User"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2023-08-10 11:46:19.369484",
"modified": "2023-08-22 10:13:55.205052",
"modified_by": "Administrator",
"module": "AuMMS",
"name": "Design Request",
Expand Down
16 changes: 11 additions & 5 deletions aumms/aumms/doctype/design_request/design_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

import frappe
from frappe.model.document import Document
from frappe.desk.form.assign_to import add as add_assign

class DesignRequest(Document):

def autoname(self):

if self.customer_name:
self.name = self.customer + '-' + self.design_title + '-' + frappe.utils.today()

Expand All @@ -26,7 +26,13 @@ def design_analyst_user_query(doctype, txt, searchfield, start, page_len, filter
u.name like %s
""", ("%" + txt + "%"))





@frappe.whitelist()
def assign_design_request(doctype, docname, assign_to):
assign_to_list = [assign_to]
add_assign({
"assign_to": assign_to_list,
"doctype": doctype,
"name": docname
})
frappe.db.set_value(doctype, docname, 'assigned_person', assign_to)
frappe.db.commit()

0 comments on commit 956ddf0

Please sign in to comment.