when i insert data of new doctype before the data insert i want add some data form read-only field of this doc
Hi,
If your data is static, you set up the same in default value.
Else, you can set the value via Server script on submit.
Thanks,
Divyesh Mangroliya
i want to add Transaction number in gl entry based on previous Transaction “number +1”
Hi,
You can do it with below code:
import frappe
from erpnext.accounts.general_ledger import GLEntry
class CustomGLEntry(GLEntry):
def before_insert(self):
self.transaction_number = self.get_next_transaction_number(self.transaction_type)
def get_next_transaction_number(self, transaction_type):
# Get the last transaction number for the given transaction type
last_transaction = frappe.db.get_value('GL Entry',
filters={'transaction_type': transaction_type},
fieldname='transaction_number',
order_by='transaction_number desc')
if last_transaction:
# Assuming transaction numbers are integers, increment by 1
next_transaction_number = int(last_transaction) + 1
else:
# If no previous transaction number exists, start from 1 (or any other base number)
next_transaction_number = 1
return next_transaction_number
Thanks,
Divyesh Mangroliya
thanks for your response i will try