Updating workflow state via custom scripts gives error "Cannot change docstatus from 1 to 0"

I created a workflow where the actions are triggered via custom buttons, not the default workflow actions dropdown. I need it this way because before approving, I need to show a confirmation pop-up so I will only proceed with the workflow state change if the approver clicks yes. And if approver declines, I will show a pop-up to write the reason.

Now, whenever the approver approves it, it shows this error:

File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 660, in check_if_latest
    self.check_docstatus_transition(tmp.docstatus)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 699, in check_docstatus_transition
    raise frappe.DocstatusTransitionError(_("Cannot change docstatus from 1 to 0"))
frappe.exceptions.DocstatusTransitionError: Cannot change docstatus from 1 to 0

This is my custom script:
image

Additional information of the workflow:

States:
image

Transitions:
image

Edit:
The error only shows up if I use the custom script. It’s fine when I approve using default action buttons (the dropdown)

image

Found the solution for this.

instead of using:
frm.set_value({
workflow_state: “State”
});
cur_frm.save();

Update the workflow using frappe.db.set_value():

frappe.db.set_value(‘Doctype’, frm.doc.name, ‘workflow_state’, ‘Approved by Accounting’)