I have a custom script in my app for purchase invoice which add incentive and do other things, but when trying to submit the doc, i’m getting update after submit, The Script Add a amount in a custom feild when update,
def update_commission(doc, change):
new_total = (doc.custom_commison or 0) + change
frappe.db.set_value(
"Purchase Invoice",
doc.name,
"custom_commison",
new_total,
update_modified=False
)
why is it not working ? in my server script.
Actually, something is working or some value is being updated in a field (either in Python or JavaScript). Please check all your code in the Purchase Invoice and its related events as well. Its coming from your code.
Have you marked “custom_commison” allow on submit in customization if you have to update the value after the document is submitted
the below code runs on the Purchase Invoice Submission.
- We generate 500rs incentive for each Pur Invoice for the Person namein the field custom_purchase_by- this is working fine.
- but after the creation of incentive, the current Pur Invoice Document changes to ‘Update’ state from ‘Submit’ State - Why this is happening as we are posting the data direclty in database using frappe.db.set_value
import frappe
from frappe import _
from frappe.utils import getdate, nowdate, add_days
import calendar
frappe.utils.logger.set_log_level(“DEBUG”)
logger = frappe.logger(“api”, allow_site=True, file_count=50)
def on_submit_purchase_invoice(doc, method):
"""
Create purchase Incentive when Purchase Invoice is submitted
"""
if doc.custom_docsfine_status == "Completed" and doc.custom_purchase_by:
if not frappe.db.exists("Purchase Incentive", {"purchase_invoice": doc.name}):
incentive = frappe.new_doc("Purchase Incentive")
incentive.purchase_user = doc.custom_purchase_by
incentive.purchase_invoice = doc.name
incentive.amount = 500
incentive.insert()
\# Update submitted document field
frappe.db.set_value(
"Purchase Invoice",
doc.name,
"custom_commison",
(doc.custom_commison or 0) + (incentive.amount or 0),
)
frappe.msgprint(f"Purchase Incentive {incentive.name} created for {doc.custom_purchase_by} with amount {incentive.amount}.")
Yes i marked it Allow on submit
Pls check my comments and code, all support will be highly appreciated.
Hi @Abubakar_Falah
I can suggest two possible solutions that may work:
-
Enable the “Allow Submit” option for that field.
-
Use frappe.db.commit() after performing the necessary operations.
Thank You!