500 server error on doc.save() or doc.submit()


when i try to save or submit a doctype using server script from another doctype, i get 500 error.

i have a doctype called ‘Payment’. In my payment.py, i have

from new_app.new_app.doctype.application.application import update_payment

class Payment(Document):
    def validate(self):
        ...... (other line of codes and conditions)

def make_payment(docname,amount):
    if req_amount==paid_amount:

and in my application.py i have

def update_payment(docname,amount):
	doc = frappe.get_doc("Application",str(docname))
	doc.append('payment', {
		"mode_of_payment": "Cash",
		"paid_amount": amount

i get 500 internal server error for this. if i remove the doc.save(), there is no error, but the child table record doesnt get appended.

What might be the reason?

What do your log files show as the cause of the error.

Do you have NGinx in front of ERPNext? 500 Errors arise from the proxy server. I don’t think ERPNext emits them.

Meanwhile … does your DocType “Application” actually exist? Is docname actually naming something that exists? Does it have a child table called payment?

please try to simulate in bench console by calling the function update_payment with hard coded docname and amount.

yes, i have nginx and i am running a production server. and yes, the doctypes and the child table payment do exist.

hmm… that’s a good idea… i dint use bench console much earlier… i can now see that there is an error in another function which is part of validate. let me correct it and update here.

yes it worked now. i was able to understand the issue from bench console and fix it accordingly. Thanks @MartinHBramwell and @szufisher

Hah! There ya go! I’m not as dumb as I look.

1 Like