# COI Project

This project runs Django and SQL Server with Docker Compose.

## Start The Stack

```bash
docker compose build
docker compose up -d
docker compose ps
```

Web app:

```text
http://localhost:8039
```

## Import Customer Template Data

The project includes a tab-separated import file:

```text
app/customer_template_mapping_import.tsv
```

Import it into `CustomerTemplateMapping`:

```bash
docker exec coi-web-1 python manage.py import_customer_templates /app/customer_template_mapping_import.tsv
```

Set `created_by`:

```bash
docker exec coi-web-1 python manage.py import_customer_templates /app/customer_template_mapping_import.tsv --created_by 1
```

Override export template:

```bash
docker exec coi-web-1 python manage.py import_customer_templates /app/customer_template_mapping_import.tsv --export-template japanese
```

### Import Command Behavior

- Merges duplicate rows by `customer_name`
- Uses the numeric template column from the TSV as the sheet selector
- Maps template indexes to `SHEET_NAMES` using 1-based order
- Skips `hardness_out_in_4` from the numeric index mapping
- Defaults imported `export_template` to `asean`

Adjusted numeric mapping:

```text
1  -> hardness_out
2  -> hardness_out_in
3  -> hardness_both_size
4  -> dimension
5  -> dimension_weight_warp
6  -> dimension_app
7  -> dimension_app_drawing
8  -> dimension_bal_weight
9  -> dim_bal_app_hard
10 -> dim_bal_app_hard_stamp
11 -> dim_bal_app_rot_hard
12 -> thickness_8_point
13 -> centering
```

The command also still supports the older CSV format with `customer_name` and JSON `template_names`.

## Other Management Commands

Seed or top up project data models:

```bash
docker exec coi-web-1 python manage.py seed_all_mock_models
docker exec coi-web-1 python manage.py seed_all_mock_models --target-count 100
```

Create missing user profiles:

```bash
docker exec coi-web-1 python manage.py create_profile
```

Run migrations:

```bash
docker exec coi-web-1 python manage.py migrate
```

Open a Django shell:

```bash
docker exec -it coi-web-1 python manage.py shell
```

## Useful Docker Commands

Show running containers:

```bash
docker compose ps
```

View web logs:

```bash
docker compose logs web --tail 200
```

View database logs:

```bash
docker compose logs db --tail 200
```

Restart services:

```bash
docker compose restart web
docker compose restart db
```

Stop the stack:

```bash
docker compose down
```

## COI Test Lots

Lots for `/report/coi/`:

- `260218548-019` -> customer `NOGUCHI SEIKI` -> auto-selects `asean`
- `260218549-022` -> customer `NOGUCHI SEIKI` -> auto-selects `asean`
- `CEN-TEST-008` -> customer `CENTERING TEST` -> auto-selects `asean`
- `CEN-TEST-012` -> customer `CENTERING TEST` -> auto-selects `asean`
- `CEN-JP-001` -> customer `CENTERING JAPAN TEST` -> auto-selects `japanese`

## Notes

- The web container name in Compose is `coi-web-1`
- The database container name in Compose is `coi-db-1`
- SQL Server credentials are defined in `docker-compose.yml`
- The app code is mounted into the container from `./app`
