if I want to raise the credit note from sales invoice, I will open sales invoice and click on create then return/credit note. it opens to create a credit note, the series does not change from Invoice to Credit Note, due to this, if accountant miss to select credit note series, it will automatically add to invoice series. Something can do here.
Hi,
You can add the following client script on Invoice Doctype to accomplish the task. Adjust the script as per your need.
frappe.ui.form.on('Sales Invoice', {
// Trigger this function when the form loads
onload: function(frm) {
// Set default series based on the invoice type
set_series_based_on_type(frm);
},
// Trigger this function when the invoice type field changes
invoice_type: function(frm) {
set_series_based_on_type(frm);
}
});
function set_series_based_on_type(frm) {
if (frm.doc.__islocal) {
// Only set series for new documents
return;
}
if (frm.doc.docstatus == 0) {
// Check if the document is a new draft
if (frm.doc.is_credit_note) {
frm.set_value('naming_series', 'CREDIT-NOTE-.#####');
} else {
frm.set_value('naming_series', 'INVOICE-.#####');
}
}
}
Thanks,
Divyesh Mangroliya