How to reset company transaction

like in erpnext we can reset company transaction how to achieve that in dokos

Hi @Shuhain_Ismail,

Unlike ERPNext, Dokos doesn’t allow resetting all company transactions as it is not compliant with french law.
You need to reinstall your site to have a clean state.

Have a nice day

hi is there any sql Quary that i can use it
coz i did lots of changes and did a demo run that all the functions are working like to do reset on all transaction before we can use it
it will take lot of time to setup it again

Hi @Shuhain_Ismail,

Unfortunaltely, one SQL query won’t be enough.
I invite you to check the implementation done by ERPNext to make a similar implementation in a custom application: erpnext/erpnext/setup/doctype/transaction_deletion_record at develop · frappe/erpnext · GitHub

Have a nice day

Delete All Company Transactions in Dokos (for Testing & Reset)

Purpose:
This utility script is designed for developers and testers using Dokos ERP. It safely deletes all transactional data tied to a specific company, while preserving master data (like items, customers, employees, etc.).

This is useful when:
You’re resetting a test/demo site
You want a clean company slate after trial runs
You’re preparing for new migrations or data imports

:warning: Warning
Use only in test or development environments.
This will permanently delete all transactional data for the specified company.
Always back up your database first!

:receipt: Script

company_name = "RanBiz"  plz change to your company name there

run in bench console.

import frappe

def clean_company_transactions():
    company_name = "RanBiz" ##change to your company name

    excluded_doctypes = {
        "Account", "Cost Center", "Warehouse", "Budget", "Party Account", "Employee",
        "Sales Taxes and Charges Template", "Purchase Taxes and Charges Template",
        "POS Profile", "BOM", "Company", "Bank Account", "Item Tax Template",
        "Mode of Payment", "Mode of Payment Account", "Item Default", "Customer",
        "Supplier", "Salary Component Account", "Salary Structure",
        "Salary Structure Assignment", "Payroll Period", "Income Tax Slab",
        "Leave Period", "Leave Policy Assignment", "Employee Onboarding Template",
        "Employee Separation Template"
    }

    ledger_doctypes = [
        "GL Entry", "Stock Ledger Entry", "Payment Ledger Entry"
    ]

    print(f"\n🔍 Scanning transactional doctypes for: {company_name}")
    transactional_doctypes = []
    for dt in frappe.get_all("DocType", filters={"issingle": 0}, pluck="name"):
        if dt in excluded_doctypes:
            continue
        try:
            if frappe.db.has_column(dt, "company"):
                transactional_doctypes.append(dt)
        except frappe.db.TableMissingError:
            continue

    print(f"\nđź§ą Deleting documents from {len(transactional_doctypes)} doctypes...\n")
    for doctype in transactional_doctypes:
        try:
            names = frappe.get_all(doctype, filters={"company": company_name}, pluck="name")
            print(f"đź“„ {doctype} - {len(names)} records found")
            for name in names:
                try:
                    doc = frappe.get_doc(doctype, name)
                    if doc.docstatus == 1:
                        doc.cancel()
                    doc.delete()
                    print(f"âś… Deleted {doctype} {name}")
                except Exception as e:
                    print(f"⚠️  Failed to delete {doctype} {name}: {e}")
        except Exception as e:
            print(f"⚠️  Skipping {doctype} due to error: {e}")

    for ledger in ledger_doctypes:
        try:
            deleted = frappe.db.delete(ledger, {"company": company_name})
            print(f"đź§ľ {ledger} - Cleared: {deleted}")
        except Exception as e:
            print(f"⚠️  {ledger} - Error: {e}")

    # General orphaned child cleanup
    print("\nđź§ą Checking for orphaned child rows...")
    child_tables = frappe.get_all("DocType", filters={"istable": 1}, pluck="name")
    for child_table in child_tables:
        try:
            if not (frappe.db.has_column(child_table, "parent") and frappe.db.has_column(child_table, "parenttype")):
                continue

            parenttypes = frappe.db.get_all(child_table, distinct=True, pluck="parenttype")
            for parenttype in parenttypes:
                if not frappe.db.has_column(parenttype, "name"):
                    continue  # skip if parent DocType is not real

                orphaned_rows = frappe.db.sql(f"""
                    SELECT name FROM `tab{child_table}`
                    WHERE parenttype = %s AND parent NOT IN (
                        SELECT name FROM `tab{parenttype}`
                    )
                """, (parenttype,), as_dict=True)

                for row in orphaned_rows:
                    frappe.db.delete(child_table, {"name": row.name})
                    print(f"🗑️  Deleted orphaned row in {child_table}: {row.name}")

        except Exception as e:
            print(f"⚠️  Error checking {child_table}: {e}")

    # Clean up logs and attachments
    try:
        frappe.db.delete("Communication", {"company": company_name})
    except: pass
    try:
        frappe.db.delete("File", {"attached_to_doctype": ("!=", ""), "attached_to_name": ("!=", "")})
    except: pass
    try:
        frappe.db.delete("Email Queue")
        frappe.db.delete("Email Queue Recipient")
        frappe.db.delete("Activity Log")
    except: pass

    frappe.db.commit()
    print(f"\nâś… Database cleanup completed for: {company_name}")

# Run it
clean_company_transactions()

To finalize cleanup after exiting bench console, run the following commands from your Dokos bench directory:

bench --site site-name migrate
bench --site site-name clear-cache

2 « J'aime »

Hi everyone!
I’ve developed a standalone app called transaction_tools to simplify the process of deleting test or unwanted transactional data in Dokos

:wrench: What it does:

  • Clears all transactional records for a selected company (GL Entries, Invoices, Stock, etc.)
  • Useful during development, testing, or resetting a company’s data
  • Clean interface with task-specific toggles
  • Designed for Dokos v4

:dart: Use cases:

  • Resetting test environments
  • Cleaning up training/demo data
  • Quickly wiping out trial transactions during implementation

The app is cleanly packaged, includes workspace shortcuts, and is easy to install.

:point_right: Check it out: GitHub - shuhain85/transaction_tools

Would love to hear your thoughts, feedback, or contributions! :speech_balloon:
Let me know if it helps your workflow or if you’d like to see more features added.

2 « J'aime »