Versioning and Audit Trail

Adding Versioning and Audit Trail in ERPNext

By Rushabh Mehta January 2, 2017 ERPNext Features No comments yet

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!


Rushabh Mehta
Rushabh Mehta
"Rushabh is a software developer and founder of ERPNext. He usually writes about the startup experience, open source and the technologies he is working on."
No comments yet

No comments yet. Start a new discussion.

Add Comment