Item Price changed when duplicate Sales Order

I found some problems occurred recently (around end of 2024). When I duplicate Sales Order, normally item price will be same as original sales order. However, now item price is changed based on price_list_rate (if higher price that price_list_rate, item rate will not change, but if item rate is less that price_list_rate, item rate will be changed to price_list_rate). I have tried setting as follows, but it doesn’t seem to work as expected.

details of issues

  1. Selling Setting
    1.1 Set Enable on Maintain Same Rate throughout Sales Cycle
    1.2 Set Enable on Allow User to Edit Price List Rate in Transactions
  2. Disable All items in Price List
  3. Set rate to 0 on the item
  4. On the sales Order, I set ignore pricing rule already.

    Here are my questions.
  5. How to disable this automated action to set item rate when duplicating Sales Order?
  6. Which table keeps price_list_rate and base_price_list_rate?

Hello, I try to test are you and also can’t find configuration that can prevent changing of price when duplicate.

So, let’s fix the code. From chrome network, we know this method is called when making copy of Sales Order.

http://localhost:8000/api/method/erpnext.accounts.doctype.pricing_rule.pricing_rule.apply_pricing_rule

By testing, I found that by fixing code in pricing_rule.py, to include Sales Order to return , it will work for your case.

So, if you have your own module you can override this whitelist function by these steps,

  1. Add this whitelisted function apply_pricing_rule to your code, i.e., myapp/myapp/custom/pricing_rule.py
import json
import copy
import frappe
from erpnext.accounts.doctype.pricing_rule.pricing_rule import (
    set_transaction_type,
    get_pricing_rule_for_item
)


@frappe.whitelist()
def apply_pricing_rule(args, doc=None):

	...

	if args.get("doctype") in ("Material Request", "Sales Order"):
	# if args.get("doctype") == "Material Request":
		return out

	....

	return out

  1. In hooks.py, declare that you want to override the whitelisted method,
override_whitelisted_methods = {
	"erpnext.accounts.doctype.pricing_rule.pricing_rule.apply_pricing_rule": "myapp.custom.pricing_rule.apply_pricing_rule",
}
  1. bench restart to refresh the hook.

I guess, that’s it. Try to copy again, the overrid method should be used now.