Hi ERPNext Community,
I am working on a weight-based pricing requirement in ERPNext and would appreciate guidance on the best implementation approach.
Current ERPNext Behavior
ERPNext calculates item amount using the standard formula:
Amount = Qty × Rate
Business Requirement
My requirement is:
Amount = Qty × Rate × Weight Per Unit
Example:
Qty = 2
Rate = 133
Weight Per Unit = 28.2
Amount = 2 × 133 × 28.2 = 7501.20
Current Customization
I added the following custom fields in transaction item tables:
• Weight Per Unit (Float)
• Total Weight (Float)
Using a Server Script (Before Save), I calculate:
Total Weight = Qty × Weight Per Unit
Amount = Qty × Rate × Weight Per Unit
Current Result
The row-level calculation works correctly:
Qty = 2
Rate = 133
Weight Per Unit = 28.2
Total Weight = 56.40
Row Amount = 7501.20
However, ERPNext still appears to use its standard formula (Qty × Rate) when calculating document totals and taxes.
Example:
ERPNext calculates:
Qty = 2
Rate = 133
Net Total = 266
GST = Based on 266
Expected:
Net Total = 7501.20
GST = Based on 7501.20
Grand Total = Based on 7501.20
Issues
✓ Item Amount is correct
✓ Total Weight is correct
✗ Net Total is incorrect
✗ Total is incorrect
✗ GST is calculated using Qty × Rate
✗ Grand Total is incorrect
✗ Rounded Total becomes inconsistent
✗ Amount In Words is incorrect
✗ Rounding Adjustment becomes incorrect
Scope
I need this calculation to work consistently across the complete transaction flow.
Sales Flow:
• Sales Order
• Delivery Note
• Sales Invoice
Purchase Flow:
• Purchase Order
• Purchase Receipt
• Purchase Invoice
Questions
-
Is it possible to completely replace ERPNext’s standard formula (Amount = Qty × Rate) with Amount = Qty × Rate × Weight Per Unit using only Server Scripts?
-
Which ERPNext methods/controllers are responsible for calculating Amount, Net Total, Taxes, Grand Total, Rounded Total, and Amount In Words?
-
Is there a supported customization approach that does not require ERPNext core modifications?
-
Would Hooks, Controller Overrides, Extend Doctype Class, or another framework-supported approach be recommended?
-
Is there any existing ERPNext app, marketplace solution, or open-source implementation that supports weight-based pricing?
-
How can custom fields such as Weight Per Unit and Total Weight be automatically mapped through:
Sales Order → Delivery Note → Sales Invoice
and
Purchase Order → Purchase Receipt → Purchase Invoice
- Has anyone successfully implemented weight-based pricing across the complete buying and selling cycle while keeping taxes, totals, rounding, and amount-in-words calculations working correctly?
Environment
• ERPNext v15 / v16
• Frappe Framework v15 / v16
Any suggestions, implementation examples, GitHub repositories, marketplace apps, or best practices would be greatly appreciated.
Thank you.