When we create Purchase Order from Material Request and Purchase UOM is not same as stock uom then we need to reset Purchase order qty.
E.g.1) always change qty = qty/conversion factor
frappe.ui.form.on('Purchase Order', 'validate', function(frm){
for (var idx in frm.doc.items){
if (frm.doc.items[idx].stock_uom != frm.doc.items[idx].uom){
frm.doc.items[idx].qty = frm.doc.items[idx].qty/frm.doc.items[idx].conversion_factor
}
}
});
E.g. 2) change only when PO created from Material Request
frappe.ui.form.on('Purchase Order', 'validate', function(frm){
if(frm.doc.items[0].prevdoc_docname){
for (var idx in frm.doc.items){
if (frm.doc.items[idx].stock_uom != frm.doc.items[idx].uom){
frm.doc.items[idx].qty = frm.doc.items[idx].qty/frm.doc.items[idx].conversion_factor
}
}
}
});
Note:
Here, for loop is used to execute loop and change all item values ``for (var idx in frm.doc.items)``
Previously we are trying this for UOM conversion
cur_frm.cscript.rate_per_weight_unit = function(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
var rate = item.rate_per_weight_unit * item.quantity_in_weight / item.qty;
frappe.model.set_value(cdt, cdn, "rate", rate);
};
E.g.1) always change qty = qty/conversion factor
frappe.ui.form.on('Purchase Order', 'validate', function(frm){
for (var idx in frm.doc.items){
if (frm.doc.items[idx].stock_uom != frm.doc.items[idx].uom){
frm.doc.items[idx].qty = frm.doc.items[idx].qty/frm.doc.items[idx].conversion_factor
}
}
});
E.g. 2) change only when PO created from Material Request
frappe.ui.form.on('Purchase Order', 'validate', function(frm){
if(frm.doc.items[0].prevdoc_docname){
for (var idx in frm.doc.items){
if (frm.doc.items[idx].stock_uom != frm.doc.items[idx].uom){
frm.doc.items[idx].qty = frm.doc.items[idx].qty/frm.doc.items[idx].conversion_factor
}
}
}
});
Note:
Here, for loop is used to execute loop and change all item values ``for (var idx in frm.doc.items)``
Previously we are trying this for UOM conversion
cur_frm.cscript.rate_per_weight_unit = function(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
var rate = item.rate_per_weight_unit * item.quantity_in_weight / item.qty;
frappe.model.set_value(cdt, cdn, "rate", rate);
};
No comments:
Post a Comment