Custom script to update price list rate of items. in purchase Purchase Receipt

I am using. buying price rate. of items in purchase Purchase Receipt.
to update default selling price list rate of item

I use that client script

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


                    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) {
                                `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



but it is work  the  selling price rate in pos. doesn't changed. 

any help

There is a setting to change prices automatically. Did you check it?

thank you for reply

what is that setting
i check many setting but no thing work
can you mention it
may be i didnt use

Stock Settings

it works only for first time means if not add before
after that you must update it from item price itself

so i search for script

Again, for items that regularly change prices, use batches. There is no need for this script.
Enable batch for that certain item, everytime you purchase it assign a batch number to update the valuation rate of that batch.
During sale, your price will depend on the batch you selected for that item

Did you check “Update Existing Price” ?

yes checked

brother its time consuming and no need for it we need the most logic thing in any retail
to change selling price
in Purchase Receipt doc