def setActivities(self, *args, **kwargs):
def activityDate(activity):<EOL><INDENT>"""<STR_LIT>"""<EOL>try:<EOL><INDENT>return activity['<STR_LIT>']['<STR_LIT>']<EOL><DEDENT>except KeyError as kerr:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>try:<EOL><INDENT>activities = self.mambuactivitiesclass(loanAccountId=self['<STR_LIT>'], *args, **kwargs)<EOL><DEDENT>except AttributeError as ae:<EOL><INDENT>from .mambuactivity import MambuActivities<EOL>self.mambuactivitiesclass = MambuActivities<EOL>activities = self.mambuactivitiesclass(loanAccountId=self['<STR_LIT>'], *args, **kwargs)<EOL><DEDENT>activities.attrs = sorted(activities.attrs, key=activityDate)<EOL>self['<STR_LIT>'] = activities<EOL>return <NUM_LIT:1><EOL>
Adds the activities for this loan to a 'activities' field.

        Activities are MambuActivity objects.

        Activities get sorted by activity timestamp.

        Returns the number of requests done to Mambu.