# Orchard Accounting Workflow

General python workflow to serve accounting steps. 
Each accounting step should be described as new flow. 

## Workflows

### reserve_payouts

**TD** : https://docs.google.com/a/theorchard.com/document/d/1UDqDX0fsba3ADbeoymIgs46u3oHHO-rU7KC7nHM65YY/edit?usp=sharing

This workflow grab data from accountingflat.processed_dig_sales, art_relations.booked_vendor_contract_snapshot MySQL tables. Put data in dynamoDB, SQS. Make reserve payouts calculation, using data from SQS. PUT data in manual_adjastments Mysql database, using ows_manual_adjastments microservice. Update statuses in DynamoDB table items. Validate that all initial data was processed. Send result email. 

## Version
0.1

## Running the script:

1. This workflow that only being run once a month after current accounting process(Accounting Run):
```
garcon exec reserve_payouts -c "{\"period_id\": 214}"
```

But there also are additional parameters to run with:

- `skip_prepare_label_data` (boolean) - indicates if the prepare_label_data task should be skipped. 
This is needed for cases when the workflow has failed or was interrupted and there are still messages 
in the {env}-reserve-payout-calculations SQS  queue that should be processed.
- `validate_only` (boolean) - indicates if only the validation should be performed. ‘
validate_only’ flag should be set since the latter will instruct the flow to skip other steps 
except for the validation step

That's how flow could be ran without prepare label data:
```
garcon exec reserve_payouts -c "{\"period_id\": 214, \"skip_prepare_label_data\":true}"
```

That's how flow could be ran to just validate result
```
garcon exec reserve_payouts -c "{\"period_id\": 214, \"validate_only\":true}"
```

## Installation

The installation process is very straightforward.

## Dependencies
- python 3.4.3

## Set up a virtual Python environment
For dev environment
```sh
$ git clone git@github.com:theorchard/swf-accounting.git .
$ pyvenv ./env
$ source ./env/bin/activate
$ pip install -r reqs.pip
$ pip install -r reqs-test.pip
$ python setup.py develop
```

## .env.shadow
.env.shadow is a template environment variable script that exports keys and values necessary for successful connectivity, paths, etc.  You will need to copy this file to `.env` and populate the necessary keys.

```sh
$ cp .env.shadow .env
```

## Development and Debugging

Start Development and debugging on Devbox please:

1. finish #Set up a virtual Python environment, #Env.shadow steps
2. Check that you have enough permissions for:

    - DynamoDb Table defined in .env. If it doesnt exist - create it
    - SWF service
    - SQS queue defined in .env. If it doesnt exist - create it
