Skip to content

Commit 3dfa9ec

Browse files
mivertowskiclaude
andcommitted
Enhance accounting network generation with domain knowledge
Add comprehensive domain-aware features to improve flow matching: Account Classification System: - AccountClass enum (Asset, Liability, Equity, Revenue, COGS, Expense, Tax, Intercompany, Suspense, OtherIncomeExpense, Unknown) - Numeric classification (1xxx=Asset, 2xxx=Liability, etc.) - Keyword-based classification fallback (cash, receivable, payable, etc.) VAT/Tax Detection: - VatDetector with known rates for multiple jurisdictions (UK 20%, Germany 19%, France 20%, Canada GST 5%/HST 13-15%) - Automatic VAT split detection from gross/net amount ratios - VatPattern struct with rate, amounts, and input/output VAT flags Transaction Pattern Recognition: - TransactionPattern enum (SimpleSale, SaleWithVat, SimplePurchase, PurchaseWithVat, Payment, Receipt, Payroll, Depreciation, Accrual, AccrualReversal, Transfer, Intercompany, CostAllocation, Adjustment) - PatternMatcher with configurable patterns - Pattern detection based on account class combinations Enhanced Flow Metadata: - from_account_class, to_account_class on flows - pattern, vat_rate, is_tax_flow, is_intercompany flags - confidence_factors list for matching rationale Confidence Boosting: - Pattern-based confidence adjustments (capped at 1.0) - Higher confidence for recognized transaction patterns - Enhanced statistics tracking (VAT entries, pattern counts) Also includes clippy fixes: - Domain::from_str() renamed to Domain::parse() - Manual strip_prefix usage - Derive Default where applicable - Unused variable prefixes Tests: 75 tests pass (60 original + 15 new enhanced feature tests) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 40bd9f0 commit 3dfa9ec

10 files changed

Lines changed: 1593 additions & 181 deletions

File tree

crates/rustkernel-accounting/src/coa_mapping.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,15 @@ impl ChartOfAccountsMapping {
218218
/// Evaluate a simple condition.
219219
fn evaluate_condition(account: &Account, condition: &str) -> bool {
220220
// Simple attribute-based conditions
221-
if condition.starts_with("attr:") {
222-
let parts: Vec<&str> = condition[5..].splitn(2, '=').collect();
221+
if let Some(stripped) = condition.strip_prefix("attr:") {
222+
let parts: Vec<&str> = stripped.splitn(2, '=').collect();
223223
if parts.len() == 2 {
224224
return account.attributes.get(parts[0]) == Some(&parts[1].to_string());
225225
}
226226
}
227227

228228
// Account type conditions
229-
if condition.starts_with("type:") {
230-
let type_str = &condition[5..];
229+
if let Some(type_str) = condition.strip_prefix("type:") {
231230
return match type_str {
232231
"asset" => account.account_type == crate::types::AccountType::Asset,
233232
"liability" => account.account_type == crate::types::AccountType::Liability,
@@ -303,7 +302,7 @@ impl GpuKernel for ChartOfAccountsMapping {
303302
}
304303

305304
/// Mapping configuration.
306-
#[derive(Debug, Clone)]
305+
#[derive(Debug, Clone, Default)]
307306
pub struct MappingConfig {
308307
/// Include inactive accounts.
309308
pub include_inactive: bool,
@@ -313,16 +312,6 @@ pub struct MappingConfig {
313312
pub strict_mode: bool,
314313
}
315314

316-
impl Default for MappingConfig {
317-
fn default() -> Self {
318-
Self {
319-
include_inactive: false,
320-
default_target: None,
321-
strict_mode: false,
322-
}
323-
}
324-
}
325-
326315
/// Rule validation error.
327316
#[derive(Debug, Clone)]
328317
pub struct RuleValidationError {

crates/rustkernel-accounting/src/journal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//! - Apply GL mappings
77
88
use crate::types::{
9-
ErrorSeverity, JournalEntry, JournalLine, JournalStatus, MappedAccount, MappingResult,
10-
TransformationResult, TransformationStats, ValidationError,
9+
ErrorSeverity, JournalEntry, JournalLine, MappedAccount, MappingResult, TransformationResult,
10+
TransformationStats, ValidationError,
1111
};
1212
use rustkernel_core::{domain::Domain, kernel::KernelMetadata, traits::GpuKernel};
1313
use std::collections::HashMap;
@@ -362,7 +362,7 @@ pub enum PeriodType {
362362
#[cfg(test)]
363363
mod tests {
364364
use super::*;
365-
use crate::types::MappingStats;
365+
use crate::types::{JournalStatus, MappingStats};
366366

367367
fn create_test_entry() -> JournalEntry {
368368
JournalEntry {

crates/rustkernel-accounting/src/network.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl NetworkAnalysis {
253253
}
254254

255255
if let Some(neighbors) = graph.get(current) {
256-
for (next, amount) in neighbors {
256+
for (next, _amount) in neighbors {
257257
if *next == path[0] && path.len() >= 2 {
258258
// Found a cycle
259259
let total_amount: f64 = path

0 commit comments

Comments
 (0)