Try ERPNext Try Frappe Cloud Buy Support Partners Foundation

How to change the margin formula


In our company, we calculate the selling price by adding a percentage of margin to the buying price. Entering directly the selling price or margin amount is not an option.

However, it turns out we use the markup rate :

selling price = buying price / (1 - markup rate)

and not the margin rate as used by ERPNext:

selling price = buying price + (margin rate * buying price)

Using the margin rate instead of the markup rate is not an option for the sales team, so I had no choice but to change the formula in the source code.

I find that the computation is done in erpnext/public/js/controllers/taxes_and_totals.js in the function apply_pricing_rule_on_item and modified it. Then, when creating a quotation and adding items to it, that works! Until I hit the “save” button and the prices are saved using the old formula.

I guess I need to modify something else. Can someone help me with that?

Please note, that if there’s a way to achieve my goal without modifying the source code, it would be perfect!

Thanks a lot!

I have implemented similar functionality via adaptions via “Customize Form”, to add additional fields and “Custom Script”.