Files
accounted/extensions/general/woocommerce/index.ts
T
bb5fafe87b fix(orders): book webshop orders against 1686 and stop the missing-account dead end (#1697)
Booking an order from the Orders page could fail outright on a fresh
company. seed_chart_of_accounts() seeds a deliberately small chart:
3001/3002/3003 and 2611/2621/2631 are in it, but 3004, 3740 and the
clearing account are not. All three are reachable from an entirely
ordinary order (a 0%-rate line, an ore residual, or simply no
payment-method mapping yet), and the engine treats a missing or
inactive account as AccountsNotInChartError, so the user's first click
on Bokfor returned an error naming accounts they had no reason to know
about, with no way forward but to hand-add them.

The book route now ensures the closed set of accounts our own prefill
can emit exists before drafting. Deliberately narrow: only accounts in
WEBSHOP_PREFILL_ACCOUNTS are ever created, and only when a submitted
line uses one, so an account the user typed still surfaces as a real
error instead of quietly growing the chart. A deactivated row is
reactivated rather than duplicated, and every failure is swallowed so
the engine's typed error still wins over a chart tidy-up.

The unmapped default also moves from 1680 to 1686. 1680 is the generic
"Andra kortfristiga fordringar" parent; 1686 "Fordringar for kontokort
och kuponger" is what BAS defines for a claim on a payment provider,
which is what money sitting at Klarna or Stripe actually is. The Stripe
extension already settles against 1686, so a store running both
surfaces now shares one clearing account instead of splitting the same
receivable across two.

Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-19 19:51:02 +02:00

38 lines
1.4 KiB
TypeScript

import type { Extension } from '@/lib/extensions/types'
import { woocommerceApiRoutes } from './api-routes'
/**
* WooCommerce extension
*
* Connects a company's WooCommerce store via the wc-auth key handshake (or
* manual key entry) and imports the store's orders and refunds as rows in the
* Orders workspace (webshop_orders). Feed-only (same doctrine as the Stripe
* feed, decision 2026-08-06): nothing is auto-booked. The user books a row
* from the Orders page, prefilled against the per-store payment-method
* mapping and otherwise BAS 1686 (Fordringar för kontokort och kuponger).
*
* Gateway fees and payouts are still out of scope, but not because they are
* unreachable: core wc/v3 does not expose them, yet a WooPayments store also
* serves /wc/v3/payments/deposits and /payments/reports/transactions (fees,
* net, deposit_id) under the same consumer key, given a key whose user has
* manage_woocommerce. Booking those is a separate settlement-ledger feature.
*
* Required environment variables:
* - WOOCOMMERCE_CREDENTIALS_ENCRYPTION_KEY (at-rest key for consumer key/secret)
*/
export const woocommerceExtension: Extension = {
id: 'woocommerce',
name: 'WooCommerce',
version: '1.0.0',
sector: 'general',
settingsPanel: {
label: 'WooCommerce',
path: '/import?mode=woocommerce',
},
apiRoutes: woocommerceApiRoutes,
}
export default woocommerceExtension