Performing validations/changes on every `GL Entry`

Hi:

I have this issue:

I would like to make some extra validation (and eventual change of data) on the GL Entry records (documents) that should be performed no matter the source of the document that writes them (ie: Journal Entry, Payment, Invoice, etc).

What is the best way to do it without modifying Frappe/ERPNext source code?

Please, let me explain in detail:

For certain Account records (documents) we have extra fields that optionally define a required Party Type and Party.

Now, when any GL Entry has those specific Accounts there should be a validation to check whether those fields are set or not, to write them using the defined for the Account, or warn the user if the received don’t match the specification.

I’m stuck on what mechanism to use for this case. I have been able to write a Server Script customization for the Journal Entry associated to its DocType Event Before Validate.

The reason I don’t try the same for other documents like Invoices and Payments is that I think there is always the chance that other document does not verify our requirement.

That’s why I’m thinking of perform that validation on the GL Entry. However using the same type of customization, the script is not validated, in fact, it seems it never gets called.

Is it possible to make that validation on GL Entry? Hopefully, using the customization options instead changes on the source code or custom apps.

Thank you!

Hey everyone.

After diving on the docs I’m making progress. I’m able to confirm I get my server side script called on a GL Entry.

Here I show a working simple test that shows the Account on the GL Entry

However, I’m stuck on changing the data. In the above example the: doc. set('account', 'Some valid value for account') does not throw any error. It simply gets ignored.

I have tried doc.account = "blah" but that produces an exception as doc.account is evaluates as none.

Anybody can throw me any light on this?

Now my issue is how to change a value of a field on the GL Entry via a server side script?

Please disregard all this.

The script from the last post actually works with either doc.set or doc.update.
The data on the DB is written.

I was confused as I was checking the field content of the document that requested the GL Entry (In my case the Journal Entry), not the actual GL Entry.

I’m leaving for reference if anyone else stumble with something like this. It was quite hard for me to find an example for this use case.