quickbooks_types/models/
preferences.rs

1use chrono::NaiveDate;
2use serde::{Deserialize, Serialize};
3use serde_with::skip_serializing_none;
4
5#[cfg(feature = "builder")]
6use crate::error::QBTypeError;
7use crate::{
8    common::{Email, MetaData, NtRef},
9    QBFullUpdatable, QBItem,
10};
11
12#[skip_serializing_none]
13#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
14#[serde(rename_all = "PascalCase", default)]
15#[cfg_attr(
16    feature = "builder",
17    derive(Builder),
18    builder(default, build_fn(error = "QBTypeError"), setter(into, strip_option))
19)]
20/// Preferences
21///
22/// Company-wide configuration controlling behavior for sales forms,
23/// purchasing, accounting, taxes, time tracking, currencies, and messaging
24/// in `QuickBooks` Online.
25///
26/// Semantics:
27/// - Models data only; no HTTP calls are performed in this crate.
28/// - `QBFullUpdatable::can_full_update()` returns true when `has_read()` is true
29///   (both `id` and `sync_token` are present).
30///
31/// API reference:
32/// <https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/preferences>
33pub struct Preferences {
34    /// The unique ID of the entity
35    pub id: Option<String>,
36    /// The unique sync token of the entity, used for concurrency control
37    pub sync_token: Option<String>,
38    /// Metadata about the entity
39    #[serde(skip_serializing)]
40    pub meta_data: Option<MetaData>,
41    /// Preferences for email messages
42    pub email_message_prefs: Option<EmailMessagePrefs>,
43    /// Preferences for products and services
44    pub product_and_services_prefs: Option<ProductAndServicesPrefs>,
45    /// Preferences for reports
46    pub report_prefs: Option<ReportPrefs>,
47    /// Preferences for accounting information
48    pub accounting_info_prefs: Option<AccountingInfoPrefs>,
49    /// Preferences for sales forms
50    pub sales_forms_prefs: Option<SalesFormsPrefs>,
51    /// Preferences for vendors and purchases
52    pub vendor_and_purchases_prefs: Option<VendorAndPurchasesPrefs>,
53    /// Preferences for taxes
54    pub tax_prefs: Option<TaxPrefs>,
55    /// Other miscellaneous preferences
56    pub other_prefs: Option<OtherPrefs>,
57    /// Preferences for time tracking
58    pub time_tracking_prefs: Option<TimeTrackingPrefs>,
59    /// Preferences for currency
60    pub currency_prefs: Option<CurrencyPrefs>,
61}
62
63/// Email Message Preferences
64#[skip_serializing_none]
65#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
66#[serde(rename_all = "PascalCase", default)]
67pub struct EmailMessagePrefs {
68    pub invoice_message: Option<EmailMessageType>,
69    pub estimate_message: Option<EmailMessageType>,
70    pub sales_receipt_message: Option<EmailMessageType>,
71    pub statement_message: Option<EmailMessageType>,
72}
73
74/// Email Message Type
75#[skip_serializing_none]
76#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
77#[serde(rename_all = "PascalCase", default)]
78pub struct EmailMessageType {
79    pub message: Option<String>,
80    pub subject: Option<String>,
81}
82
83/// Product and Services Preferences
84#[skip_serializing_none]
85#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
86#[serde(rename_all = "PascalCase", default)]
87pub struct ProductAndServicesPrefs {
88    pub revenue_recognition_enabled: Option<bool>,
89    pub recognition_frequency_type: Option<String>,
90    pub for_sales: Option<bool>,
91    pub quantity_on_hand: Option<bool>,
92    pub quantity_with_price_and_rate: Option<bool>,
93    pub for_purchase: Option<bool>,
94}
95
96/// Report Preferences
97#[skip_serializing_none]
98#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
99#[serde(rename_all = "PascalCase", default)]
100pub struct ReportPrefs {
101    pub report_basis: Option<String>,
102    pub calc_aging_report_from_txn_date: Option<bool>,
103}
104
105/// Accounting Info Preferences
106#[skip_serializing_none]
107#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
108#[serde(rename_all = "PascalCase", default)]
109pub struct AccountingInfoPrefs {
110    pub first_month_of_fiscal_year: Option<String>,
111    pub use_account_numbers: Option<bool>,
112    pub tax_year_month: Option<String>,
113    pub class_tracking_per_txn: Option<bool>,
114    pub track_departments: Option<bool>,
115    pub tax_form: Option<String>,
116    pub customer_terminology: Option<String>,
117    pub book_close_date: Option<NaiveDate>,
118    pub department_terminology: Option<String>,
119    pub class_tracking_per_txn_line: Option<bool>,
120}
121
122#[skip_serializing_none]
123#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
124#[serde(rename_all = "PascalCase", default)]
125/// Sales Forms Preferences
126///
127/// Represents the preferences for sales forms in `QuickBooks`.
128pub struct SalesFormsPrefs {
129    /// BCC email address for sales forms.
130    pub sales_emaill_bcc: Option<Email>,
131    /// CC email address for sales forms.
132    pub sales_email_cc: Option<Email>,
133    /// Indicates if progress invoicing is being used.
134    pub using_progress_invoicing: Option<bool>,
135    /// Custom field for sales forms.
136    pub custom_field: Option<String>, // TODO
137    /// Indicates if service date is allowed on sales forms.
138    pub allow_service_date: Option<bool>,
139    /// Default message for estimates.
140    pub estimate_message: Option<String>,
141    /// Indicates if a copy of the email should be sent to the company.
142    pub email_copy_to_company: Option<bool>,
143    /// Default customer message for sales forms.
144    pub default_customer_message: Option<String>,
145    /// Indicates if shipping is allowed on sales forms.
146    pub allow_shipping: Option<bool>,
147    /// Indicates if the default discount account is enabled.
148    pub default_discount_account: Option<bool>,
149    /// Indicates if IPN support is enabled.
150    #[serde(rename = "IPNSupportEnabled")]
151    pub ipn_support_enabled: Option<bool>,
152    /// Indicates if e-transaction payment is enabled.
153    pub e_transaction_payment_enabled: Option<bool>,
154    /// Default terms for sales forms.
155    pub default_terms: Option<NtRef>,
156    /// Indicates if deposits are allowed on sales forms.
157    pub allow_deposit: Option<bool>,
158    /// Indicates if price levels are being used.
159    pub using_price_levels: Option<bool>,
160    /// Indicates if the default shipping account is enabled.
161    pub default_shipping_account: Option<bool>,
162    /// Indicates if e-transaction PDF attachment is enabled.
163    #[serde(rename = "ETransactionAttachPDF")]
164    pub e_transaction_attach_pdf: Option<bool>,
165    /// Indicates if custom transaction numbers are allowed.
166    pub custom_txn_numbers: Option<bool>,
167    /// Status of e-transaction enabled.
168    pub e_transaction_enabled_status: Option<String>,
169    /// Indicates if estimates are allowed.
170    pub allow_estimates: Option<bool>,
171    /// Indicates if discounts are allowed.
172    pub allow_discount: Option<bool>,
173    /// Indicates if auto-apply credit is enabled.
174    pub auto_apply_credit: Option<bool>,
175}
176
177#[skip_serializing_none]
178#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
179#[serde(rename_all = "PascalCase", default)]
180/// Vendor and Purchases Preferences
181///
182/// Represents the preferences related to vendors and purchases.
183pub struct VendorAndPurchasesPrefs {
184    /// Custom field for purchase orders
185    #[serde(rename = "POCustomField")]
186    pub po_custom_field: Option<String>, // TODO
187    /// Reference to the default markup account
188    pub default_markup_account: Option<NtRef>,
189    /// Indicates if tracking by customer is enabled
190    pub tracking_by_customer: Option<bool>,
191    /// Reference to the default terms
192    pub default_terms: Option<NtRef>,
193    /// Indicates if billable expense tracking is enabled
194    pub billable_expense_tracking: Option<bool>,
195    /// Default markup value
196    pub default_markup: Option<f64>,
197    /// Indicates if TPAR (Taxable Payments Annual Report) is enabled
198    #[serde(rename = "TPAREnabled")]
199    pub tpar_enabled: Option<bool>,
200}
201
202/// Tax Preferences
203#[skip_serializing_none]
204#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
205#[serde(rename_all = "PascalCase", default)]
206pub struct TaxPrefs {
207    pub partner_tax_enabled: Option<bool>,
208    pub tax_group_code_ref: Option<String>,
209    pub using_sales_tax: Option<bool>,
210}
211
212/// Miscellaneous Other Preferences
213#[skip_serializing_none]
214#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
215#[serde(rename_all = "PascalCase", default)]
216pub struct OtherPrefs {
217    pub name_value: Option<Vec<NtRef>>,
218}
219
220#[skip_serializing_none]
221#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
222#[serde(rename_all = "PascalCase", default)]
223/// Time Tracking Preferences
224///
225/// Represents the preferences for time tracking in `QuickBooks`.
226pub struct TimeTrackingPrefs {
227    /// The start date of the work week.
228    pub work_week_start_date: Option<String>,
229    /// Indicates if time entries should be marked as billable.
230    pub mark_time_entries_billable: Option<bool>,
231    /// Indicates if the bill rate should be shown to all users.
232    pub show_bill_rate_to_all: Option<bool>,
233    /// Indicates if sales tax is being used.
234    pub using_sales_tax: Option<bool>,
235    /// Indicates if customers should be billed.
236    pub bill_customers: Option<bool>,
237}
238
239/// Currency Preferences
240///
241/// Represents the preferences related to currency handling in `QuickBooks`.
242#[skip_serializing_none]
243#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
244#[serde(rename_all = "PascalCase", default)]
245pub struct CurrencyPrefs {
246    pub home_currency: Option<NtRef>,
247    pub multi_currency_enabled: Option<bool>,
248}
249
250impl QBFullUpdatable for Preferences {
251    fn can_full_update(&self) -> bool {
252        self.has_read()
253    }
254}