Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

refactor: genericize chart of accounts levels #1527

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

vindard
Copy link
Contributor

@vindard vindard commented Mar 2, 2025

Description

This PR will be to change the fixed-depth hierarchy of our current Chart of Accounts to an any-depth hierachy. The current Chart is made up of Categories, ControlAccounts and ControlSubAccounts. The new structure will simply have nested Nodes and Leaves.

The scope of this PR is simply to move our existing Charts implementation from the old hierarchy to the new hierarchy.

Segmentation

In the old model, account codes were derived sequentially based on the parent entity. In the new model, a SegmentationSchema will be defined for the chart and user-defined account codes will be validated against this schema. The schema contains information about:

  • number of levels in the hierarchy, represented by number of segments
  • the length of code as defined by the aggregate of fixed lengths of each segment/level

User-provided codes will be validated via:

  • valid characters
  • segmentation schema conformity
  • uniqueness in the chart

Samples from Domain Projection

Old
ChartTree {
    id: ChartId(
        0200d1d3-59ec-44f8-891a-b3dbceebbe3e,
    ),
    name: "Test Chart",
    assets: ChartTreeCategory {
        name: "Assets",
        encoded_path: "10000",
        children: [
            ChartTreeControlAccount {
                name: "Loans Receivable",
                encoded_path: "10100",
                children: [
                    ChartTreeControlSubAccount {
                        name: "Fixed Loans Receivable",
                        encoded_path: "10101",
                    },
                ],
            },
        ],
    },
    liabilities: ChartTreeCategory {
        name: "Liabilities",
        encoded_path: "20000",
        children: [
            ChartTreeControlAccount {
                name: "User Checking",
                encoded_path: "20100",
                children: [
                    ChartTreeControlSubAccount {
                        name: "User Checking",
                        encoded_path: "20101",
                    },
                ],
            },
        ],
    },
    equity: ChartTreeCategory {
        name: "Equity",
        encoded_path: "30000",
        children: [
            ChartTreeControlAccount {
                name: "Shareholder Equity",
                encoded_path: "30100",
                children: [
                    ChartTreeControlSubAccount {
                        name: "Shareholder Equity",
                        encoded_path: "30101",
                    },
                ],
            },
        ],
    },
    revenues: ChartTreeCategory {
        name: "Revenues",
        encoded_path: "40000",
        children: [
            ChartTreeControlAccount {
                name: "Interest Revenue",
                encoded_path: "40100",
                children: [],
            },
        ],
    },
    expenses: ChartTreeCategory {
        name: "Expenses",
        encoded_path: "50000",
        children: [],
    },
}
New
ChartTreeAlt {
    id: ChartId(
        d2b8c01e-023e-46fd-bafe-0fed171741c6,
    ),
    name: "Test Chart",
    children: [
        Node {
            id: AccountSetId(
                9b2cdbe6-2371-4ba2-96bb-3d474ccb1348,
            ),
            reference: "assets",
            encoded_path: EncodedPath {
                value: "1",
            },
            parent: None,
            children: [
                Node {
                    id: AccountSetId(
                        134bd004-0b4f-4d2f-850b-8a3ddd602021,
                    ),
                    reference: "loans-receivable",
                    encoded_path: EncodedPath {
                        value: "10",
                    },
                    parent: Some(
                        EncodedPath {
                            value: "1",
                        },
                    ),
                    children: [
                        Node {
                            id: AccountSetId(
                                85450f8c-2f0b-4371-bdb1-5836ccded321,
                            ),
                            reference: "fixed-loans-receivable",
                            encoded_path: EncodedPath {
                                value: "100",
                            },
                            parent: Some(
                                EncodedPath {
                                    value: "10",
                                },
                            ),
                            children: [
                                Leaf {
                                    id: AccountSetId(
                                        4e1af726-ab76-485b-b95a-1dd3ecf85e7e,
                                    ),
                                    reference: "fixed-loans-receivable-01",
                                    encoded_path: EncodedPath {
                                        value: "1000",
                                    },
                                    parent: Some(
                                        EncodedPath {
                                            value: "100",
                                        },
                                    ),
                                },
                                Leaf {
                                    id: AccountSetId(
                                        c2d7f866-44a3-4e31-9ef2-d097c245dd33,
                                    ),
                                    reference: "fixed-loans-receivable-02",
                                    encoded_path: EncodedPath {
                                        value: "1001",
                                    },
                                    parent: Some(
                                        EncodedPath {
                                            value: "100",
                                        },
                                    ),
                                },
                            ],
                        },
                    ],
                },
            ],
        },
        Node {
            id: AccountSetId(
                d2c43bfb-ca25-439a-970b-8ee5b9589b50,
            ),
            reference: "liabilities",
            encoded_path: EncodedPath {
                value: "2",
            },
            parent: None,
            children: [
                Node {
                    id: AccountSetId(
                        48911139-8c90-4b53-b790-772dae253ca7,
                    ),
                    reference: "user-checking",
                    encoded_path: EncodedPath {
                        value: "20",
                    },
                    parent: Some(
                        EncodedPath {
                            value: "2",
                        },
                    ),
                    children: [
                        Node {
                            id: AccountSetId(
                                c4951a75-c1fd-4779-883d-351f5488eb0b,
                            ),
                            reference: "sub-user-checking",
                            encoded_path: EncodedPath {
                                value: "200",
                            },
                            parent: Some(
                                EncodedPath {
                                    value: "20",
                                },
                            ),
                            children: [
                                Leaf {
                                    id: AccountSetId(
                                        b38b520e-1fc0-49f3-a26d-5b1ad44363eb,
                                    ),
                                    reference: "sub-user-checking-01",
                                    encoded_path: EncodedPath {
                                        value: "2000",
                                    },
                                    parent: Some(
                                        EncodedPath {
                                            value: "200",
                                        },
                                    ),
                                },
                            ],
                        },
                    ],
                },
            ],
        },
    ],
}

@vindard vindard force-pushed the refactor-chart-of-accounts branch 3 times, most recently from 34725de to 9d82aa8 Compare March 2, 2025 03:41
@vindard vindard force-pushed the refactor-chart-of-accounts branch from 9d82aa8 to 4aeb4e4 Compare March 2, 2025 04:00
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant