# Correction Apply

## Overview

This lambda creates ledger entries by:

1. Determining which worksheet corrections to apply based on the `target_id` and `event_name` of the received `abacus_event`.
2. Getting a list of unapplied worksheet correction for a specified statement_period_id(`target_id`) and correction_type(`event_name`).
3. Formatting the worksheet correction items and rounding gross_revenue, distribution_fee, net_revenue.
4. Creating ledger_correction entries. Committing rounded net_revenue to ledger_account_contract.
5. Creating ledger_deposit entries to track remaining balances after rounding net_revenue's.

## Getting Started

### Requirements

- Python 3.11
- Docker

### OWS Dependencies

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

### 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`
