I have created a button to generate a payslip of an employee.
How do I prompt a message to the user to say that the “Payslip successfully generated” after clicking the button?
You must use a wizard for that.
But it is not the common practice in Tryton. The form on which the button is clicked usually shows that it has changed (like the status or a check box etc.).
How to activate a boolean field on clicking the button?
The method of the button should write on this boolean.
You may use Bus Publish - Notification for Show Notification to user
Example Sending Notification
@classmethod
@ModelView.button
@Workflow.transition('draft')
def mark_as_beneficiary(cls, records):
for record in records:
record.is_beneficiary = True
if record.ifsc_code:
regex = re.compile("^[A-Za-z]{4}[a-zA-Z0-9]{7}$")
if (regex.match(record.ifsc_code)):
record.ifsc_code = record.ifsc_code.upper()
else:
record.raise_user_error('Please fill valid IFSC code.')
if record.account_no:
if record.account_no.isnumeric() is False:
record.raise_user_error(
'Account No should be Numeric. Please fill valid Account No.')
The above code is not working as well as not showing any error on clicking the button mark_as_beneficiary. On clicking the button mark_as_beneficiary it should automatically make the boolean field is_beneficiary = True.
Any help regarding the issue will be grateful.
You must call ModelSQL.save
on the records to get the changes persisted.