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?
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.
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.
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,
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’