POS Invoice tax calculation in Sales Invoice

Hi everyone,

I’ve run into an issue that I’m not too sure how to solve.

If you look at the attached image, when making a POS Invoice from the dedicated POS utility, tax is applied correctly per item. “Item 1” has 10% tax on it however “Item 2” has no tax and this leads to the correct grand total.

I am unable to get this method of tax calculation to work in Sales Invoices, Sales Orders, etc and was wondering how it could be achieved.

Thanks

Current Solution:
Add a Taxes and Charges Template set to “Actual” and manually calculate Tax per item before save using a script.

Perhaps there is still a better way to do it but I am unsure.

Client Script (can be used for purchase/sale order/invoice, just change the ‘Sales Invoice’ string):

frappe.ui.form.on('Sales Invoice', {
	before_save: () => {
	    if (cur_frm.doc.taxes.length < 1)
	        return;
	        
        var taxRow;
	        
	    cur_frm.doc.taxes.forEach((row) => {
	        if (taxRow === undefined)
    	        if (row.charge_type === 'Actual' && row.description.startsWith('GST'))
    	            taxRow = row;
	    });
	    
	    if (taxRow === undefined)
	        return;
	    
        var gstAmt = 0;
        
        cur_frm.doc.items.forEach((row) => {
            let tax = Object.values(JSON.parse(row.item_tax_rate))[0];
            
            if (tax !== undefined) {
                tax = 1 + (tax * 0.01); // tax is initially a percentage
                gstAmt += ((row.rate * tax) - row.rate) * row.qty;
            }
		});
		
		taxRow.tax_amount = gstAmt;
	}
});

Script intended for Australian GST calculation so you may need to adjust it to fit your needs.

What’s your setup for POS? Maybe your configuration is incorrect but it works for POS. Im not sure you should fix this by code in the first place. It seems to be a config issue. (but I just did tax set up for sales invoices not for POS in the past).

I’m working off a brand new instance of ERPNext so as far as I’m aware, everything is stock behavior.

On a Sales Invoice, I am not sure if it is possible to apply a percentage tax to each item individually.
Taxes in the “Sales Taxes and Charges” area apply only to the whole invoice.