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.
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.
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:
- Properties that changed
- Rows added
- Rows removed
- 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.
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
to update the Version table instead of Communication
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!