Hi guys,
Need some help with a filter.
Setting the date range doesn’t seem to work. I’m still getting all the quotes to this customer.
Any ideas?
frappe.ui.form.on('Quotation', {
customer_name(frm) {
set_doc_id(frm);
},
transaction_date(frm) {
set_doc_id(frm);
}
});
function set_doc_id(frm) {
if (!frm.doc.party_name) {
return;
}
var date = frm.doc.transaction_date;
//var date = new Date();
var YYYY = date.slice(0,4);
var date_range = '01-01-' + YYYY + ' to 31-12-' + YYYY;
frappe.call({
method: 'frappe.client.get_list',
args: {
doctype: 'Quotation',
filters: [
['party_name', '=', frm.doc.party_name],
['transaction_date', 'Between', '01-01-' + YYYY + ' to 31-12-' + YYYY]
]
}
})
.then(count => {
//get the customer in order to retrieve the abbr
frappe.db.get_doc('Customer', frm.doc.party_name)
.then(customer => {
let abbr;
if (customer.hasOwnProperty('abbr')){
//if abbr is already set, dont overwrite it
if (customer.abbr !== "" && customer.abbr !== null && customer.abbr !== undefined) {
abbr = customer.abbr;
}
else {
//get abbreviation
abbr = make_abbr(frm.doc.customer_name);
}
}
else {
//get abbreviation
abbr = make_abbr(frm.doc.customer_name);
}
//add 4 zeros before the actual digit
const padding = (num, places) => String(num).padStart(places, '0');
let cus_doc_count = padding(count.message.length, 3);
//combine values to make transaction id
let id = abbr + "-" + cus_doc_count + "-" + YY + "-" + MM + "-" + DD;
frm.set_value("doc_id", id);
});
frm.refresh_field("doc_id");
});
}
function make_abbr(name) {
//get abbreviation from frappe method
return frappe.get_abbr(name, 5);
}