quickbooks_types/models/
sales_receipt.rs

1use chrono::NaiveDate;
2use serde::{Deserialize, Serialize};
3use serde_with::skip_serializing_none;
4
5use super::{
6    common::{
7        Addr, CreditCardPayment, CustomField, DeliveryInfo, Email, GlobalTaxCalculation, LinkedTxn,
8        MetaData, NtRef, PrintStatus, TxnTaxDetail,
9    },
10    LineField,
11};
12#[cfg(feature = "builder")]
13use crate::error::QBTypeError;
14use crate::{
15    QBCreatable, QBFullUpdatable, QBItem, QBPDFable, QBSendable, QBSparseUpdateable, QBVoidable,
16};
17
18#[skip_serializing_none]
19#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
20#[serde(rename_all = "PascalCase", default)]
21#[cfg_attr(
22    feature = "builder",
23    derive(Builder),
24    builder(default, build_fn(error = "QBTypeError"), setter(into, strip_option))
25)]
26
27/// `SalesReceipt`
28///
29/// Represents a finalized sale where payment is received at the time of purchase. Unlike an invoice, it does not create an accounts receivable balance.
30///
31/// Update semantics:
32/// - `QBCreatable::can_create()` returns true when `line` contains at least one valid line.
33/// - `QBFullUpdatable::can_full_update()` for `SalesReceipt` requires `has_read()` (ID + sync token) and `can_create()`.
34///
35/// API reference:
36/// <https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/salesreceipt>
37pub struct SalesReceipt {
38    /// The unique ID of the entity
39    pub id: Option<String>,
40    /// Line items for the transaction
41    pub line: Option<LineField>,
42    /// Reference to the customer for the transaction
43    pub customer_ref: Option<NtRef>,
44    /// The unique sync token of the entity, used for concurrency control
45    pub sync_token: Option<String>,
46    /// Reference to the currency for the transaction
47    pub currency_ref: Option<NtRef>,
48    /// Email address for billing
49    pub bill_email: Option<Email>,
50    /// Address from which the items are shipped
51    pub ship_from_addr: Option<Addr>,
52    /// Custom fields for the entity
53    pub custom_field: Option<Vec<CustomField>>,
54    /// Date when the items are shipped
55    pub ship_date: Option<NaiveDate>,
56    /// Tracking number for the shipment
57    pub tracking_num: Option<String>,
58    /// Reference to the class for the transaction
59    pub class_ref: Option<NtRef>,
60    /// Print status of the sales receipt
61    pub print_status: Option<PrintStatus>,
62    /// Reference number for the payment
63    pub payment_ref_num: Option<String>,
64    /// Source of the transaction
65    pub txn_source: Option<String>,
66    /// Linked transactions
67    pub linked_txn: Option<Vec<LinkedTxn>>,
68    /// Global tax calculation method
69    pub global_tax_calculation: Option<GlobalTaxCalculation>,
70    /// Indicates if tax is applied after discount
71    pub apply_tax_after_discount: Option<bool>,
72    /// Document number for the sales receipt
73    pub doc_number: Option<String>,
74    /// Private note for the transaction
75    pub private_note: Option<String>,
76    /// Reference to the account where the deposit is made
77    pub deposit_to_account_ref: Option<NtRef>,
78    /// Memo for the customer
79    pub customer_memo: Option<NtRef>,
80    /// Information about a credit card payment for the transaction
81    pub credit_card_payment: Option<CreditCardPayment>,
82    /// Tax details for the transaction
83    pub txn_tax_detail: Option<TxnTaxDetail>,
84    /// Reference to the payment method for the transaction
85    pub payment_method_ref: Option<NtRef>,
86    /// Exchange rate for the transaction
87    pub exchange_rate: Option<f64>,
88    /// Address to which the items are shipped
89    pub ship_addr: Option<Addr>,
90    /// Indicates if the transaction is a sparse object
91    #[serde(rename = "sparse")]
92    pub sparse: Option<bool>,
93    /// Reference to the department for the transaction
94    pub department_ref: Option<NtRef>,
95    /// Reference to the shipping method for the transaction
96    pub ship_method_ref: Option<NtRef>,
97    /// Address for billing
98    pub bill_addr: Option<Addr>,
99    /// Metadata about the transaction
100    #[serde(skip_serializing)]
101    pub meta_data: Option<MetaData>,
102    /// Home balance for the transaction
103    pub home_balance: Option<f64>,
104    /// Delivery information for the transaction
105    pub delivery_info: Option<DeliveryInfo>,
106    /// Reference to the recurring data for the transaction
107    pub recur_data_ref: Option<NtRef>,
108    /// Total amount of the transaction
109    pub total_amt: Option<f64>,
110    /// Balance for the transaction
111    pub balance: Option<f64>,
112    /// Indicates if the address is a free-form address
113    pub free_form_address: Option<bool>,
114    /// Date of the transaction in YYYY-MM-DD format
115    pub txn_date: Option<NaiveDate>,
116}
117
118impl QBCreatable for SalesReceipt {
119    fn can_create(&self) -> bool {
120        self.line.can_create()
121    }
122}
123
124impl QBVoidable for SalesReceipt {}
125impl QBFullUpdatable for SalesReceipt {
126    fn can_full_update(&self) -> bool {
127        self.can_create() && self.has_read()
128    }
129}
130
131impl QBSparseUpdateable for SalesReceipt {
132    fn can_sparse_update(&self) -> bool {
133        self.can_full_update()
134    }
135}
136
137impl QBSendable for SalesReceipt {}
138impl QBPDFable for SalesReceipt {}