Quotation % Amount Billed quantity

hello everyone,
I’m trying to Know the percent of quantity that I used in sales order from quotation

example:
I have a quotation the of total quantity is 100
I create sale Order form that Quotation and change the quantity to 50
that is mean I used just 50% of quotation

I want to know that value, the remind quantity ?

note if created sales invoice from sales order there is field in sales order called ‘% Amount Billed’ by this field I can know how much I used from sales order

but in quotation I can not
please guide me.

Possible, here I made a short scenario, so please check it.

Server Script:

quotations = set()

for item in doc.items:
    if item.prevdoc_docname:
        quotations.add(item.prevdoc_docname)

for quotation_id in quotations:
    quotation = frappe.get_doc("Quotation", quotation_id)
    total_quotation_qty = sum(item.qty for item in quotation.items)

    total_used_qty = frappe.db.sql("""
        SELECT SUM(qty) FROM `tabSales Order Item`
        WHERE prevdoc_docname = %s AND docstatus = 1
    """, quotation_id)[0][0] or 0

    percent_used = (total_used_qty / total_quotation_qty) * 100 if total_quotation_qty > 0 else 0
    remaining_qty = total_quotation_qty - total_used_qty

    frappe.db.set_value("Quotation", quotation_id, "percent_quantity_used", percent_used)
    frappe.db.set_value("Quotation", quotation_id, "remaining_quantity", remaining_qty)
1 Like

Thank you very much, it is work successfully.

is there way to print variable in server script like console.log() in client script
because I need to make editing in code .thanks

use frappe.errprint(xyz)

1 Like