MambuPy.rest.mambuloan

Mambu Loans objects.

MambuLoan holds a loan account.

MambuLoans holds a list of loan accounts.

Uses mambugeturl.getloans as default urlfunc. You can override this and use mambugeturl.getgrouploansurl for the loans of a specific group instead (you should send the Group ID instead of the Loan ID as the entid argument in the constructor in that case).

Classes

MambuLoan([urlfunc, entid])

A Loan account from Mambu.

MambuLoans([urlfunc, entid, itemclass])

A list of Loan accounts from Mambu.

class MambuPy.rest.mambuloan.MambuLoan(urlfunc=<function getloansurl>, entid='', *args, **kwargs)[source]

Bases: MambuStruct

A Loan account from Mambu.

With the default urlfunc, entid argument must be the ID of the loan account you wish to retrieve.

__init__(urlfunc=<function getloansurl>, entid='', *args, **kwargs)[source]

Tasks done here:

Just initializes the MambuStruct.

__module__ = 'MambuPy.rest.mambuloan'
_get_holder_data_by_client(fullDetails, getClients, *args, **kwargs)[source]
_get_holder_data_by_group(getRoles, fullDetails, getClients, *args, **kwargs)[source]
_get_loanclientsdata_from_group_setHolder(holder, *args, **kwargs)[source]
_get_roles(fullDetails=True, *args, **kwargs)[source]

Get a list of roles and clients for the loan account.

The roles are mentionend in the holder of the loan account.

The holder acquires a “roles” property, a list of dictionaries with the following keys:

role (str): role name client (obj): MambuClient that has the mentioned role

Parameters:

fullDetails (bool) – whether instantiate clients with full details or not

Returns:

int - number of requests done to Mambu

getClientDetails(*args, **kwargs)[source]

Gets the loan details for every client holder of the account.

As default, assigns the whole loan amount to each client. This works fine for Client holders of the loan account. When Group holders, this is perhaps not ideal, but I cannot tell.

If you inherit MambuLoan you should override this method to determine another way to assign particular amounts to each client.

You can also use the overriden version of this method to add several other fields with information you wish to associate to each client holder of the loan account.

BEWARE: for group loan accounts, this code assumes the holder (the group) currentrly has all the client members. But for accounts where the holder has changed along time, you may stumble upon accounts which assumes certain group members which weren’t the members that belonged to the group when it was disbursed.

getDebt()[source]

Sums up all the balances of the account and returns them.

preprocess()[source]

Preprocessing.

Each active custom field is given a ‘name’ key that holds the field name, and for each keyed name, the value of the custom field is assigned.

Notes on the group get some html tags removed.

setActivities(*args, **kwargs)[source]

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.

setBranch(*args, **kwargs)[source]

Adds the branch for this loan to a ‘assignedBranch’ field.

Also adds an ‘assignedBranchName’ field with the name of the branch.

Branch is a MambuBranch object.

Returns the number of requests done to Mambu.

setCentre(*args, **kwargs)[source]

Adds the centre for this loan to a ‘assignedCentre’ field.

Also adds an ‘assignedCentreName’ field with the name of the centre.

Centre is a MambuCentre object.

Returns the number of requests done to Mambu.

setHolder(getClients=False, getRoles=False, *args, **kwargs)[source]

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?

setProduct(cache=False, *args, **kwargs)[source]

Adds the product for this loan to a ‘product’ field.

Product is a MambuProduct object.

cache argument allows to use AllMambuProducts singleton to retrieve the products. See mambuproduct.AllMambuProducts code and pydoc for further information.

Returns the number of requests done to Mambu.

setRepayments(*args, **kwargs)[source]

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

setTransactions(*args, **kwargs)[source]

Adds the transactions for this loan to a ‘transactions’ field.

Transactions are MambuTransaction objects.

Transactions get sorted by transaction id.

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

setUser(*args, **kwargs)[source]

Adds the user for this loan to a ‘user’ field.

User is a MambuUser object.

Returns the number of requests done to Mambu.

update(data, *args, **kwargs)[source]

Updates a loan in Mambu

Updates customFields of a MambuLoan

TODO: update “core fields” of a MambuLoan

https://support.mambu.com/docs/loans-api#post-loans https://support.mambu.com/docs/loans-api#patch-loan https://support.mambu.com/docs/loans-api#patch-loan-custom-field-values

Parameters -data dictionary with data to update

update_patch(data, *args, **kwargs)[source]

Updates a Mambu loan using method PATCH

Parameters:

data (dictionary) – dictionary with data to update

https://support.mambu.com/docs/loans-api#patch-loan

upload_document(data, *args, **kwargs)[source]

Updates a loan in Mambu

Uploads a document to a MambuLoan

https://support.mambu.com/docs/attachments-api#post-attachments

Parameters -data dictionary with data to upload

Example data = {

“document”:{

“documentHolderKey” : self.encodedKey, “documentHolderType” : “LOAN_ACCOUNT”, “name” : “loan_resume”, “type” : “pdf”,

}, “documentContent” : “[‘encodedBase64_file’]”,

}

class MambuPy.rest.mambuloan.MambuLoans(urlfunc=<function getloansurl>, entid='', itemclass=<class 'MambuPy.rest.mambuloan.MambuLoan'>, *args, **kwargs)[source]

Bases: MambuStruct

A list of Loan accounts from Mambu.

With the default urlfunc, entid argument must be empty at instantiation time to retrieve all the loan accounts according to any other filter you send to the urlfunc.

There’s another possible urlfunc you may use, getgrouploansurl. If you use that, you should send the ID of the group from which you wish to retrieve its loan accounts.

itemclass argument allows you to pass some other class as the elements for the list. Why is this useful? at least for now, MambuLoan is the most specialized class on MambuPy. So you may wish to override several behaviours by creating your own MambuLoan son class. Pass that to the itemclass argument here and voila, you get a list of YourMambuLoan class using MambuLoans instead of plain old MambuLoan elements.

If you wish to specialize other Mambu objects on MambuPy you may do that. Mind that if you desire that the iterable version of it to have elements of your specialized class, you need to change the logic of the constructor and the convert_dict_to_attrs method in the iterable class to use some sort of itemclass there too. Don’t forget to submit the change on a pull request when done ;-)

__init__(urlfunc=<function getloansurl>, entid='', itemclass=<class 'MambuPy.rest.mambuloan.MambuLoan'>, *args, **kwargs)[source]

By default, entid argument is empty. That makes perfect sense: you want several groups, not just one.

__iter__()[source]
__module__ = 'MambuPy.rest.mambuloan'
convert_dict_to_attrs(*args, **kwargs)[source]

The trick for iterable Mambu Objects comes here:

You iterate over each element of the responded List from Mambu, and create a Mambu Loan (or your own itemclass) object for each one, initializing them one at a time, and changing the attrs attribute (which just holds a list of plain dictionaries) with a MambuLoan (or your own itemclass) just created.

Todo

pass a valid (perhaps default) urlfunc, and its corresponding id to entid to each itemclass, telling MambuStruct not to connect() by default. It’s desirable to connect at any other further moment to refresh some element in the list.