## Reserves Release

### Requirements

- Python 3.11
- Docker

## OWS Dependencies

- [ows-ledger](https://github.com/theorchard/ows-ledger)

## Overview
This lambda creates reserve_release and account ledger entries by:
1. Using the `target_id` of the received `abacus_event` to determine which statement period's reserves are to be released.
2. Requesting ows-ledger service to get `ledger_reserve_release_schedule` records by `release_statement_period_id`.
3. Process the ledger_reserve_release_schedule's information.
4. For each `ledger_release_reserve_schedule` record, inserts `installment_amount` into `ledger_reserve_release` table as credit.
5. Group `ledger_release_reserve_schedule` records by `contract_id` to get a sum of `installment_amount` per contract.
6. For each contract, inserts this summed up `installment_amount` to the `ledger_account` as a credit.

### Installation

Create a `.env` file based on the `.env.shadow` and fill in the values:

```bash
$ cp .env.shadow .env
```

Create a virtual env and install the requirements:

```bash
$ make dev_env
```

## Running

You can run the function locally with: `make run`

Or you can run the function inside Docker with: `make docker_local_up` and trigger an event with `make local_event`


### Testing

You can run the linter and the unit tests locally with: `make lint` and `make test`

Or you can run the linter and the unit tests inside Docker with: `make docker_test`

The integration tests can only be run inside Docker with: `make docker_test_integration`

**Note:**
You might need to login to Docker with the shared AWS account in order to run the integration tests:

```bash
$ awsume <shared_profile>
$ make docker_login
```

### Adding new packages

- For dev packages, add them normally to `requirements-dev.txt`
- For regular packages, add the new top level package name
  and optionally version constraints to `requirements-to-freeze.txt`
- Run `make pip_lock_versions`

### Upgrading packages

Regularly running `make pip_lock_versions` will update and freeze all non-dev dependencies in `requirements.txt`
