frappe.ui.form.on("Quotation", "refresh", function(frm, doctype, name) {
cur_frm.add_custom_button(__('Add Interaction'), function() {
var d = frappe.prompt([
{'fieldname': 'person_interacted_with', 'fieldtype': 'Data', 'label': 'Person Interacted with', 'reqd': 0},
{'fieldname': 'type_of_interaction', 'fieldtype': 'Link', options:"Interaction Type",'label': 'Type of Interaction', 'reqd': 0},
{'fieldname': 'result', 'fieldtype': 'Link', options:"Interaction Result",'label': 'Result', 'reqd': 0},
{'fieldname': 'responsible', 'fieldtype': 'Link', options:"User", 'default': user, 'label': 'Responsible', 'reqd': 0},
{'fieldname': 'create_task', 'fieldtype': 'Check', 'default': true, 'label': 'Create Task'},
{fieldtype: "Column Break"},
{'fieldname': 'next_date', 'fieldtype': 'Date',
'label': 'Next Action Date', 'default': frappe.datetime.add_days(frappe.datetime.nowdate(),7), 'reqd': 0},
{'fieldname': 'next_action_by', 'fieldtype': 'Link', options:"User", 'default': user,'label': 'Next Action By', 'reqd': 0},
{'fieldname': 'comment', 'fieldtype': 'Text', 'label': 'Next Action Task', 'reqd': 1},
{fieldtype: "Section Break"},
{'fieldname': 'remarks', 'fieldtype': 'Text Editor', 'label': 'Remarks', 'reqd': 1}
],
function(values){
// How to get popup value
var c = d.get_values()
var cmnt = "Person Interacted with: "+ c.person_interacted_with
+"<br>Type of Interaction: "+ c.type_of_interaction
+"<br>Result: "+ c.result
// call the python fuction and pass the argument
var me = frm.doc
frappe.call({
method: "dpicrm.custom_method.add_interaction",
args: {
doc:{
doctype: "Interaction",
reference_doctype: frm.doc.doctype,
reference_name: frm.doc.name,
result: c.result,
person_interacted_with: c.person_interacted_with,
next_action_date: c.next_date,
type_of_interaction: c.type_of_interaction,
// result: c.result,
next_action_by: c.next_action_by,
next_action_task: c.comment,
remarks: c.remarks,
responsible: c.responsible
// next_date
}
},
callback: function(r) {
msgprint("Interaction master record created");
}
});
},
'Submit','Add Interaction', "btn-default"
)
});
});
python code
@frappe.whitelist()
def add_interaction(doc):
doc_json=json.loads(doc)
doc = frappe.get_doc(doc_json)
doc.date = utils.now()
if doc.doctype != "Interaction":
frappe.throw(_("This method can only be used to create a Interaction Master"), frappe.PermissionError)
doc.insert(ignore_permissions = True)
return doc.as_dict()
No comments:
Post a Comment