quickbooks_types/models/
account.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4use super::common::{MetaData, NtRef};
5#[cfg(feature = "builder")]
6use crate::error::QBTypeError;
7use crate::{QBCreatable, QBFullUpdatable, QBItem};
8
9#[skip_serializing_none]
10#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
11#[serde(rename_all = "PascalCase", default)]
12#[cfg_attr(
13    feature = "builder",
14    derive(Builder),
15    builder(default, build_fn(error = "QBTypeError"), setter(into, strip_option))
16)]
17
18/// Account
19///
20/// Represents a general ledger account in `QuickBooks` Online (for example: Bank, Income, Expense).
21/// Accounts categorize transactions and track balances. Many entities reference an account via `*Ref` fields.
22///
23/// Creation requirements:
24/// - `QBCreatable::can_create()` returns true when `name` is set and either `account_type` or `account_sub_type` is set.
25///
26/// Update semantics:
27/// - `QBFullUpdatable::can_full_update()` returns true when `has_read()` (ID + sync token present) and `name` are set.
28///
29/// API reference:
30/// <https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/account>
31pub struct Account {
32    /// The unique ID of the entity
33    pub id: Option<String>,
34    /// The unique sync token of the entity, used for concurrency control
35    pub sync_token: Option<String>,
36    /// Metadata about the entity
37    #[serde(skip_serializing)]
38    pub meta_data: Option<MetaData>,
39    /// Name of the account
40    pub name: Option<String>,
41    /// Account number
42    pub acct_num: Option<String>,
43    /// Reference to the currency for the account
44    pub currency_ref: Option<NtRef>,
45    /// Reference to the parent account if this is a sub-account
46    pub parent_ref: Option<NtRef>,
47    /// Description of the account
48    pub descripton: Option<String>,
49    /// Indicates if the account is active
50    pub active: Option<bool>,
51    /// Indicates if the account is a sub-account
52    pub sub_account: Option<bool>,
53    /// Classification of the account
54    pub classification: Option<String>,
55    /// Fully qualified name of the account
56    pub fully_qualified_name: Option<String>,
57    /// Location type for transactions in this account
58    pub txn_location_type: Option<String>,
59    /// Type of account
60    pub account_type: Option<AccountType>,
61    /// Current balance including sub-accounts
62    pub current_balance_with_sub_accounts: Option<f64>,
63    /// Alternative name for the account
64    pub account_alias: Option<String>,
65    /// Reference to the tax code associated with the account
66    pub tax_code_ref: Option<NtRef>,
67    /// Sub-type of the account
68    pub account_sub_type: Option<String>,
69    /// Current balance of the account
70    pub current_balance: Option<f64>,
71}
72
73/// `AccountType`
74///
75/// High-level classification of an account (for example: Bank, `OtherAsset`, Income).
76/// Note: This enum is currently a placeholder; concrete variants will be added as the API surface is implemented.
77#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
78#[serde(rename_all = "PascalCase")]
79pub enum AccountType {
80    #[default]
81    TODO, // TODO: Define actual types
82}
83
84impl QBCreatable for Account {
85    fn can_create(&self) -> bool {
86        self.name.is_some() && (self.account_type.is_some() || self.account_sub_type.is_some())
87    }
88}
89
90impl QBFullUpdatable for Account {
91    fn can_full_update(&self) -> bool {
92        self.name.is_some() && self.has_read()
93    }
94}