summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnders Betts <anders.betts@gmail.com>2026-09-21 21:43:44 +0200
committerAnders Betts <anders.betts@gmail.com>2026-09-21 21:43:44 +0200
commit62a92f0af0442c78277c3c97c9efe6fef8145625 (patch)
tree3802a62904880da22bf84a44e9ece3cdff9cd8aa /tests
parentf1eeb15781a044a9451ee08b91c63feb395b4767 (diff)
downloadbokf-0.1.60.tar.gz
bokf-0.1.60.zip
settings: per-feature voucher series and console invoice number; tui: F9 hintsv0.1.60
Diffstat (limited to 'tests')
-rw-r--r--tests/test_core.c140
1 files changed, 140 insertions, 0 deletions
diff --git a/tests/test_core.c b/tests/test_core.c
index 12d42e5..a0b2468 100644
--- a/tests/test_core.c
+++ b/tests/test_core.c
@@ -2317,6 +2317,132 @@ static void test_settings(struct tctx *t)
yyjson_doc_free(d);
}
+static void test_series(struct tctx *t)
+{
+ yyjson_doc *d;
+ (void)t;
+
+ /* own org: the series settings and their vouchers must not disturb the
+ shared test org's counts and defaults */
+ d = call(reqf("{\"v\":1,\"id\":\"sv0\",\"cmd\":\"org.create\","
+ "\"session\":\"%s\",\"args\":{\"name\":\"Serie AB\","
+ "\"org_nr\":\"5560001111\"}}",
+ g_session));
+ CHECK_OK(d);
+ int org = (int)jint(d, "result.id");
+ CHECK(org > 0);
+ yyjson_doc_free(d);
+
+ /* the legacy default_series seeds series_voucher; the other features
+ have their own conventional defaults */
+ d = call(reqf("{\"v\":1,\"id\":\"sv1a\",\"cmd\":\"settings.set\","
+ "\"session\":\"%s\",\"org\":%d,\"args\":{\"key\":"
+ "\"default_series\",\"value\":\"V-\"}}",
+ g_session, org));
+ CHECK_OK(d);
+ yyjson_doc_free(d);
+ d = call(reqf("{\"v\":1,\"id\":\"sv1\",\"cmd\":\"settings.get\","
+ "\"session\":\"%s\",\"org\":%d}",
+ g_session, org));
+ CHECK_OK(d);
+ CHECK_STR(d, "result.series_voucher", "V-");
+ CHECK_STR(d, "result.series_invoice", "F");
+ CHECK_STR(d, "result.series_payroll", "L");
+ CHECK_STR(d, "result.series_bokslut", "Å");
+ CHECK_STR(d, "result.series_ib", "IB");
+ yyjson_doc_free(d);
+
+ d = call(reqf("{\"v\":1,\"id\":\"sv2\",\"cmd\":\"settings.set\","
+ "\"session\":\"%s\",\"org\":%d,\"args\":{\"key\":"
+ "\"series_foo\",\"value\":\"X\"}}",
+ g_session, org));
+ CHECK_STR(d, "error.code", "UNSUPPORTED");
+ yyjson_doc_free(d);
+
+ /* an explicit per-feature voucher series wins over the legacy key */
+ d = call(reqf("{\"v\":1,\"id\":\"sv3\",\"cmd\":\"settings.set\","
+ "\"session\":\"%s\",\"org\":%d,\"args\":{\"key\":"
+ "\"series_voucher\",\"value\":\"S-\"}}",
+ g_session, org));
+ CHECK_OK(d);
+ CHECK_STR(d, "result.value", "S-");
+ yyjson_doc_free(d);
+ d = call(reqf("{\"v\":1,\"id\":\"sv4\",\"cmd\":\"voucher.post\","
+ "\"session\":\"%s\",\"org\":%d,\"args\":{\"date\":"
+ "\"2026-09-20\",\"description\":\"Serieserie\",\"rows\":"
+ "[{\"account\":\"1930\",\"debit_ore\":100},{\"account\":"
+ "\"3001\",\"credit_ore\":100}]}}",
+ g_session, org));
+ CHECK_OK(d);
+ CHECK_STR(d, "result.series", "S-");
+ yyjson_doc_free(d);
+
+ /* invoices post in the invoice series */
+ d = call(reqf("{\"v\":1,\"id\":\"sv5\",\"cmd\":\"settings.set\","
+ "\"session\":\"%s\",\"org\":%d,\"args\":{\"key\":"
+ "\"series_invoice\",\"value\":\"F2\"}}",
+ g_session, org));
+ CHECK_OK(d);
+ yyjson_doc_free(d);
+ d = call(reqf("{\"v\":1,\"id\":\"sv6\",\"cmd\":\"customer.create\","
+ "\"session\":\"%s\",\"org\":%d,\"args\":{\"name\":"
+ "\"Serie Test AB\"}}",
+ g_session, org));
+ CHECK_OK(d);
+ int64_t cust = jint(d, "result.id");
+ CHECK(cust > 0);
+ yyjson_doc_free(d);
+ d = call(reqf("{\"v\":1,\"id\":\"sv7\",\"cmd\":\"invoice.issue\","
+ "\"session\":\"%s\",\"org\":%d,\"args\":{\"customer_id\":"
+ "%lld,\"invoice_date\":\"2026-09-20\",\"due_date\":"
+ "\"2026-10-20\",\"rows\":[{\"description\":\"Konsult\","
+ "\"quantity\":\"1\",\"unit_price_ore\":100000,"
+ "\"vat_code\":\"25\"}]}}",
+ g_session, org, (long long)cust));
+ CHECK_OK(d);
+ int64_t voucher = jint(d, "result.voucher_id");
+ CHECK(voucher > 0);
+ yyjson_doc_free(d);
+ d = call(reqf("{\"v\":1,\"id\":\"sv8\",\"cmd\":\"voucher.get\","
+ "\"session\":\"%s\",\"org\":%d,\"args\":{\"id\":%lld}}",
+ g_session, org, (long long)voucher));
+ CHECK_OK(d);
+ CHECK_STR(d, "result.series", "F2");
+ yyjson_doc_free(d);
+
+ /* the configured IB series counts as ingående balans */
+ d = call(reqf("{\"v\":1,\"id\":\"sv9\",\"cmd\":\"settings.set\","
+ "\"session\":\"%s\",\"org\":%d,\"args\":{\"key\":"
+ "\"series_ib\",\"value\":\"IBX\"}}",
+ g_session, org));
+ CHECK_OK(d);
+ yyjson_doc_free(d);
+ d = call(reqf("{\"v\":1,\"id\":\"sv10\",\"cmd\":\"report.trial_balance\","
+ "\"session\":\"%s\",\"org\":%d}",
+ g_session, org));
+ CHECK_OK(d);
+ int64_t ib_before = find_amount(d, "result.accounts", "account", "1930",
+ "ib_ore");
+ yyjson_doc_free(d);
+ d = call(reqf("{\"v\":1,\"id\":\"sv11\",\"cmd\":\"voucher.post\","
+ "\"session\":\"%s\",\"org\":%d,\"args\":{\"date\":"
+ "\"2026-01-01\",\"description\":\"IB serietest\","
+ "\"series\":\"IBX\",\"rows\":[{\"account\":\"1930\","
+ "\"debit_ore\":700},{\"account\":\"2010\","
+ "\"credit_ore\":700}]}}",
+ g_session, org));
+ CHECK_OK(d);
+ CHECK_STR(d, "result.series", "IBX");
+ yyjson_doc_free(d);
+ d = call(reqf("{\"v\":1,\"id\":\"sv12\",\"cmd\":\"report.trial_balance\","
+ "\"session\":\"%s\",\"org\":%d}",
+ g_session, org));
+ CHECK_OK(d);
+ CHECK(find_amount(d, "result.accounts", "account", "1930", "ib_ore") ==
+ ib_before + 700);
+ yyjson_doc_free(d);
+}
+
static void test_smtp_settings(struct tctx *t)
{
yyjson_doc *d;
@@ -4554,6 +4680,12 @@ static void test_payroll(struct tctx *t)
yyjson_doc_free(d);
/* post: one balanced voucher, the run and its lines */
+ d = call(reqf("{\"v\":1,\"id\":\"p13a\",\"cmd\":\"settings.set\","
+ "\"session\":\"%s\",\"org\":%d,\"args\":{\"key\":"
+ "\"series_payroll\",\"value\":\"L9\"}}",
+ g_session, (int)t->org_id));
+ CHECK_OK(d);
+ yyjson_doc_free(d);
d = call(reqf("{\"v\":1,\"id\":\"p13\",\"cmd\":\"payroll.run_post\","
"\"session\":\"%s\",\"org\":%d,\"args\":"
"{\"period\":\"2026-08\",\"pay_date\":\"2026-08-25\"}}",
@@ -4575,6 +4707,13 @@ static void test_payroll(struct tctx *t)
g_session, (int)t->org_id, (long long)voucher));
CHECK_OK(d);
CHECK_STR(d, "result.source", "payroll");
+ CHECK_STR(d, "result.series", "L9");
+ yyjson_doc_free(d);
+ d = call(reqf("{\"v\":1,\"id\":\"p14b\",\"cmd\":\"settings.set\","
+ "\"session\":\"%s\",\"org\":%d,\"args\":{\"key\":"
+ "\"series_payroll\",\"value\":\"L\"}}",
+ g_session, (int)t->org_id));
+ CHECK_OK(d);
yyjson_doc_free(d);
char sql[512];
@@ -5124,6 +5263,7 @@ static const struct ttest TESTS[] = {
{ "sie_export", test_sie_export, "ib" },
{ "sie_import", test_sie_import, "attachments sie_export" },
{ "settings", test_settings, "org_members" },
+ { "series", test_series, "settings" },
{ "smtp_settings", test_smtp_settings, "org_members" },
{ "bank", test_bank, "settings" },
{ "invoices", test_invoices, "org_members" },