How to update Item Price

Hi team,
I have a question. Does it works when you change the item’s price in the Sales Invoice item table it’s changed automatically in the Item Price document?
Thanks for your answers.

No.

But if there is none, it will create one using the sales invoice item price.

1 Like

thank you

I’ve been using this custom script:

Does this help? This asks if you want to update price list, if different.

frappe.ui.form.on("Sales Invoice", "on_submit", function(frm) {
            $.each(cur_frm.doc.items || [], function(i, v) { // for each item on table do this
                var precoAntigo;
                frappe.call({
                    method: "frappe.client.get_list",
                    args: {
                        doctype: "Item Price",
                        filters: [
                            ['price_list', "=", cur_frm.doc.selling_price_list],
                            ["item_code", "=", v.item_code],
                        ],
                        fields: [

                            "price_list_rate",
                            "name"

                        ]
                    },
                    callback: function(r) { // do this to found price list doc
                        precoAntigo = (r.message[0].price_list_rate);
                        var nomelista = r.message[0].name
                        // console.log(precoAntigo)
                        if (precoAntigo && precoAntigo != v.rate) {
                            frappe.confirm(
                                `Deseja atualizar o preço do item ${v.item_name} de ${ precoAntigo } para ${ v.rate} na lista de preços ${cur_frm.doc.selling_price_list} ?`, //ask something to update price
                                function() { // do this if ok
                                    frappe.db.set_value("Item Price", nomelista, "price_list_rate", v.rate)
                                },
                                function() { // do nothing if cancel

                                }

                            )
                        }
                    }
                });
            })
})
5 Likes

Yes, that’s very helpful. Thank you very much. I was thinking about the custom script too but you solved it for me)))

Mr. Outerlook, would you please be kind and tell us where and ow to add the custom script to make this working, thanks.

Go to custom script and you can add this script to the relevant document.

If you see in the Script the doctype is mentioned, which is Sales Invoice. So select Sales Invoice and you can write your code.

1 Like