Auto Calculate Selling Prices?

Hello ,
I am trying to use erpnext for my small pharmacy.
I am not sure if i overlooked or something , i see no option to auto calculate selling prices based on last buying price or average valuation or something like that . Do i need to set selling price manually for all items (thousands) ? I tried with item price , price list and pricing rules . Still no luck . Am i missing something? I want to sell with different prices to different customers like retail and whilesale . For pricing rules to work , it needs some base value i think . If i manually set standard selling prices , it works fine which i don’t think is convenient as i have thousands of items (which have more than one UoM too) . Item price rates are also needed to enter manually . Please help me clarify things . Are there anything like selling price based on buying price or all people adding selling prices manually?Or i am so stupid i can’t make it work?

Thanks in advance .

I asked ChatGPT and it recommended this client script: -

frappe.ui.form.on(“Item”, {
refresh(frm) {
if (frm.doc.last_purchase_rate) {
add_auto_price_button(frm);
}
},
validate(frm) {
// Auto-create prices when saving also
create_auto_prices(frm);
}
});

function add_auto_price_button(frm) {
frm.add_custom_button(“Auto Generate Selling Prices”, () => {
create_auto_prices(frm, true);
}).addClass(“btn-primary”);
}

function create_auto_prices(frm, show_msg) {

let cost = frm.doc.last_purchase_rate || frm.doc.valuation_rate || 0;

if (!cost) {
    frappe.msgprint("No cost found (Last Purchase or Valuation). Cannot generate prices.");
    return;
}

// ---- YOUR MARGINS HERE ----
let retail_price = cost * 1.20;      // +20%
let wholesale_price = cost * 1.10;   // +10%

let price_updates = [
    {
        price_list: "Retail",
        price_list_rate: retail_price
    },
    {
        price_list: "Wholesale",
        price_list_rate: wholesale_price
    }
];

frappe.call({
    method: "frappe.client.insert",
    args: {
        doc: {
            doctype: "Item Price",
            item_code: frm.doc.name,
            price_list: "",        // Overwritten in loop
            price_list_rate: 0     // Overwritten in loop
        }
    },
    freeze: true,
    freeze_message: "Updating Item Prices...",
    callback: function () {
        // Insert or update prices one-by-one
        update_loop(frm.doc.name, price_updates, show_msg);
    }
});

}

function update_loop(item_code, price_updates, show_msg) {
price_updates.forEach(p => {
frappe.call({
method: “frappe.client.get_list”,
args: {
doctype: “Item Price”,
filters: {
item_code: item_code,
price_list: p.price_list
},
limit: 1
},
callback(r) {
if (r.message && r.message.length > 0) {
// Update existing Item Price
let item_price_name = r.message[0].name;

                frappe.call({
                    method: "frappe.client.set_value",
                    args: {
                        doctype: "Item Price",
                        name: item_price_name,
                        fieldname: "price_list_rate",
                        value: p.price_list_rate
                    }
                });
            } else {
                // Create new Item Price
                frappe.call({
                    method: "frappe.client.insert",
                    args: {
                        doc: {
                            doctype: "Item Price",
                            item_code: item_code,
                            price_list: p.price_list,
                            price_list_rate: p.price_list_rate
                        }
                    }
                });
            }
        }
    });
});

if (show_msg) {
    frappe.msgprint("Selling prices updated based on last purchase rate.");
}

}

Best of luck

thanks for helping me out. I will try .

I tried odoo 19 and i can’t sell in POS with multiple UOM . In erpnext i can do so but can’t set selling price automatically like in odoo . Well at least not free .