Skip to main content

quickbooks_types/models/
class.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4use crate::{
5    common::{MetaData, NtRef},
6    QBCreatable, QBFullUpdatable, QBReadable,
7};
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/// Class
18///
19/// Represents a classification or category that can be applied to transactions and entities in `QuickBooks` Online. Classes allow for tracking and reporting on different segments of a business, such as departments, locations, or product lines. A class can have a hierarchical structure with parent and child classes.
20///
21/// API reference:
22/// <https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/class>
23pub struct Class {
24    /// The unique ID of the entity
25    pub id: Option<String>,
26    /// The unique sync token of the entity, used for concurrency control
27    pub sync_token: Option<String>,
28    /// Metadata about the entity
29    #[serde(skip_serializing)]
30    pub meta_data: Option<MetaData>,
31    /// Name of the class
32    pub name: Option<String>,
33    /// Reference to the parent class if this is a subclass
34    pub parent_ref: Option<NtRef>,
35    /// Indicates whether this object is a subclass
36    pub sub_class: Option<bool>,
37    /// Indicates if the class is active
38    pub active: Option<bool>,
39    /// Fully qualified name of the class (e.g., Parent:SubClass)
40    pub fully_qualified_name: Option<String>,
41}
42
43impl QBCreatable for Class {
44    fn can_create(&self) -> bool {
45        self.id.is_none()
46            && self.sync_token.is_none()
47            && self.meta_data.is_none()
48            && self.name.is_some()
49            && if let Some(true) = self.sub_class {
50                self.parent_ref.is_some()
51            } else {
52                true
53            }
54    }
55}
56
57impl QBFullUpdatable for Class {
58    fn can_full_update(&self) -> bool {
59        self.can_read()
60    }
61}