Custom script is not working for the custom field

Hello Everyone,

I have customized the Sales order Item table in the Sales Order form as shown below.

I have included the extra charges custom field in the child table and have also written a custom script for calculating the amount, but it is not calculating properly. When I enter the value in the extra charges field it will calculate, but on saving the document it will not show correct value in the amount and total field.

Below is the custom script.

Can anyone help me with this?

Thanks & Regards,
Sujay

hi

erpnext overriding your custom calculations .
pls try to override the deafult method. :slight_smile:

@AkshayJadhao I didn’t get you… can you please explain me more.

How can I achieve that?

@Sujay you can do your calculations on sales order validate

like i did this

def custom_validate(doc,method):
for item in doc.items:
if item.upcharge_downcharge:
item.amount=item.amount+item.upcharge_downcharge

i hope you know how to call validate of sales order :slight_smile:

Thanks for your quick response.

I’m not good at coding javascripts, can you please help me in this.

@Sujay you have to do this on server side(python)

edit your hooks.py like this

doc_events = {“Sales Order”: {
“validate”: [“app_name.custom.sales_order.sales_order.custom_validate”],
},
}

after this hit bench migrate to terminal
then when you will save doc cusom_validate method will calll

pls make sure you enter your method path right

:slight_smile: