Metadata-Version: 2.5
Name: ishelf-ee
Version: 0.7.0
Summary: InvoiceShelf from the command line: export and log expenses (with receipts), create invoices and record payments.
Author-email: Arpit Goyal <hunterarpit@gmail.com>
License: MIT
License-File: LICENSE
Keywords: accounting,bookkeeping,csv,expenses,export,invoices,invoiceshelf,payments,receipts
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: End Users/Desktop
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Topic :: Office/Business :: Financial :: Accounting
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# ishelf-ee — InvoiceShelf Expense Exporter

Export a client's expenses from a self-hosted InvoiceShelf (2.4.1) instance to CSV,
and bundle their receipts into a zip. Zero runtime dependencies (Python standard
library only). Installs the `ee` command.

## Install

    pip install ishelf-ee

Requires Python 3.8+. Or run from a clone without installing:

    python3 -m ishelf_ee --client "Acme Corp" --start 01042025 --end 30062025
    # or the legacy shim:
    python3 export_expenses.py --client "Acme Corp" --start 01042025 --end 30062025

## Configure

The tool needs your instance URL and login. Provide them either as environment
variables or in a config file. **Never commit or share your filled-in config — it
holds your password.**

Required: `INVOICESHELF_URL`, `INVOICESHELF_EMAIL`, `INVOICESHELF_PASSWORD`.
Optional: `INVOICESHELF_COMPANY_ID` (default `1`; or use `--company`),
`INVOICESHELF_USER_AGENT` (see Troubleshooting).

### Option A — environment variables (work from any directory)

    export INVOICESHELF_URL=https://invoices.example.com
    export INVOICESHELF_EMAIL=you@example.com
    export INVOICESHELF_PASSWORD=your-password

### Option B — a config file

Copy the template and fill it in:

    mkdir -p ~/.config/ishelf-ee
    curl -o ~/.config/ishelf-ee/config.env \
      https://raw.githubusercontent.com/<you>/ishelf-ee/main/config.env.example
    # then edit ~/.config/ishelf-ee/config.env

The config file is discovered in this order (first match wins):

1. `--config PATH` (explicit)
2. `$INVOICESHELF_CONFIG`
3. `./config.env` (current directory)
4. `~/.config/ishelf-ee/config.env`  ← recommended for the installed `ee` command
5. `~/.ishelf-ee.env`

Environment variables always override file values.

## Usage

    ee --client "Acme Corp" --start 01042025 --end 30062025
    ee --company "My Company" --client "Acme Corp" --start 01042025 --end 30062025
    ee --customer-id 12 --start 01042025 --end 30062025 --out ./exports
    ee --client "Acme Corp" --start 01042025 --end 30062025 --dry-run

Dates are `DDMMYYYY`, inclusive. Outputs `<Client>_<start>-<end>.csv` and
`<Client>_<start>-<end>_receipts.zip` into `--out` (default `exports/`). Use
`--dry-run` to see what would be exported without downloading or writing anything.

### Choosing the company

If you run more than one company in InvoiceShelf, pass `--company "Name"` to scope
the export; the name is resolved to its id (case-insensitive, exact match preferred).
`--company` overrides `INVOICESHELF_COMPANY_ID`. On an ambiguous or unknown name, the
tool lists the available companies as `id — name` so you can pick.

### Full-corpus export

Export every field (not just the default six) and/or every company/client in one run:

- `--export-all-fields` — widen the CSV to include `expense_id, company, client, category,
  exchange_rate, created_at` (category/customer ids resolved to names). Without it, the export
  is unchanged (six columns).
- `--company all` — iterate every company.
- `--client all` — include every client (no customer filter).

In `all` mode, `--start`/`--end` are optional (omit for all-time) and the output is a single
combined `all-expenses_<range>.csv` plus one combined receipts zip.

```bash
# Whole history, all companies/clients, all fields, with receipts:
ee --company all --client all --export-all-fields --config ~/.personal/configs/ishelf-config.env
```

The default per-client export (`--client NAME --start … --end …`) is unchanged.

## Create an expense

`ee create` logs a single expense to InvoiceShelf, optionally attaching a receipt. The
export commands are unchanged — `ee …` with no subcommand still exports, and `ee export …`
is the explicit form.

    ee create --company "AsterHQ" --amount 12.34 --currency USD --date 07082026 \
              --category "Software" --notes "Anthropic" --payment-method "Credit Card" \
              --receipt ./receipt.png

Flags: `--company` (required, resolved by name), `--amount` (decimal), `--currency` (code,
e.g. `USD`), `--date` (`DDMMYYYY`), `--category` (required, resolved by name),
`--notes`/`--vendor`, `--customer` (optional), `--payment-method` (optional, resolved by
name to its `payment_method_id`, e.g. `"Credit Card"`), `--receipt PATH` (uploaded as
`attachment_receipt`), `--exchange-rate` (only when the currency differs from the company
default), and `--dry-run`.

`--dry-run` prints the exact `POST /expenses` body without writing anything. Amounts are
sent in minor units; a receipt is uploaded via `multipart/form-data`.

### `ee update`

`ee update` changes one expense, or attaches a receipt to it. The expense is found by its
**expense number** (company-scoped, so `--company` is required):

    ee update --company "Arpit Goyal" --expense-number 1509202603 --amount 2400.52
    ee update --company "Arpit Goyal" --expense-number 1509202603 --receipt ~/Downloads/bill.pdf

Flags: `--company` and `--expense-number` (required); at least one of `--amount`, `--date`
(DDMMYYYY), `--category`, `--notes`, `--client`, `--payment-method`, `--receipt`; plus `--config` and
`--dry-run`. `--expect-id ID` makes it refuse (exit 2, nothing sent) unless the expense with that
number has that id: numbers can repeat after an expense is deleted and another is made for the
same day. Anything you do not name keeps its current value. On success it prints one line,
`updated <number>: <field>=<value>, ...` (`would update ...` with `--dry-run`, which changes
nothing). Exit code 0 on success, 2 if no expense (or more than one) has that number or its id is
not the expected one, 1 on an API error or when InvoiceShelf returns the expense with no amount
(it is never sent as 0). Empty fields are left out of the multipart form. Without a receipt it sends `PUT /expenses/{id}`; with one it sends a multipart
`POST /expenses/{id}` with `_method=PUT` and the file in `attachment_receipt`.

### `ee delete`

`ee delete` removes a single expense by its **expense number** (numbers are company-scoped, so
`--company` is required):

    ee delete --company "AsterHQ" --expense-number 0708202601

Flags: `--company` (required, resolved by name), `--expense-number` (required), `--config`, and
`--dry-run`. It looks the expense up by number and deletes it via `POST /expenses/delete`. If no
expense matches — or more than one does — it errors and deletes nothing. `--dry-run` prints the
expense that would be deleted without removing it.

## Invoices and payments

`ee invoice …` and `ee payment …` each have four verbs: `create`, `list`, `export`, `delete`.
Every one needs `--company`; all take `--config`.

**Currency.** InvoiceShelf always bills a customer in *that customer's* currency. When it
differs from the company currency (e.g. a USD client of an INR company), you must give the
INR value too, one of:

- `--inr-amount` — the INR the bank actually credited (e.g. the eFIRC amount). The exchange
  rate is worked out from it, so the INR InvoiceShelf stores matches the bank.
- `--exchange-rate` — the rate itself.

For a customer in the company currency, leave both out.

### `ee invoice create`

    ee invoice create --company "Ascendra Ventures" --client "Aster AI" --date 30092026 \
                      --item "Consulting Sep 2026=3781" --currency USD --inr-amount 355639.79

- `--item "NAME=PRICE"` or `"NAME=PRICE@QTY"` (price per unit). Repeat for more lines. No taxes
  or discounts.
- `--due-date DDMMYYYY`, `--notes`, `--template` (default `invoice1`) are optional.
- `--invoice-number` is optional; by default InvoiceShelf's next number is used (e.g. `INV-000012`).
- `--currency` is only a safety check: it fails if the customer is not billed in that currency.
- The invoice is created as a draft.

### `ee payment create`

    ee payment create --company "Ascendra Ventures" --invoice INV-000012 --amount 3781 \
                      --inr-amount 355639.79 --date 01102026 --payment-method "Bank Transfer" \
                      --notes "eFIRC CITIN26740027028"

- `--invoice NUMBER` links the payment to an invoice; the customer and currency come from it,
  and a payment larger than the invoice's due amount is refused. Without `--invoice`, pass
  `--client` instead.
- `--amount` is in the customer's currency. `--payment-method` is resolved by name within the
  company. `--payment-number` is optional (next number by default).
- InvoiceShelf 2.4.1 payments **cannot carry attachments**, so put the eFIRC / reference number
  in `--notes`.

### list, export, delete

    ee invoice list   --company "Ascendra Ventures" [--client "Aster AI"] [--start 01092026 --end 30092026]
    ee payment export --company "Ascendra Ventures" [--client …] [--start … --end …] [--out DIR] [--dry-run]
    ee invoice delete --company "Ascendra Ventures" --invoice-number INV-000012 [--dry-run]
    ee payment delete --company "Ascendra Ventures" --payment-number PAY-000019 [--dry-run]

`list` prints a table; `export` writes `invoices_<client or company>_<range|all-time>.csv` (or
`payments_…`) with every field, including the INR `base_total` / `base_amount`. Leave out
`--start`/`--end` for all time. `delete` finds the record by exact number and errors if none or
several match. InvoiceShelf refuses to delete an invoice that still has payments; deleting a
payment puts its amount back on the invoice's due amount.

All `create` and `delete` commands take `--dry-run`, which prints the request and changes nothing.

## Troubleshooting

**Cloudflare "Error 1010: Access denied" / HTTP 403 on login.** The instance is
behind Cloudflare, which bans the default Python User-Agent. The tool already sends
a browser User-Agent. If your Cloudflare config still blocks it, override it:

    INVOICESHELF_USER_AGENT="Mozilla/5.0 (...)" ee ...

If it persists, allowlist your own access in the Cloudflare dashboard (e.g. a WAF
skip rule for the `/api/*` path, or turn off Bot Fight Mode for the API) — it is
your own site.

## Develop / test

    python3 -m unittest discover -s tests -v

## Releasing

Publishing to PyPI is automated via GitHub Actions (`.github/workflows/publish-to-pypi.yaml`)
using PyPI Trusted Publishing — no API token is stored. To cut a release:

1. Bump `version` in `pyproject.toml` (must match the tag below).
2. Commit, then tag and push:

        git tag v0.1.0
        git push origin main --tags

The workflow builds and publishes the tagged version. A one-time Trusted Publisher
must be configured on PyPI for the `ishelf-ee` project (owner `argoyal`, repo
`ishelf-ee`, workflow `publish-to-pypi.yaml`).
