Since the secondary update needs to occur on the users collection, it's appropriate to define the listener in the UserService class already defined. We add a new method, updateBorrowerListener(), which is later subscribed as a listener. Note that the argument to the listener is arg, in order to match that defined in our Publisher wrapper class described in the section just before.
We first import the Python classes to convert between Decimal and Decimal128:
def updateBorrowerListener(self, arg) :
from decimal import Decimal
from bson.decimal128 import Decimal128
We then initialize two sets of two values representing amounts due, and amounts paid, as defined by information from the users collection and also the loans collection:
loan = arg['loan']
amtPaid = arg['amtPaid']
amtDueFromLoan = Decimal(0.00)
amtPaidFromLoan = Decimal(0.00)
amtDueFromUser = Decimal(0.00)
...