pub struct Account {
pub id: Uuid,
pub code: String,
pub label: String,
pub parent_code: Option<String>,
pub account_type: AccountType,
pub direct_use: bool,
pub organization_id: Uuid,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}Expand description
Account in the Belgian Normalized Accounting Plan (PCMN)
Represents a single account in the hierarchical chart of accounts.
Structure inspired by Noalyss tmp_pcmn table.
§Hierarchical Structure
Accounts can have parent-child relationships for organization:
6 (Charges/Expenses - parent: None)
60 (Approvisionnements - parent: "6")
604 (Fournitures - parent: "60")
604001 (Électricité - parent: "604")§Belgian PCMN Classes
- Class 1: Liabilities (Capital, Reserves, Provisions)
- Classes 2-5: Assets (Fixed assets, Inventory, Receivables, Cash)
- Class 6: Expenses (Purchases, Services, Salaries)
- Class 7: Revenue (Sales, Services, Financial income)
- Class 9: Off-balance (Control accounts)
Reference: Belgian Royal Decree AR 12/07/2012
Fields§
§id: UuidUnique identifier
code: StringAccount code (e.g., “700”, “604001”, “100”)
Can be hierarchical. Parent codes are typically shorter. Example: “604001” is child of “604” which is child of “60”
label: StringAccount label/description
Examples:
- “Électricité” (Electricity)
- “Appels de fonds ordinaires” (Regular fees)
- “Assurance immeuble” (Building insurance)
parent_code: Option<String>Parent account code for hierarchical organization
None if this is a top-level account (e.g., “6”, “7”) Some(“604”) if this is a child account (e.g., “604001”)
account_type: AccountTypeAccount classification (Asset, Liability, Expense, Revenue, OffBalance)
direct_use: boolWhether this account can be used directly in journal entries
- true: Can post transactions to this account (e.g., “604001” - Electricity)
- false: Summary account only (e.g., “60” - Approvisionnements)
Corresponds to Noalyss pcm_direct_use field (Y/N)
organization_id: UuidOrganization this account belongs to (multi-tenancy)
created_at: DateTime<Utc>Creation timestamp
updated_at: DateTime<Utc>Last update timestamp
Implementations§
Source§impl Account
impl Account
Sourcepub fn new(
code: String,
label: String,
parent_code: Option<String>,
account_type: AccountType,
direct_use: bool,
organization_id: Uuid,
) -> Result<Self, String>
pub fn new( code: String, label: String, parent_code: Option<String>, account_type: AccountType, direct_use: bool, organization_id: Uuid, ) -> Result<Self, String>
Create a new account with validation
§Arguments
code- Account code (must be non-empty)label- Account description (must be non-empty)parent_code- Optional parent account codeaccount_type- Account classificationdirect_use- Whether account can be used in transactionsorganization_id- Organization ID
§Returns
Ok(Account) if validation passes, Err(String) otherwise
§Validation Rules
- Code must not be empty
- Code must be alphanumeric (can contain letters for auxiliary accounts)
- Label must not be empty
- Label must be <= 255 characters
- Parent code cannot equal code (prevent self-reference)
Sourcepub fn get_class(&self) -> &str
pub fn get_class(&self) -> &str
Get the account class (first digit for Belgian PCMN)
§Examples
let account = Account::new(
"604001".to_string(),
"Electricity".to_string(),
Some("604".to_string()),
account::AccountType::Expense,
true,
org_id
).unwrap();
assert_eq!(account.get_class(), "6");Sourcepub fn update(
&mut self,
label: Option<String>,
parent_code: Option<Option<String>>,
account_type: Option<AccountType>,
direct_use: Option<bool>,
) -> Result<(), String>
pub fn update( &mut self, label: Option<String>, parent_code: Option<Option<String>>, account_type: Option<AccountType>, direct_use: Option<bool>, ) -> Result<(), String>
Update account details
§Arguments
label- New label (optional, keeps current if None)parent_code- New parent code (optional, keeps current if None)account_type- New type (optional, keeps current if None)direct_use- New direct use flag (optional, keeps current if None)
§Returns
Ok(()) if validation passes, Err(String) otherwise
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Account
impl<'de> Deserialize<'de> for Account
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Account
Auto Trait Implementations§
impl Freeze for Account
impl RefUnwindSafe for Account
impl Send for Account
impl Sync for Account
impl Unpin for Account
impl UnwindSafe for Account
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Chain<T> for T
impl<T> Chain<T> for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Fake for T
impl<T> Fake for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more