nodes: 0, module; 1, function_definition; 2, function_name:setRepayments; 3, parameters; 4, block; 5, identifier:self; 6, list_splat_pattern; 7, dictionary_splat_pattern; 8, expression_statement; 9, function_definition; 10, try_statement; 11, expression_statement; 12, expression_statement; 13, return_statement; 14, identifier:args; 15, identifier:kwargs; 16, comment:"""Adds the repayments for this loan to a 'repayments' field.
  
          Repayments are MambuRepayment objects.
  
          Repayments get sorted by due date.
  
          Returns the number of requests done to Mambu.
  
  .. todo:: since pagination logic was added, is not always true that
            just 1 request was done. It may be more! But since request
            counter singleton holds true information about how many requests
            were done to Mambu, in fact this return value may be obsolete
          """; 17, function_name:duedate; 18, parameters; 19, block; 20, block; 21, except_clause; 22, assignment; 23, assignment; 24, integer:1; 25, identifier:repayment; 26, expression_statement; 27, try_statement; 28, expression_statement; 29, as_pattern; 30, block; 31, attribute; 32, call; 33, subscript; 34, identifier:reps; 35, comment:"""Util function used for sorting repayments according to due Date"""; 36, block; 37, except_clause; 38, assignment; 39, identifier:AttributeError; 40, as_pattern_target; 41, import_from_statement; 42, expression_statement; 43, expression_statement; 44, identifier:reps; 45, identifier:attrs; 46, identifier:sorted; 47, argument_list; 48, identifier:self; 49, string; 50, return_statement; 51, as_pattern; 52, block; 53, identifier:reps; 54, call; 55, identifier:ae; 56, relative_import; 57, dotted_name; 58, assignment; 59, assignment; 60, attribute; 61, keyword_argument; 62, string_content:repayments; 63, subscript; 64, identifier:KeyError; 65, as_pattern_target; 66, return_statement; 67, attribute; 68, argument_list; 69, import_prefix; 70, dotted_name; 71, identifier:MambuRepayments; 72, attribute; 73, identifier:MambuRepayments; 74, identifier:reps; 75, call; 76, identifier:reps; 77, identifier:attrs; 78, identifier:key; 79, identifier:duedate; 80, identifier:repayment; 81, string; 82, identifier:kerr; 83, call; 84, identifier:self; 85, identifier:mamburepaymentsclass; 86, keyword_argument; 87, list_splat; 88, dictionary_splat; 89, identifier:mamburepayment; 90, identifier:self; 91, identifier:mamburepaymentsclass; 92, attribute; 93, argument_list; 94, string_content:dueDate; 95, attribute; 96, argument_list; 97, identifier:entid; 98, subscript; 99, identifier:args; 100, identifier:kwargs; 101, identifier:self; 102, identifier:mamburepaymentsclass; 103, keyword_argument; 104, list_splat; 105, dictionary_splat; 106, identifier:datetime; 107, identifier:now; 108, identifier:self; 109, string; 110, identifier:entid; 111, subscript; 112, identifier:args; 113, identifier:kwargs; 114, string_content:id; 115, identifier:self; 116, string; 117, string_content:id
code: def setRepayments(self, *args, **kwargs):
          """Adds the repayments for this loan to a 'repayments' field.
  
          Repayments are MambuRepayment objects.
  
          Repayments get sorted by due date.
  
          Returns the number of requests done to Mambu.
  
  .. todo:: since pagination logic was added, is not always true that
            just 1 request was done. It may be more! But since request
            counter singleton holds true information about how many requests
            were done to Mambu, in fact this return value may be obsolete
          """
          def duedate(repayment):
              """Util function used for sorting repayments according to due Date"""
              try:
                  return repayment['dueDate']
              except KeyError as kerr:
                  return datetime.now()
  
          try:
              reps = self.mamburepaymentsclass(entid=self['id'], *args, **kwargs)
          except AttributeError as ae:
              from .mamburepayment import MambuRepayments
              self.mamburepaymentsclass = MambuRepayments
              reps = self.mamburepaymentsclass(entid=self['id'], *args, **kwargs)
  
          reps.attrs = sorted(reps.attrs, key=duedate)
          self['repayments'] = reps
  
          return 1