When the user clicks the “Create” button, a quick entry form appears where they can enter the customer name. After entering the customer name and clicking “Create,” the customer is created in the Customer doctype, but it remains unsaved. Why is this happening? Please correct this issue.
Below is the Screenshot
Then click Create a new Doc is Created in Customer but it still Unsaved
Below is the code
Help
refresh: function(frm) {
// Check if the document is in “Draft” status or is a new document
if (frm.doc.docstatus === 0 || frm.is_new()) {
{ frm.set_df_property(‘customer’, ‘only_select’, true); }
// Show the button only for "Draft" status and new documents
// addCreateCustomerButton(frm);
frm.fields_dict['customer'].$wrapper.find('.btn-create-customer').remove();
// Add the button
frm.fields_dict['customer'].$wrapper.append('<button class="btn btn-xs btn-primary btn-create-customer">Create Customer</button>');
frm.fields_dict['customer'].$wrapper.find('.btn-create-customer').css({
'background-color': '#ffffff',
'color': '#000000',
'width': '100%', // Adjust the width as needed
'border': '1px solid #808080'
}).on('click', function() {
frappe.call({
method: 'frappe.client.get_value',
args: {
doctype: 'Company',
filters: {'name': frm.doc.company},
fieldname: ['default_currency',]
},
callback: function(response) {
if (!response.exc && response.message) {
defaultCurrency = response.message.default_currency;
}
}
});
frappe.prompt([
{'label': 'Customer Name', 'fieldname': 'customer_name', 'fieldtype': 'Data', 'reqd': true},
{
'label': 'Customer Type1',
'fieldname': 'customer_type1',
'fieldtype': 'HTML',
'options': `
<div style="display: flex;">
<label style="margin-right: 20px !important;">
<input type="radio" name="customer_type1" value="Company" checked> Company
</label>
<label>
<input type="radio" name="customer_type1" value="Individual"> Individual
</label>
</div>
`
},
{'label': 'Company', 'fieldname': 'company', 'fieldtype': 'Link', 'options': 'Company', 'default': frm.doc.company,'hidden': true},
{'label': 'Plan', 'fieldname': 'plan', 'fieldtype': 'Data', 'default': frm.doc.custom_plan,'hidden':true},
{'label': 'Customer Group', 'fieldname': 'customer_group', 'fieldtype': 'Link', 'options': 'Customer Group' },
{'label':'indusrty ','fieldname':'industry','fieldtype':'Data','default':frm.doc.custom_industry,'hidden':true},
{'label': 'Country', 'fieldname': 'country', 'fieldtype': 'Link','options':'Country','default':frm.doc.custom_country,'mandatory_depends_on': 'eval:doc.industry==="IT Service" && doc.plan=="Professional" || doc.plan =="Premium" && doc.industry=="IT Service"','depends_on': 'eval:doc.industry==="IT Service" && doc.plan=="Professional" || doc.plan=="Premium" && doc.industry=="IT Service"'},
{'label': 'Tax Category', 'fieldname': 'tax', 'fieldtype': 'Link','options':'Tax Category','depends_on':'eval:doc.country=="India"','mandatory_depends_on':'eval:doc.country=="India"','description':'For Transactions Outside your State, Choose "Outstate" .For Transactions within your State, Choose "Instate".'},
{'label': 'Mobile Number', 'fieldname': 'mobile_number', 'fieldtype': 'Phone', 'mandatory_depends_on': 'eval:doc.industry==="IT Service" && doc.plan=="Professional" || doc.plan =="Premium" && doc.industry=="IT Service"'},
],
function(values){
var newCustomer = frappe.model.get_new_doc('Customer');
newCustomer.customer_name = values.customer_name;
newCustomer.customer_group = values.customer_group;
newCustomer.custom_mobile_number = values.mobile_number;
// Set the custom_customer_type based on the selected value
console.log("newCustomer before save call:", newCustomer);
frappe.call({
method: 'frappe.client.save',
args: {
doc: newCustomer
},
callback: function(response) {
console.log("Response from save call:", response);
if (!response.exc) {
// frappe.msgprint(__('Customer created successfully!'));
frappe.msgprint('<div style="text-align:center;"><i class="fa fa-check-circle" style="color: green; font-size: 60px;"></i><br>' +
'<span style="font-size: 20px;">' + __('Customer created successfully!') + '</span>' +
'</div>');
frappe.call({
method:"frappe.client.get",
args:{
doctype:"Customer",
name: response.message.name
},
callback :function(responseion){
var customerData = responseion.message
console.log( "Inner ",customerData)
frappe.call({
method:"frappe.client.save",
args:{
doc: customerData
},
callback: function(saveResponse) {
if (saveResponse.message) {
console.log("Customer saved successfully!");
}
}
})
}
})
frm.set_value('customer', response.message.name);
} else {
frappe.msgprint(__('Error creating customer: ') + response.exc);
}
}
});
}, 'New Customer', 'Create');
});
}
},