qunatity ledger in table definition

This commit is contained in:
Priec
2026-07-29 20:25:24 +02:00
parent 7da9b6fe1e
commit 06447e13f3
12 changed files with 23 additions and 8 deletions

2
client

Submodule client updated: 71b5cff16d...c7ba851c73

View File

@@ -197,7 +197,9 @@ message ColumnDefinition {
// MONEY rounding applied before a value is stored. // MONEY rounding applied before a value is stored.
MoneyRounding rounding = 4; MoneyRounding rounding = 4;
reserved 5; // When true, this numeric column is server-owned and projected from the
// profile quantity ledger.
bool quantity_ledger = 5;
} }
// Response after table creation (success + DDL preview). // Response after table creation (success + DDL preview).

View File

@@ -73,9 +73,8 @@ message TableColumn {
// Typically true for the "id" column created by the system. // Typically true for the "id" column created by the system.
bool is_primary_key = 4; bool is_primary_key = 4;
// True for a user-defined column whose logic should be recomputed whenever // True when this column is projected from the profile quantity ledger.
// one of its dependencies changes. False for system and foreign-key columns. bool quantity_ledger = 5;
reserved 5;
// True when the server created this as a companion of another logical column. // True when the server created this as a companion of another logical column.
bool generated = 6; bool generated = 6;

Binary file not shown.

View File

@@ -166,6 +166,10 @@ pub struct ColumnDefinition {
/// MONEY rounding applied before a value is stored. /// MONEY rounding applied before a value is stored.
#[prost(enumeration = "MoneyRounding", tag = "4")] #[prost(enumeration = "MoneyRounding", tag = "4")]
pub rounding: i32, pub rounding: i32,
/// When true, this numeric column is server-owned and projected from the
/// profile quantity ledger.
#[prost(bool, tag = "5")]
pub quantity_ledger: bool,
} }
/// Response after table creation (success + DDL preview). /// Response after table creation (success + DDL preview).
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]

View File

@@ -55,6 +55,9 @@ pub struct TableColumn {
/// Typically true for the "id" column created by the system. /// Typically true for the "id" column created by the system.
#[prost(bool, tag = "4")] #[prost(bool, tag = "4")]
pub is_primary_key: bool, pub is_primary_key: bool,
/// True when this column is projected from the profile quantity ledger.
#[prost(bool, tag = "5")]
pub quantity_ledger: bool,
/// True when the server created this as a companion of another logical column. /// True when the server created this as a companion of another logical column.
#[prost(bool, tag = "6")] #[prost(bool, tag = "6")]
pub generated: bool, pub generated: bool,

View File

@@ -74,6 +74,7 @@ impl CreateTableForm {
name: name.to_string(), name: name.to_string(),
field_type: field_type.to_string(), field_type: field_type.to_string(),
rounding: rounding.into(), rounding: rounding.into(),
quantity_ledger: flags.contains(&"quantity-ledger"),
}); });
} }
if columns.is_empty() { if columns.is_empty() {
@@ -143,7 +144,7 @@ mod tests {
let request = CreateTableForm { let request = CreateTableForm {
profile_name: "accounting".into(), profile_name: "accounting".into(),
table_name: "invoice".into(), table_name: "invoice".into(),
columns: "number: text:indexed\namount: money:half-up".into(), columns: "number: text:indexed\namount: money:half-up,quantity-ledger".into(),
required_links: "customer".into(), required_links: "customer".into(),
base_currency: "eur".into(), base_currency: "eur".into(),
row_display_columns: "number, amount".into(), row_display_columns: "number, amount".into(),
@@ -157,5 +158,6 @@ mod tests {
assert!(request.links[0].required); assert!(request.links[0].required);
assert_eq!(request.base_currency, "EUR"); assert_eq!(request.base_currency, "EUR");
assert_eq!(request.row_display_columns, vec!["number", "amount"]); assert_eq!(request.row_display_columns, vec!["number", "amount"]);
assert!(request.columns[1].quantity_ledger);
} }
} }

View File

@@ -21,7 +21,7 @@ pub(crate) fn render_page(page: &AddTablePageState) -> String {
.map(render_submission_error) .map(render_submission_error)
.unwrap_or_default(); .unwrap_or_default();
format!( format!(
"<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><title>Add table</title><script src=\"https://cdn.jsdelivr.net/npm/htmx.org@2/dist/htmx.min.js\"></script><style>{ADMIN_CSS}</style></head><body><header class=\"topbar\"><div><strong>Komp Accounting</strong></div><nav><a href=\"/admin\">Admin</a><a href=\"/\">Analytics</a></nav></header><main class=\"form-main\"><a class=\"back-link\" href=\"/admin\">← Admin panel</a><section class=\"form-card\"><p class=\"eyebrow\">Table definition</p><h1>Add table</h1><p>Create a table through the existing gRPC table-definition service.</p><form hx-post=\"/admin/tables\" hx-target=\"#submission-status\" hx-swap=\"innerHTML\" hx-disabled-elt=\"button[type=submit]\"><div class=\"form-grid\"><label>Profile<select name=\"profile_name\" required><option value=\"\">Choose a profile</option>{options}</select></label><label>Table name<input name=\"table_name\" value=\"{}\" required placeholder=\"invoices\"></label><label class=\"wide\">Columns<textarea name=\"columns\" rows=\"9\" required placeholder=\"number: text:indexed&#10;issued_on: date&#10;amount: money:half-up\">{}</textarea><small>One per line: <code>name: type: optional flags</code>. Flags: indexed, half-up.</small></label><label>Additional indexed columns<input name=\"indexed_columns\" value=\"{}\" placeholder=\"number, issued_on\"></label><label>Base currency<input name=\"base_currency\" value=\"{}\" maxlength=\"3\" placeholder=\"EUR\"></label><label>Required links<input name=\"required_links\" value=\"{}\" placeholder=\"customer, address\"></label><label>Optional links<input name=\"optional_links\" value=\"{}\" placeholder=\"project\"></label><label>Row display columns<input name=\"row_display_columns\" value=\"{}\" placeholder=\"name, ico\"></label></div><div id=\"submission-status\" aria-live=\"polite\">{error}</div><div class=\"form-actions\"><a href=\"/admin\">Cancel</a><button type=\"submit\">Create table</button></div></form></section></main></body></html>", "<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><title>Add table</title><script src=\"https://cdn.jsdelivr.net/npm/htmx.org@2/dist/htmx.min.js\"></script><style>{ADMIN_CSS}</style></head><body><header class=\"topbar\"><div><strong>Komp Accounting</strong></div><nav><a href=\"/admin\">Admin</a><a href=\"/\">Analytics</a></nav></header><main class=\"form-main\"><a class=\"back-link\" href=\"/admin\">← Admin panel</a><section class=\"form-card\"><p class=\"eyebrow\">Table definition</p><h1>Add table</h1><p>Create a table through the existing gRPC table-definition service.</p><form hx-post=\"/admin/tables\" hx-target=\"#submission-status\" hx-swap=\"innerHTML\" hx-disabled-elt=\"button[type=submit]\"><div class=\"form-grid\"><label>Profile<select name=\"profile_name\" required><option value=\"\">Choose a profile</option>{options}</select></label><label>Table name<input name=\"table_name\" value=\"{}\" required placeholder=\"invoices\"></label><label class=\"wide\">Columns<textarea name=\"columns\" rows=\"9\" required placeholder=\"number: text:indexed&#10;issued_on: date&#10;stock: int:quantity-ledger\">{}</textarea><small>One per line: <code>name: type: optional flags</code>. Flags: indexed, half-up, quantity-ledger.</small></label><label>Additional indexed columns<input name=\"indexed_columns\" value=\"{}\" placeholder=\"number, issued_on\"></label><label>Base currency<input name=\"base_currency\" value=\"{}\" maxlength=\"3\" placeholder=\"EUR\"></label><label>Required links<input name=\"required_links\" value=\"{}\" placeholder=\"customer, address\"></label><label>Optional links<input name=\"optional_links\" value=\"{}\" placeholder=\"project\"></label><label>Row display columns<input name=\"row_display_columns\" value=\"{}\" placeholder=\"name, ico\"></label></div><div id=\"submission-status\" aria-live=\"polite\">{error}</div><div class=\"form-actions\"><a href=\"/admin\">Cancel</a><button type=\"submit\">Create table</button></div></form></section></main></body></html>",
crate::escape_html(&page.form.table_name), crate::escape_html(&page.form.table_name),
crate::escape_html(&page.form.columns), crate::escape_html(&page.form.columns),
crate::escape_html(&page.form.indexed_columns), crate::escape_html(&page.form.indexed_columns),

View File

@@ -113,6 +113,7 @@ pub(crate) async fn load_admin_page(
data_type: column.data_type.clone(), data_type: column.data_type.clone(),
nullable: column.is_nullable, nullable: column.is_nullable,
primary_key: column.is_primary_key, primary_key: column.is_primary_key,
quantity_ledger: column.quantity_ledger,
}) })
.collect() .collect()
} }

View File

@@ -35,6 +35,7 @@ pub(crate) struct ColumnView {
pub data_type: String, pub data_type: String,
pub nullable: bool, pub nullable: bool,
pub primary_key: bool, pub primary_key: bool,
pub quantity_ledger: bool,
} }
#[derive(Debug)] #[derive(Debug)]

View File

@@ -95,6 +95,9 @@ fn render_columns(page: &AdminPageState) -> String {
} else { } else {
flags.push("required"); flags.push("required");
} }
if column.quantity_ledger {
flags.push("quantity ledger");
}
format!( format!(
"<div class=\"column\"><span>{}</span><code>{}</code><small>{}</small></div>", "<div class=\"column\"><span>{}</span><code>{}</code><small>{}</small></div>",
crate::escape_html(&column.name), crate::escape_html(&column.name),

2
server

Submodule server updated: b44238ec3b...d4343fe48b