Adds the "holder" of the loan to a 'holder' field.

        Holder may be a MambuClient or a MambuGroup object, depending on
        the type of loan created at Mambu.

        getRoles argument tells this method to retrive the clients who
        have specific roles in the group, in case of a group holder.

        getClients argument tells this method to retrieve the client
        members of the group, in case of a group holder. See the
        definition of the 'clients' field added with this argument
        below.

        fullDetails argument works for Client Holder and for the client
        members of the group. But the Group is always retrieved with
        full details.

        When using getRoles argument also adds a 'roles' field to the
        holder, a dictionary with keys:

        * 'role' , the rolename

        * 'client', a MambuClient having that role on the group

.. todo:: since the roles field is added to the holder, and it only
          applies to Groups, perhaps the getRoles functionality should be
          on MambuGroup code

        When using getClients argument, also adds a 'clients' field to
        the loan. By the way it works, when holder is a Group, it calls
        the setClients method, which adds a 'clients' field to the
        MambuGroup.

        The 'clients' field on the loan is a dictionary with the full
        name of each client receiving from this loan account as a key
        (see the 'name' field on MambuClient and MambuGroup). Each key
        holds another dictionary with the following keys:

        * 'client' holds a MambuClient. So even if a group is the holder
          of the account, you can access each individual client object
          here.

        * 'loan' holds a reference to this loan account (self)

        * 'amount' defaults to the total loan amount ('loanAmount'
          field) (see the pydoc for getClientDetails method)

        * 'montoPago' defaults to the total loan amount divided by the
          number of repayment installments of the loan account (the
          'repaymentInstallments' field), that is, how much to pay for
          each repayment installment (see the pydoc for getClientDetails
          method)

.. todo:: change the name to an english name

        * 'porcentaje' defaults to a 100%, the total loan amount divided
          by itself, that is, hoy much in percentage of the debt belongs
          to this client (see the pydoc for getClientDetails method)

.. todo:: change the name to an english name

        This three fields are supposed to reflect individual numbers for
        each client, but Mambu does an awful job indicating this on
        group loan accounts. So you should indicate how much you
        assigned to each client in other ways. Using the notes of the
        loan account perhaps (with a predefined format you parse on the
        preprocessing of MambuLoan)? with custom fields? Your call that
        you may define making your own loan account class inheriting
        from MambuLoan class. See the pydoc for getClientDetails method
        below, it specifies the way to determine the amount for each
        client depending on your use of Mambu, and additionally any
        other fields you wish to add to the 'clients' field on the loan
        account.

        Returns the number of requests done to Mambu.

.. todo:: what to do on Hybrid loan accounts?

def setHolder(self, getClients=False, getRoles=False, *args, **kwargs):
        """Adds the "holder" of the loan to a 'holder' field.

        Holder may be a MambuClient or a MambuGroup object, depending on
        the type of loan created at Mambu.

        getRoles argument tells this method to retrive the clients who
        have specific roles in the group, in case of a group holder.

        getClients argument tells this method to retrieve the client
        members of the group, in case of a group holder. See the
        definition of the 'clients' field added with this argument
        below.

        fullDetails argument works for Client Holder and for the client
        members of the group. But the Group is always retrieved with
        full details.

        When using getRoles argument also adds a 'roles' field to the
        holder, a dictionary with keys:

        * 'role' , the rolename

        * 'client', a MambuClient having that role on the group

.. todo:: since the roles field is added to the holder, and it only
          applies to Groups, perhaps the getRoles functionality should be
          on MambuGroup code

        When using getClients argument, also adds a 'clients' field to
        the loan. By the way it works, when holder is a Group, it calls
        the setClients method, which adds a 'clients' field to the
        MambuGroup.

        The 'clients' field on the loan is a dictionary with the full
        name of each client receiving from this loan account as a key
        (see the 'name' field on MambuClient and MambuGroup). Each key
        holds another dictionary with the following keys:

        * 'client' holds a MambuClient. So even if a group is the holder
          of the account, you can access each individual client object
          here.

        * 'loan' holds a reference to this loan account (self)

        * 'amount' defaults to the total loan amount ('loanAmount'
          field) (see the pydoc for getClientDetails method)

        * 'montoPago' defaults to the total loan amount divided by the
          number of repayment installments of the loan account (the
          'repaymentInstallments' field), that is, how much to pay for
          each repayment installment (see the pydoc for getClientDetails
          method)

.. todo:: change the name to an english name

        * 'porcentaje' defaults to a 100%, the total loan amount divided
          by itself, that is, hoy much in percentage of the debt belongs
          to this client (see the pydoc for getClientDetails method)

.. todo:: change the name to an english name

        This three fields are supposed to reflect individual numbers for
        each client, but Mambu does an awful job indicating this on
        group loan accounts. So you should indicate how much you
        assigned to each client in other ways. Using the notes of the
        loan account perhaps (with a predefined format you parse on the
        preprocessing of MambuLoan)? with custom fields? Your call that
        you may define making your own loan account class inheriting
        from MambuLoan class. See the pydoc for getClientDetails method
        below, it specifies the way to determine the amount for each
        client depending on your use of Mambu, and additionally any
        other fields you wish to add to the 'clients' field on the loan
        account.

        Returns the number of requests done to Mambu.

.. todo:: what to do on Hybrid loan accounts?
        """
        requests = 0
        if 'fullDetails' in kwargs:
            fullDetails = kwargs['fullDetails']
            kwargs.pop('fullDetails')
        else:
            fullDetails = True

        if self['accountHolderType'] == "GROUP":

            self['holderType'] = "Grupo"
            try:
                holder = self.mambugroupclass(entid=self['accountHolderKey'], fullDetails=True, *args, **kwargs)
            except AttributeError as ae:
                from .mambugroup import MambuGroup
                self.mambugroupclass = MambuGroup
                holder = self.mambugroupclass(entid=self['accountHolderKey'], fullDetails=True, *args, **kwargs)
            self['holder'] = holder
            requests += 1

            if getRoles:
                roles = []
                # If holder is group, attach role client data to the group
                for c in holder['groupRoles']:
                    try:
                        cli = self.mambuclientclass(entid=c['clientKey'], *args, **kwargs)
                    except AttributeError as ae:
                        from .mambuclient import MambuClient
                        self.mambuclientclass = MambuClient
                        cli = self.mambuclientclass(entid=c['clientKey'], *args, **kwargs)

                    roles.append({'role'   : c['roleName'],
                                  'client' : cli
                                 })
                    requests += 1
                holder['roles'] = roles

            if getClients:
                requests += holder.setClients(fullDetails=fullDetails, *args, **kwargs)

                loanclients = {}

                loanclientsdata = self.getClientDetails(holder=holder, *args, **kwargs)

                for data in loanclientsdata:
                    loanclients[data['id']] = {'client'     : data['client'],
                                               'name'       : data['name'],
                                               'loan'       : self,
                                               'amount'     : data['amount'],
                                               'montoPago'  : data['amount'] / float(self['repaymentInstallments']),
                                               'porcentaje' : data['amount'] / float(self['loanAmount']),
                                              }
                    # Any extra key,val pair on loannames is plainly assigned to the loanclients[cte] dict
                    for k,v in [ (key,val) for (key,val) in data.items() if key not in['amount', 'name'] ]:
                        loanclients[data['id']][k] = v

                self['clients'] = loanclients


        else: # "CLIENT"
            self['holderType'] = "Cliente"
            try:
                holder = self.mambuclientclass(entid=self['accountHolderKey'], fullDetails=fullDetails, *args, **kwargs)
            except AttributeError as ae:
                from .mambuclient import MambuClient
                self.mambuclientclass = MambuClient
                holder = self.mambuclientclass(entid=self['accountHolderKey'], fullDetails=fullDetails, *args, **kwargs)

            self['holder'] = holder
            requests += 1

            if getClients:
                monto = float(self['loanAmount'])
                self['clients'] = {holder['name']: {'client'     : holder,
                                                          'loan'       : self,
                                                          'amount'     : monto,
                                                          'montoPago'  : monto / float(self['repaymentInstallments']),
                                                          'porcentaje' : 1.0,
                                                         }
                                        }

        return requests