Code autogeneration by backend
Introduction
In scope of modular implementation in Nepal support for claim code autogeneration was added. This article will describe the way it works and will provide tips to implement this feature in other modules if needed.
Backend - changes to core module and signals
Firstly, let’s describe few changes that had to be made to the general core module and its component for the whole mechanism to work. First of all, code handling mutation was changed in a following way:
# TODO this code is necessary for autogenerate functionality to work
# TODO General mutation code should be reworked
if mutation_data.get('autogenerate', False) and isinstance(messages, Dict):
data.update(messages)
error_messages = None
else:
error_messages = messages
Thanks to this we can use result of mutation to change logs afterwards - code handling creation of claim is generating claim code, but this is not available during creation of the log, so this workaround was needed.
Notice that ‘autogenerate’ is needed (to exist and to be equal to True) as an argument in any mutation that will use this mechanism. This name is generic, so it can be used in any module without problems.
Thanks to this data when we are creating claim we can add following code: