Skip to content

feat: categorize Amazon refund items#74

Merged
eshaffer321 merged 3 commits into
mainfrom
codex/amazon-return-ledger
Jul 17, 2026
Merged

feat: categorize Amazon refund items#74
eshaffer321 merged 3 commits into
mainfrom
codex/amazon-return-ledger

Conversation

@eshaffer321

Copy link
Copy Markdown
Owner

What changed

  • Read Amazon's Return Center history and per-return status pages directly with the selected account's saved cookies.
  • Capture authoritative order ID, RMA, return-created date, refund total, refund-issued date, status, ASIN, item name, and item price.
  • Add itemize amazon returns -account <name> for read-only JSON inspection without initializing Monarch, SQLite, or an LLM.
  • Integrate eligible Amazon refunds into normal sync and report categorized versus untouched refunds separately.
  • Add a unique transaction matcher that rejects tied candidates.
  • Normalize browser-exported quoted cookie values and Monarch category whitespace.

Safety behavior

  • Only positive, non-pending, unsplit credits that are uncategorized or still in [TEMP] Amazon are eligible.
  • A refund requires Amazon's explicit refund total, explicit issued date, RMA, and exactly one returned item.
  • Multi-item returns without authoritative item-level allocation remain untouched.
  • Same-date/same-amount credits are updated as a group only when Amazon record count equals Monarch credit count and every returned item independently resolves to the same category.
  • Group notes explicitly state that the bank feed cannot identify the individual credit-to-item mapping.

Root cause

Amazon's normal order-payment transaction endpoint did not expose usable refund entries. The authoritative return/item mapping lives in Return Center, while the refund-issued date lives on each return status page. The issued-date sentence spans multiple HTML elements, and Monarch stored the temporary category with repeated whitespace, so both sources needed structured normalization.

Verification

  • Mandatory failing regression tests were written before each fix.
  • Pre-commit formatting, golangci-lint, go vet ./..., and go test ./... pass.
  • go test ./... -race passes.
  • go build -o itemize ./cmd/itemize passes.
  • Full authorized account dry-run: Amazon refunds: Categorized=4 Left untouched=0.
  • Production pass categorized the four target credits.
  • A fresh Monarch read-back confirmed the final categories and truthful item/group notes.

Related: #72 improves Amazon setup cookie persistence. This branch is independently rebased directly onto origin/main v0.2.2 as requested.

Comment thread internal/adapters/providers/amazon/returns.go Fixed
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.57692% with 101 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.29%. Comparing base (ba770cd) to head (d1aae63).

Files with missing lines Patch % Lines
internal/adapters/providers/amazon/returns.go 79.71% 26 Missing and 17 partials ⚠️
...ternal/application/sync/handlers/amazon_refunds.go 87.73% 10 Missing and 10 partials ⚠️
internal/application/sync/amazon_returns.go 79.56% 13 Missing and 6 partials ⚠️
internal/domain/matcher/matcher.go 73.33% 6 Missing and 6 partials ⚠️
internal/application/sync/orchestrator.go 0.00% 7 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #74      +/-   ##
==========================================
+ Coverage   62.10%   64.29%   +2.19%     
==========================================
  Files          46       49       +3     
  Lines        6040     6560     +520     
==========================================
+ Hits         3751     4218     +467     
- Misses       2035     2036       +1     
- Partials      254      306      +52     
Flag Coverage Δ
unittests 64.29% <80.57%> (+2.19%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/application/sync/types.go 31.87% <ø> (ø)
internal/application/sync/orchestrator.go 33.33% <0.00%> (-2.13%) ⬇️
internal/domain/matcher/matcher.go 81.39% <73.33%> (-8.85%) ⬇️
internal/application/sync/amazon_returns.go 79.56% <79.56%> (ø)
...ternal/application/sync/handlers/amazon_refunds.go 87.73% <87.73%> (ø)
internal/adapters/providers/amazon/returns.go 79.71% <79.71%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@eshaffer321
eshaffer321 force-pushed the codex/amazon-return-ledger branch from 97c3df3 to d1aae63 Compare July 17, 2026 13:11
@eshaffer321
eshaffer321 marked this pull request as ready for review July 17, 2026 13:14
@eshaffer321
eshaffer321 merged commit b7a2788 into main Jul 17, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants