Edit Submitted Documents

How to edit dependable value of submitted documents.


As shown in picture, “Transport Allowance” is calculated if “TA provided” is set to Yes. I have customized with hooks.py. This works only after saving the document. This hooks code will not work if edited after submitting the document.
Any solution?

Enable allow on submit option in Doctype/customize form

image

Yes, this option enables fields to be editable, but i need to auto update the fields which are dependent on field which is enabled “Allow on Submit”.
In above picture, field “TA Provided” is set to “Allow on Submit”, the field “Transport Allowance” should be changed to zero when we set “TA Provided” to “No”. But even after we alter the of “TA Provided”, the field “Transport Allowance” remains same as that was before Submitting the document.

Can you please share the snippet of your code? It will help us to understand the issue more clearly.
Thanks

In the above picture 2nd column fields are set as “Allow on Submit”, and 3rd column fields are dependent on these fields, 3rd column field should get changed if we change 2nd column fields.
I am using hooks as follows:

After submitting the salary structure assignment, we have to avail employee with food allowance…
I have created above fields and created the above code, and it 3rd column fields will be fetched into salary slips.
The code works perfectly before submit and after save. But after submit even if I change 2nd column fields the 3rd column fields remain unchanged.
image

Ex: I above picture, if “Company Accommodation” is No, Food Allowance will not be provided, and if it yes it should assign the value 300. I am using the code,
image

"Salary Structure Assignment": 
{
    "validate": "indipco.hooks_call.salary_structure_assignment.calculate_gross_salary"
},

after submit if you want to change values (and you know what you are doing) use do a frappe.db.set_value e.g.

def on_validate_salary_structure_assignment(doc, method):
    frappe.db.set_value(doc.doctype, doc.docname,ind_food_allowance,300 if doc.ind_company_accommodation=="Yes" else 0 )

I have tried to add your code but unable to understand to use “self.doctype” and “self.docname”
Below is the code and hook lines, could you please tell me where should I use the above code:

from future import unicode_literals
import frappe
from frappe import _
from frappe.model.document import Document
from datetime import datetime
from datetime import timedelta

#@frappe.whitelist(allow_guest=True)

def calculate_gross_salary(self,method):

    if self.ind_company_accommodation=="Yes":
        self.ind_food_allowance=300
    else:
        self.ind_food_allowance=0

    if self.ind_housing_allowance_provided=="Yes":
        self.ind_hra=self.base*0.25
    else:
        self.ind_hra=0

    if self.ind_transportation_allowance_provided=="Yes":
        if self.base<15001:
            self.ind_transport_allowance=self.base*0.10
        else:
            self.ind_transport_allowance=1500
    else:
        self.ind_transport_allowance=0
        
    self.ind_gross_salary=self.base+self.ind_food_allowance+self.ind_hra+self.ind_transport_allowance+self.ind_mobile_allowance+self.ind_hardship_allowance


{
    "validate": "indipco.hooks_call.salary_structure_assignment.calculate_gross_salary"
},

Kindly add the hooks function if required or please add your code in above function.
This will help me to understand.

edited reply above to use doc. instead of self. Create your method in any file and use the dotted path to the method in your custom app hooks.py. e.g. on_submit hook in erpnext hooks.py for ‘Stock Entry’

1 Like

I appreciate your help.
Thank you very much.

I tried with “on_submit” and “onload”, “onload” is working perfectly

"Salary Structure Assignment": 
{
    "onload": "indipco.hooks_call.salary_structure_assignment.calculate_gross_salary"
},