Disclaimer: This is my first step in server-side scripting
I have added a custom field in Item Price and two custom fields in Sales Invoice in the items-child table.
The fields are called rr and rr_amount. The value of rr should come from the used Item Price and should be multiplied by the charged qty to automatically fill in rr_amount
The next step that I need to take is to add all rr_amount-fields on a Sales Invoice and put the sum into another custom field on the main DocType Sales Invoice called rr_grand_total But before I can start to figure out this I need to get the script working. I’ve already spent a lot of hours trying to fix this by using a Client Script, before finding out that the behavior I’m looking for should be handled by a Server Script.
I’ve managed to get the Server Scripts active on our ERPNext v13 setup so I could start writing my first Server Script:
This is what I have now:
Script Type: DocType Event
Reference Document Type: Sales Invoice
DocType Event: Before Save
Script:
def calculate_child_table_values(doc, method):
for row in doc.items:
row.rr_amount = row.qty * row.rr
and the script shows enabled.
I would not be here if this was working so nothing happens at all in the rr_amount-field.