Frappe Technologies
Screenshot 2023-10-25 at 10.48.41 PM.png
Versioning and Audit Trail
Adding Versioning and Audit Trail in ERPNext
author

By

Rushabh Mehta

·

2 January 2017

·

2

min read

Till 7.3, ERPNext did not have a built in first class version tracking system for documents. The recommended way was making the document Submittable and then amending it when you wanted to change it. This served other purposes too, like submitting something, triggers downstream postings to accounts or stock or other dependant documents, and the document becomes read-only. You can also set different permission rules for submit so it acts as a workflow mechanism.

While the submit workflow is great for transactions, it does cover documents that keep changing, like Customer details, contacts. If someone changes an address you lose the earlier information. If someone changed the credit rating of a customer, then it is important to know who did it when.

Inspiration

Since we use GitHub a lot, we love the way GitHub adds changes to an Issue to the timeline.


This seemed like a really nice way to track changes.

Implementation

Also since Frappé Framework had its own ORM, adding a new event listener seemed like an easy thing to do. So I wrote out a basic todo list on a GitHub Issue.

We already had a basic versioning system with a DocType "Version" but it was only activated for Web Page and Blog Post, so it made sense to extend it.

The implementation is really simple. Everytime a document is saved, and if versions are tracked, the ORM runs a basic difference check on the document structure before and after the update saving:

  1. Properties that changed
  2. Rows added
  3. Rows removed
  4. Properties in child tables that are changed.
Once this information is stored, we load the Version in the timeline along with other communications and render the history, a bit like GitHub


Since document changes can be extensive, only a small fraction of the details are shown and the user can click on the link and see the detailed difference.

Cleanups

The moment I built this, I was obvious that some of the other changes (like adding, removing of assignments, attachments, sharing) should be a part of the Versioning and not Communication. So I just changed the implementation of the add_comment method to update the Version table instead of Communication

Stretch Goal

What was left was deletions, when a document was deleted, currently there was no delete log. So we added  a new document type Deleted Document, that keeps a log of all deleted records. What's more, you can restore them too!


Published by

Rushabh Mehta

on

2 January 2017
2

Share

Add your comment

Success!

Error

Comments

I
Inventore velit irur

· 

May 18, 2022

i love this

Moses Gitonga

· 

March 22, 2020

Thank You Rubash for this

Discussion

image7f7d4e.png

Paul Mugambi

·

3 days

ago

Beautiful read, and an insight into an individual I respect and have learned a lot from. Am inspired to trust the process and never give up.

image4c43d6.png

Anna Dane

·

5 days

ago

I must say this is a really amazing post, and for some of my friends who provide Best British Assignment Help, I must recommend this post to them.

Add your comment

Comment