Fetch Sales Order value to Sales Invoice Item Table


i would like to fetch Sales Order Po no to sale invoice item table individual item row.
i have create a custom field, customer order po no under sales invoice item table (customer_po_item) and add the below
custom script under Sales Invoice Item and it seen not works.

frappe.ui.form.on(“Sales Order”, “po_no”, function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, “customer_po_item”);

Did i do something wrong? any advice?

The script should be in the ‘Sales Invoice’ type, not ‘Sales Invoice Item’. Also, the script should point to the Sales Invoice, like so:

frappe.ui.form.on("Sales Invoice", "po_no", function(frm, cdt, cdn) {
       var d = locals[cdt][cdn];
       frappe.model.set_value(cdt, cdn, "customer_po_item");

Not sure about the rest of your custom script though.

Hi Cpurbaugh,

Thanks for the quick advice. i have follow your advice to add the script under ‘Sales Invoice’. still not lucky to make this work. did my script got issues? how i should link it to sales invoice table item column? as i create " customer_po_item" under sales invoice item forms.

I’m not sure. Child tables are tricky. I don’t think your field names are correct for what you are trying to do but I’m not sure.

can further advice how i can use the custom script below?
such as field and syntax?
as i not so sure as i read through from the previous discussion and try to modify from there.

frappe.ui.form.on(“Sales Invoice”, “po_no”, function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, “customer_po_item”);

Why you want “po_no” in the Sales Invoice Item table? You can add the field in the Sales Invoice table. And if you maintain the same fieldname in SO and SI, the value should be copied automatically (if no_copy unchecked).

Hi Nabinhait,

Thanks for advice. i manage sort this out with your advice:)

Hi Nabin

I am trying to get the below script working. Could you point me to the right way?

This script is created for doctype ‘Sales Invoice’

frappe.ui.form.on(“Sales Invoice Item”, “rate”, function(frm, cdt, cdn){
var row = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, vat_value, row.rate * 0.05);

I am trying to get the ‘vat_value’ to get populated when we change the ‘rate’ in the item table.

KR Fasil

vat_value should be wrapped with double quote.

By the way, Are you doing the changes for the UAE VAT? Then for your information, we are also adding vat rate and value column in Invoice Item table to show it in the print format.

1 Like


Many thanks for the update. It worked!!! :smile:

Yes, I have actually added both the columns, vat rate and vat value. Is it possible to autofill the corresponding vat of an item when a new item is added to the row?

when will be this changes, vat rate and vat value in invoice item table ,pushed to the master?

Released it yesterday into master :slight_smile:

@nabinhait Will that work only for UAE localization?

Yes, UAE and Saudi Arabia

Thank you team for your efforts :hugs:

1 Like

@nabinhait any hint on how to get total net amount per tax?

Refer item_wise_tax_detail field in Tax table

@nabinhait unfortunately it doesn’t work in my case :frowning:.

I’m looking for the total net amount on which tax are calculated, let’s have an example:

Let’s suppose there are 3 items in a Sales or Purchase Invoice

Item1 for a net total amount of $100.00 and VAT @ 20%
Item2 for a net total amount of $50.00 and VAT @ 10%
Item3 for a net total amount of $150.00 and VAT @ 20%

So the total net amount on which taxes are calculated are:

$250.00 for VAT @ 20% => VAT @ 20% = $50.00
$50.00 for VAT @ 10% => VAT @ 10% = $5.00

in item_wise_tax_detail i can find tax value per item, what i need is the total amount which generate that tax amount; in the example above $250.00 for VAT@20% and $50.00 for VAT@10%