Skip to content

Feat/purchase order tracking#74

Merged
emilwojtaszek merged 6 commits into
mainfrom
feat/purchase-order-tracking
Mar 4, 2026
Merged

Feat/purchase order tracking#74
emilwojtaszek merged 6 commits into
mainfrom
feat/purchase-order-tracking

Conversation

@emilwojtaszek

@emilwojtaszek emilwojtaszek commented Mar 4, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added purchase order field to invoices with full creation, editing, and retrieval support
    • Automatic extraction of purchase order from invoice documents
    • Purchase order integrated into search and filtering functionality
    • API endpoints now accept and return purchase order data in all operations
  • Tests

    • Added tests for purchase order extraction, storage, editing, and search functionality

emilwojtaszek and others added 6 commits March 4, 2026 09:49
Add nullable purchase_order column (max 256 chars) to track PO identifiers
from KSeF XML (NrZamowienia / DodatkowyOpis) and PDF extraction.

- Migration adds purchase_order string column
- Schema: field, cast, validation in changeset and edit_changeset
- Parser: extract NrZamowienia with DodatkowyOpis fallback
- Context: upsert replace, extraction mapping, search ILIKE

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add purchase_order to invoice_json response
- Add to @create_allowed_keys and @update_allowed_keys
- Add purchase_order property to Invoice, CreateInvoiceRequest,
  and UpdateInvoiceRequest OpenAPI schemas

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Show PO row in details table (conditional, when present)
- Add PO text input to edit form

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Parser tests: NrZamowienia extraction, DodatkowyOpis fallback,
  nil when absent, NrZamowienia precedence, value regex
- Context tests: upsert stores PO, re-sync updates PO,
  update_invoice_fields updates PO, search matches PO,
  edit_changeset validation
- API tests: show/create/update include purchase_order
- New XML fixtures with PO data

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The pattern "zamowienie" (nominative) doesn't match "zamowienia"
(genitive) as a substring. Use "zamowien" root instead to match
all declension forms. Also use word-boundary regex for "po" key
to avoid false positives on keys like "pozycja".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace if/else with case pattern matching in extract_purchase_order
- Narrow @po_key_substrings: remove broad "order", use "order.number"
- Update list_invoices @doc to mention purchase_order in :query filter
- Extract dodatkowy_opis_xml/2 test helper to DRY inline XML fixtures
- Add parser tests: P.O., Purchase Order variants, unrelated DodatkowyOpis
- Add LiveView tests: PO display, hidden when nil, edit form field, save

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Mar 4, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6f5263e6-e643-4556-918a-89e7752996fb

📥 Commits

Reviewing files that changed from the base of the PR and between b9f54f3 and 6b777b7.

📒 Files selected for processing (15)
  • lib/ksef_hub/invoices.ex
  • lib/ksef_hub/invoices/invoice.ex
  • lib/ksef_hub/invoices/parser.ex
  • lib/ksef_hub_web/controllers/api/invoice_controller.ex
  • lib/ksef_hub_web/live/invoice_live/show.ex
  • lib/ksef_hub_web/schemas/create_invoice_request.ex
  • lib/ksef_hub_web/schemas/invoice.ex
  • lib/ksef_hub_web/schemas/update_invoice_request.ex
  • priv/repo/migrations/20260304100000_add_purchase_order_to_invoices.exs
  • test/ksef_hub/invoices/parser_test.exs
  • test/ksef_hub/invoices_test.exs
  • test/ksef_hub_web/controllers/api/invoice_controller_test.exs
  • test/ksef_hub_web/live/invoice_live/show_test.exs
  • test/support/fixtures/sample_expense_with_dodatkowy_opis_po.xml
  • test/support/fixtures/sample_income_with_po.xml

📝 Walkthrough

Walkthrough

This PR adds comprehensive support for a new purchase_order field across the invoicing system, including database migration, schema validation, XML parser enhancement for multi-source PO extraction, API endpoints, OpenAPI schemas, UI display/editing, and full test coverage.

Changes

Cohort / File(s) Summary
Database & Schema
priv/repo/migrations/20260304100000_add_purchase_order_to_invoices.exs, lib/ksef_hub/invoices/invoice.ex
Adds string column purchase_order (max 256 chars) to invoices table via migration. Schema updated with field casting, validation, and inclusion in editable fields.
Core Business Logic
lib/ksef_hub/invoices.ex, lib/ksef_hub/invoices/parser.ex
Extraction mapping now includes purchase_order. Parser adds multi-source extraction: prefers NrZamowienia, falls back to regex-based extraction from DodatkowyOpis with custom key matching and value parsing. Upsert logic updated to handle purchase_order in conflict resolution.
API & OpenAPI Schemas
lib/ksef_hub_web/controllers/api/invoice_controller.ex, lib/ksef_hub_web/schemas/*.ex
Controller's create/update allowed keys extended. OpenAPI schemas (CreateInvoiceRequest, UpdateInvoiceRequest, Invoice) updated with nullable string field (max 256 chars).
UI Display & Editing
lib/ksef_hub_web/live/invoice_live/show.ex
LiveView template adds conditional purchase_order display row and input field with validation in edit form.
Parser Tests
test/ksef_hub/invoices/parser_test.exs
Comprehensive tests for purchase_order extraction: nil when absent, extraction from NrZamowienia, DodatkowyOpis precedence, regex variants (PO:, P.O., Purchase Order).
Integration & API Tests
test/ksef_hub/invoices_test.exs, test/ksef_hub_web/controllers/api/invoice_controller_test.exs
Tests verify upsert persistence, search filtering, edit validation, and API endpoints (show/create/update) correctly handle purchase_order.
UI & LiveView Tests
test/ksef_hub_web/live/invoice_live/show_test.exs
Tests confirm display visibility, form presence, and persistence through LiveView edit submission.
Test Fixtures
test/support/fixtures/sample_income_with_po.xml, test/support/fixtures/sample_expense_with_dodatkowy_opis_po.xml
Sample XML invoices with purchase_order data in different XML structures (NrZamowienia and DodatkowyOpis) for parser validation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related PRs

Poem

🐰 A purchase order hops into view,
Through XML leaves, both old and new,
From NrZamowienia to descriptions deep,
The parser extracts with regex leaps,
Now buyers' orders in invoices keep! 📜✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'Feat/purchase order tracking' clearly and directly describes the main change: adding purchase order field support throughout the invoice system.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/purchase-order-tracking

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant