(OFBIZ-12178)
This is a manual backport of the related two commits in trunk with minor changes to fit the r18.12 codebase.