Filters by date on custom field link

Hi,

i wonder how i can do this :
cur_frm.set_query(“fp_keluaran”, function () {
return{
filters: { ‘invoice’: ‘’,‘period’:(‘<’,frappe.utlis.today())) }
}
});

i want to filter only document with valid period that can be selected

Thanks

return{
                filters: [
                    ["invoice", "period", "<", frappe.utlis.today()]
                ]
            }
1 Like

return{
filters: [
[“invoice”,“=”,“”, “period”, “<”, frappe.utlis.today()]
]
}
i want to select document that not linked to an invoice yet…so is that right ?

i had a similar situation, what is did was write a custom func to return list of indents (invoices in your case), filtered out using SQL.

Ref.

def get_indent_for_vehicle(doctype, txt, searchfield, start, page_len, filters):
    indent_items_sql = """
        SELECT name, customer
        FROM `tabIndent Item`
		WHERE parent IN (SELECT name FROM tabIndent WHERE vehicle = "{vehicle}" AND docstatus = 1)
		AND {search_key} LIKE "{search_val}%"
		AND name NOT IN (SELECT indent_item FROM `tabIndent Invoice` WHERE docstatus = 1)
		ORDER BY customer ASC limit {start}, {page_len}
		""".format(
        vehicle=filters["vehicle"],
        start=start,
        page_len=page_len,
        search_key=searchfield,
        search_val=txt
    )

    return frappe.db.sql(indent_items_sql)

JS Counterpart

        this.frm.set_query("indent_item", function (doc, cdt, cdn) {

            frappe.model.validate_missing(doc, "vehicle");

            return {
                query: "flows.flows.doctype.indent_invoice.indent_invoice.get_indent_for_vehicle",
                filters: { vehicle: doc.vehicle },
                searchfield: "customer"
            };
        });
2 Likes

wow this is great…thanks