feat(manager): expenses, the supplier book and tabs on v2 (platform-v2 step 6.13a)

- Finance -> Expenses: still owed, late, filters, new/edit (supplier picked or added there), pay in parts, details with payments, delete
- CRM -> Contacts: the supplier book with what each one is owed
- Finance -> Tabs: open (who owes most first) / settled, charges and payments, pay (cash/card/other), close, forgive
- backend: expenses.manage / tabs.manage (the list also reports.view, a customer's tabs also crm.manage, put-on-tab needs tabs.manage);
  payment <= due (expense.over_due), total >= paid (expense.below_paid), categories/kinds/methods checked, null clears a field;
  live events expenses.changed / tabs.changed; GET /api/expenses ?from=&to= venue dates (the report uses it); tab_status=settled
- fix: an expense with a due date failed to save (naive date refused by D-11)
- @xenia/i18n/number subpath; tests: test_finance.py (6), finance.test.mjs (5), e2e manager.mjs finance flow

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 12:54:21 +02:00
co-authored by Claude Opus 5.5
parent 6bdf0bdd79
commit 93c0dd7d9c
32 changed files with 1667 additions and 1153 deletions
+91
View File
@@ -1238,6 +1238,97 @@ try {
await opens('/reports/expenses', 'expenses-total', 'Expenses')
await page.screenshot({ path: path.join(OUT, 'manager-report-expenses.png'), fullPage: true })
// ── 6.13a: a supplier, an expense paid in two parts, a tab paid and closed ──────
const fi = 'finance:'
for (const m of ['expenses', 'crm', 'tabs']) await api('PUT', `/api/platform/modules/${m}`, { token: boss, body: { enabled: true } }).catch(() => {})
await page.goto(`${APP}/crm/contacts`)
await page.getByTestId('contact-new').click()
await page.getByTestId('contact-save').click()
r.check(`${fi} a contact needs a name`, (await page.getByTestId('contact-dialog').textContent()).includes('Enter a name'))
await page.getByTestId('contact-name').fill('E2E Dairy')
await page.getByTestId('contact-phone').fill('2310 555 000')
await page.getByTestId('contact-save').click()
const dairyRow = page.locator('[data-testid="contact-row"]', { hasText: 'E2E Dairy' })
r.check(`${fi} the supplier is in the book`, await dairyRow.waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
const dairy = (await api('GET', '/api/contacts/', { token: boss })).find(c => c.name === 'E2E Dairy')
await page.goto(`${APP}/financials/expenses`)
await page.getByTestId('expense-new').click()
await page.getByTestId('expense-save').click()
r.check(`${fi} an expense needs what it is and an amount`, (await page.getByTestId('expense-dialog').textContent()).includes('Say what it is'))
await page.getByTestId('expense-description').fill('E2E milk November')
await page.getByTestId('expense-amount').fill('120,50')
await page.getByTestId('expense-supplier').selectOption(String(dairy?.id))
await page.getByTestId('expense-due-date').fill(addDaysIso(venueDay, -1))
await page.getByTestId('expense-save').click()
const milkRow = page.locator('[data-testid="expense-row"]', { hasText: 'E2E milk November' })
await milkRow.waitFor({ timeout: 8000 }).catch(() => {})
let milk = (await api('GET', '/api/expenses/', { token: boss })).find(e => e.description === 'E2E milk November')
r.check(`${fi} entered from the page: 120.50 to the supplier, due yesterday, shown as late`, milk?.total_amount === 120.5 && milk.contact_id === dairy?.id && milk.status === 'due'
&& (await milkRow.textContent()).includes('Late'), JSON.stringify(milk))
await milkRow.getByTestId('expense-pay').click()
await page.getByTestId('expense-pay-amount').fill('70')
await page.getByTestId('expense-pay-save').click()
await page.getByTestId('expense-pay-dialog').waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
for (let i = 0; i < 20 && milk?.status !== 'partial'; i++) { await sleep(250); milk = (await api('GET', '/api/expenses/', { token: boss })).find(e => e.id === milk.id) }
r.check(`${fi} a payment of 70: partly paid, 50.50 still due`, milk.status === 'partial' && milk.due_amount === 50.5, JSON.stringify(milk))
await milkRow.getByTestId('expense-pay').click()
await page.getByTestId('expense-pay-amount').fill('60')
await page.getByTestId('expense-pay-save').click()
r.check(`${fi} paying more than what is due is refused before saving`, (await page.getByTestId('expense-pay-dialog').textContent()).includes('no more than'))
await page.getByTestId('expense-pay-amount').fill('50,50')
await page.getByTestId('expense-pay-save').click()
const gone = await milkRow.waitFor({ state: 'detached', timeout: 8000 }).then(() => true).catch(() => false)
milk = (await api('GET', '/api/expenses/', { token: boss })).find(e => e.id === milk.id)
r.check(`${fi} the rest paid: it shows paid and leaves the "not fully paid" list`, gone && milk.status === 'paid' && milk.payments.length === 2, JSON.stringify(milk))
await page.getByTestId('expenses-status').selectOption('paid')
await page.locator('[data-testid="expense-row"]', { hasText: 'E2E milk November' }).click()
r.check(`${fi} the expense opens with its two payments`, await page.getByTestId('expense-view').waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
&& await page.locator('[data-testid="expense-view"] li').count() === 2)
await page.screenshot({ path: path.join(OUT, 'manager-expenses.png'), fullPage: true })
await page.keyboard.press('Escape')
// a tab: a line of a customer's order goes on the tab, paid in two parts on the page, then closed
await api('POST', '/api/business-day/open', { token: boss, body: {} }).catch(() => {})
const tabCustomer = await api('POST', '/api/customers/', { token: boss, body: { name: 'Tab E2E', phone: '6900000013' } })
const tabMenu = await api('GET', '/api/orders/menu', { token: boss })
const tabProduct = tabMenu.products.find(x => x.available && !x.service && !x.prefs.length && x.price > 0)
const tabOrder = await api('POST', '/api/orders/', { token: boss, body: { order_type: 'takeaway' } })
await api('PUT', `/api/orders/${tabOrder.id}/customer`, { token: boss, body: { customer_id: tabCustomer.id } })
await api('POST', `/api/orders/${tabOrder.id}/items`, { token: boss, body: { lines: [{ product_id: tabProduct.id, quantity: 2 }] } })
const tabLine = (await api('GET', `/api/orders/${tabOrder.id}`, { token: boss })).items.find(x => x.product_id === tabProduct.id)
await api('POST', `/api/orders/${tabOrder.id}/items/${tabLine.id}/tab`, { token: boss })
const owes = Math.round(tabLine.unit_price * 2 * 100) / 100
await page.goto(`${APP}/financials/tabs`)
const tabCard = page.locator('[data-testid="tab-card"]', { hasText: 'Tab E2E' })
await tabCard.waitFor({ timeout: 10_000 }).catch(() => {})
r.check(`${fi} the customer's tab is open with what the line cost`, (await tabCard.getByTestId('tab-balance').textContent()).replace(/[\s,]/g, '').includes(owes.toFixed(2)), `${owes} vs ${await tabCard.textContent()}`)
await tabCard.locator('button[aria-expanded]').click()
await tabCard.getByTestId('tab-pay').click()
await page.getByTestId('tab-pay-amount').fill('1')
await page.getByRole('radio', { name: 'Card' }).click()
await page.getByTestId('tab-pay-save').click()
await page.getByTestId('tab-pay-dialog').waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
for (let i = 0; i < 30 && (await tabCard.getByTestId('tab-balance').textContent()).replace(/[\s,]/g, '').includes(owes.toFixed(2)); i++) await sleep(250) // the first payment shows
await tabCard.getByTestId('tab-pay').click()
await page.getByTestId('tab-pay-save').click() // the rest (the default)
await page.getByTestId('tab-pay-dialog').waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
const closeBtn = tabCard.getByTestId('tab-close')
r.check(`${fi} paid in two parts (card, then the rest): nothing owed, it can be closed`, await closeBtn.waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
await page.screenshot({ path: path.join(OUT, 'manager-tabs.png'), fullPage: true })
await closeBtn.click()
await tabCard.waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
const settled = (await api('GET', '/api/tabs/?tab_status=settled', { token: boss })).find(x => x.customer_id === tabCustomer.id)
r.check(`${fi} closed: it leaves the open tabs; payments card + cash`, settled?.status === 'closed' && settled.payments.map(x => x.payment_method).join(',') === 'card,cash', JSON.stringify(settled?.payments))
await page.getByTestId('tabs-view-settled').click()
r.check(`${fi} it is listed with the settled tabs`, await page.locator('[data-testid="tab-card"]', { hasText: 'Tab E2E' }).waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
await page.getByTestId('user-menu').click()
await page.getByRole('menuitemradio', { name: 'Ελληνικά' }).click()
await page.waitForFunction(() => document.querySelector('[data-testid="tabs-page"] h1')?.textContent === 'Καρτέλες', null, { timeout: 5000 }).catch(() => {})
r.check(`${fi} Tabs in Greek`, (await page.locator('[data-testid="tabs-page"] h1').textContent()) === 'Καρτέλες')
await page.goto(`${APP}/financials/expenses`)
r.check(`${fi} Expenses in Greek`, await page.locator('[data-testid="expenses-page"] h1', { hasText: 'Δαπάνες' }).waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
await page.getByTestId('user-menu').click()
await page.getByRole('menuitemradio', { name: 'English' }).click()
await api('PUT', '/api/platform/modules/connect_orders', { token: boss, body: { enabled: true } })
await page.goto(`${APP}/online-orders`)
await page.getByTestId('online-orders').waitFor({ timeout: 10_000 }).catch(() => {})