quickbooks_types/models/
vendor.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4use super::common::{Addr, Email, MetaData, NtRef, PhoneNumber, WebAddr};
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/// Vendor
18///
19/// Represents a supplier/payee from whom goods or services are purchased and to whom bills are owed in `QuickBooks` Online.
20///
21/// Creation requirements:
22/// - `QBCreatable::can_create()` returns true when at least one of the following is present:
23///   `display_name`, `given_name`, `family_name`, `middle_name`, `title`, or `suffix`.
24///
25/// Update semantics:
26/// - `QBFullUpdatable::can_full_update()` returns true when both `has_read()` (ID + sync token are set)
27///   and `can_create()` are true.
28///
29/// API reference:
30/// <https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/vendor>
31pub struct Vendor {
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    /// Title of the vendor
40    pub title: Option<String>,
41    /// Given name of the vendor
42    pub given_name: Option<String>,
43    /// Middle name of the vendor
44    pub middle_name: Option<String>,
45    /// Suffix of the vendor's name
46    pub suffix: Option<String>,
47    /// Family name of the vendor
48    pub family_name: Option<String>,
49    /// Primary email address of the vendor
50    pub primary_email_addr: Option<Email>,
51    /// Display name of the vendor
52    pub display_name: Option<String>,
53    /// Other contact information for the vendor
54    pub other_contact_info: Option<ContactInfo>,
55    /// Accounts Payable account reference
56    #[serde(rename = "APAccountRef")]
57    pub ap_account_ref: Option<NtRef>,
58    /// Term reference for the vendor
59    pub term_ref: Option<NtRef>,
60    /// Source of the vendor information
61    ///
62    /// DEPRECATED: as of 9/15/2025
63    pub source: Option<String>,
64    /// GSTIN of the vendor
65    #[serde(rename = "GSTIN")]
66    pub gstin: Option<String>,
67    /// Indicates if the vendor is T4A eligible
68    #[serde(rename = "T4AEligible")]
69    pub t4a_eligible: Option<bool>,
70    /// Fax number of the vendor
71    pub fax: Option<PhoneNumber>,
72    /// Business number of the vendor
73    pub business_number: Option<String>,
74    /// Currency reference for the vendor
75    pub currency_ref: Option<NtRef>,
76    /// Indicates if the vendor has TPAR
77    #[serde(rename = "HasTPAR")]
78    pub has_tpar: Option<bool>,
79    /// Tax reporting basis for the vendor
80    pub tax_reporting_basis: Option<String>,
81    /// Mobile phone number of the vendor
82    pub mobile: Option<PhoneNumber>,
83    /// Primary phone number of the vendor
84    pub primary_phone: Option<PhoneNumber>,
85    /// Indicates if the vendor is active
86    pub active: Option<bool>,
87    /// Alternate phone number of the vendor
88    pub alternate_phone: Option<PhoneNumber>,
89    /// Indicates if the vendor is 1099 eligible
90    pub vendor_1099: Option<bool>,
91    /// Cost rate for the vendor
92    pub cost_rate: Option<f64>,
93    /// Bill rate for the vendor
94    pub bill_rate: Option<f64>,
95    /// Web address of the vendor
96    pub web_addr: Option<WebAddr>,
97    /// Indicates if the vendor is T5018 eligible
98    pub t5018_eligible: Option<bool>,
99    /// Company name of the vendor
100    pub company_name: Option<String>,
101    /// Bank details for vendor payment
102    pub vendor_payment_bank_detail: Option<VendorPaymentBankDetail>,
103    /// Tax identifier for the vendor
104    pub tax_identifier: Option<String>,
105    /// Account number for the vendor
106    pub acct_num: Option<String>,
107    /// GST registration type for the vendor
108    #[serde(rename = "GSTRegistrationType")]
109    pub gst_registration_type: Option<String>,
110    /// Name to print on checks for the vendor
111    pub print_check_on_name: Option<String>,
112    /// Billing address of the vendor
113    pub bill_addr: Option<Addr>,
114    /// Balance for the vendor
115    pub balance: Option<f64>,
116}
117
118/// Contact Information
119///
120/// Represents additional contact information for a vendor in `QuickBooks` Online.
121#[skip_serializing_none]
122#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
123#[serde(rename_all = "PascalCase", default)]
124pub struct ContactInfo {
125    #[serde(rename = "Type")]
126    contact_type: Option<String>,
127    telephone: Option<PhoneNumber>,
128}
129
130/// Vendor Payment Bank Detail
131///
132/// Represents the bank details used for vendor payments in `QuickBooks` Online.
133#[skip_serializing_none]
134#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
135#[serde(rename_all = "PascalCase", default)]
136pub struct VendorPaymentBankDetail {
137    bank_account_name: Option<String>,
138    bank_branch_identifier: Option<String>,
139    bank_account_number: Option<String>,
140    statement_text: Option<String>,
141}
142
143impl QBCreatable for Vendor {
144    fn can_create(&self) -> bool {
145        self.display_name.is_some()
146            || self.suffix.is_some()
147            || self.title.is_some()
148            || self.middle_name.is_some()
149            || self.family_name.is_some()
150            || self.given_name.is_some()
151    }
152}
153
154impl QBFullUpdatable for Vendor {
155    fn can_full_update(&self) -> bool {
156        self.has_read() && self.can_create()
157    }
158}