tüit Logo Direkt zum Hauptinhalt

Adapt prices in childtable based on a item attribute

// Set item fields before save
// Date: 18.01.2022
// Version: 0.1.0
// Author: Marius Widmann
// Licence:

// Fields in the items table that should be set to zero
var fields = [
    "rate",
    "net_rate"
    ];

frappe.ui.form.on('Quotation', {
	validate(frm) {
	    frappe.show_progress('Adapting prices based on Positionsart...', 0, 100, 'Please wait');
        for (let i = 0; i < frm.doc.items.length; i++) {
            var item = frm.doc.items[i];
            frappe.show_progress('Adapting prices based on Positionsart...', (i+1)/(frm.doc.items.length)*100, 100, 'Please wait');
            if(item.positionsart != "Standard"){
                for ( let j = 0; j < fields.length; j++ ) {
                    frappe.model.set_value(item.doctype, item.name,fields[j],0);
                    frm.refresh_fields(fields[j]);
                }
            }
	    }
	    frappe.show_progress('Done', 100, 100, 'Please close');
	}
});