Amount Calculation in Sales Invoice

Hi all,

Can anyone please help modify the calculation of the Amount in sales Invoice.

As you can see above, I have created a new field Weight.

My requirement is Amount must be equal Weight * Rate instead of Qty* Rate.

Can anyone please help address the above?


Adding Up to the above,

I did the following changes in the taxes_and _totals.js (public/js/controller/taxes_and_totals.js).


Hello Kartive,

You are directly making the changes in the Core ERPNext file. Instead you can do it in customised file as well.

In your customised file for Sales Invoice.js write the below code
On change of weight -
weight : function(frm,cdt,cdn){
d = locals[cdt][cdn]
amt = d.rate * d.weight
frappe.model.set_value(cdt, cdn, “amount”,amt);

Similary, on change of rate as well and set the qty field to be 1 by default and make it readonly. So that user is not allowed to enter the Qty.

Further updating the above, i made similar changes in the in folder controller.

@radhika.g Thanks a lot.

I will be updating the mentioned above.

However, we still need quantity as this is what will be affecting the stock.

Best Regards,

Why don’t you set up a unit of measure with the weight say KG and use the quantity field itself rather than customize

Hi @Pawan,

Actually we have item like Deer/ Beef.

We sell them in terms of Weight(KG). However in Stock we need to have the quantity(Unit).

So, we still need the quantity field for stock and this the reason I created the weight field for the amount calculation.

Any other Idea @Pawan.


Try UOM conversion factor, it may work for you

I can understand where you coming from. I had a similar issue.
You dont have to change anything in the core code.
Try experimenting with UOM or

Add a custom field ratePerKg
Put custom js logic to update rate = ratePerKg x weight x qty
Amount with automatically get updated


Hi @Mohammad_Ahmad_Zulfi,

My Issue is Quantity should be in unit as we receive item in unit.

However when we sell them we sell them in terms of KG.

This is the reason I created the Weight field.

Hence, Amount = Weight * rate.

Can you please share the path of the file to modify to add this logic?

Best regards,

Hi @Pawan,

Thanks for getting back.

We tried the option UoM conversion factor. However, the weight of the items like Beef varies.

This is why we are choosing to customize it.

Best Regards,

UOM conversation wouldn’t work as the stock is maintained in Number but sold in Kg.
This scenario is applicable to all live stock e.g. Poultry/Goat/Pig/Beef farming.

As per knowledge, ERPNext couldn’t handle this scenario although you can do it using custom application.

Hi @sanjay,

Thanks for getting any suggestion how to resolve this issue.

Best Regards,

Hey I have one solution. You wont have to do any customization. Use Batch system.
Each Batch with represent individual item with same name where each item can has its own weight.
Let me try to explain:

you have two type of animals: Goat, Sheep
at the time of receiving:
add goat item multiple times(total goats) and in qty add weight of each goat
same for sheep

  1. Goat qty 25kg rate = 100/kg amount = 2500
  2. Goat qty 24.5kg rate = 100/kg amount= 2450
  3. Goat qty 30kg
  4. Sheep qty 40kg
  5. Sheep qty 35kg
    and so on

on creating purchase receipt it assign batch numbers for each. you can set the series as per your requirement in the item
for example:
Goat-.YYYY.MM.DD- (please verify the format if incorrect)
you can track batch number and its respective remaining qty
benifit: now when you sell, you can select batch and put qty or u may not choose to select batch and erp will automatically pick the batch with qty !=0 automatically

I hope this helps

@Mohammad_Ahmad_Zulfi i will try this thanks :+1:

@Kartive_lfc did you resolve that amount issue?
i have the similar issue need to change the amount on a particular check box(condition=if it checked the 2% of amount should be add in amount itself)…
please guide me if you solve it earlier.
Thanks in Advance