Calculate quantity in piece in a custom field based on input in main quantity field (UOM is DZN)

Hello

I need to show 2 types of quantity in my sales documents . My main UOM is dozen but I need to show how many piece I,m selling or ordering also .

I have created a custom field called Quantity in piece . What I want is when I put quantity in main quantity field Quantity in piece field will be auto calculated with how many piece it is from input dzn quantity ?

I,m novice to python, can anyone help me with a custom script suggestion and how to implement it ?

Thanks in Advance

@inventobd
Try this one -
Write custom script for Quotation as below

frappe.ui.form.on("Quotation Item", "qty", function(frm,cdt,cdn) {
	d = locals[cdt][cdn]
	d.quantity_in_piece = d.qty * 12;
});
1 Like

Hello @Sangram

Thank you very much for your help . I have added it via setup → custom script → quotation item

But not working , did I missed anything ? :frowning:

@inventobd
Select Doctype in custom script Quotation instead of Quotation Item and try again

U r just too awesome man, Worked like a charm :slight_smile: @Sangram

Hello Man

One more thing how can I calculate from piece to dzn automatically. I have tried changing the code so if I give entry in piece exactly like dzn it will calculate dzn automatically. But this doesn’t work . Here is the code . Can you help ?

frappe.ui.form.on("Sales Order Item", "quantity_in_piece", function(frm,cdt,cdn) { d = locals[cdt][cdn] d.qty = d.quantity_in_piece / 12; });

Thanks

SOLVED :slight_smile: