quickbooks_types/models/
bill.rs

1use chrono::NaiveDate;
2use serde::{Deserialize, Serialize};
3use serde_with::skip_serializing_none;
4
5use super::common::{LinkedTxn, MetaData, NtRef};
6#[cfg(feature = "builder")]
7use crate::error::QBTypeError;
8use crate::{LineField, QBCreatable, QBDeletable, QBFullUpdatable, QBItem};
9
10#[skip_serializing_none]
11#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
12#[serde(rename_all = "PascalCase", default)]
13#[cfg_attr(
14    feature = "builder",
15    derive(Builder),
16    builder(default, build_fn(error = "QBTypeError"), setter(into, strip_option))
17)]
18
19/// Bill
20///
21/// Represents an accounts payable bill received from a vendor.
22/// Records amounts owed to vendors; line items specify products/services and their costs.
23///
24/// Creation requirements:
25/// - `QBCreatable::can_create()` returns true when both `vendor_ref` and at least one valid `line` are present.
26///
27/// Update semantics:
28/// - `QBFullUpdatable::can_full_update()` returns true when `has_read()` (ID + sync token) is true and the creation requirements are satisfied (`vendor_ref` and `line`).
29///
30/// API reference:
31/// <https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/bill>
32pub struct Bill {
33    /// The unique ID of the entity
34    pub id: Option<String>,
35    /// The unique sync token of the entity, used for concurrency control
36    pub sync_token: Option<String>,
37    /// Metadata about the entity
38    #[serde(skip_serializing)]
39    pub meta_data: Option<MetaData>,
40    /// Domain of the transaction. `QBO` for `QuickBooks` Online.
41    pub domain: Option<String>,
42    /// Reference to the Accounts Payable account for the transaction
43    #[serde(rename = "APAccountRef")]
44    pub ap_account_ref: Option<NtRef>,
45    /// Reference to the vendor for the transaction
46    pub vendor_ref: Option<NtRef>,
47    /// Date of the transaction in YYYY-MM-DD format
48    pub txn_date: Option<NaiveDate>,
49    /// Total amount of the transaction
50    pub total_amt: Option<f64>,
51    /// Reference to the currency for the transaction
52    pub currency_ref: Option<NtRef>,
53    /// List of transactions linked to this bill
54    pub linked_txn: Option<Vec<LinkedTxn>>,
55    /// Reference to the sales terms for the transaction
56    pub sales_term_ref: Option<NtRef>,
57    /// Due date of the bill in YYYY-MM-DD format
58    pub due_date: Option<NaiveDate>,
59    /// Indicates if the transaction is a sparse object
60    pub sparse: Option<bool>,
61    /// Line items for the transaction
62    pub line: Option<LineField>,
63    /// Remaining balance on the bill
64    pub balance: Option<f64>,
65    /// Document number for the bill
66    pub doc_number: Option<String>,
67    /// Private note for the transaction
68    pub private_note: Option<String>,
69    /// Exchange rate for the transaction
70    pub exchange_rate: Option<f64>,
71    /// Reference to the department for the transaction
72    pub department_ref: Option<NtRef>,
73    /// Home currency balance for the transaction
74    pub home_balance: Option<f64>,
75    /// Reference to recurring schedule information
76    pub recur_data_ref: Option<NtRef>,
77}
78
79impl QBCreatable for Bill {
80    fn can_create(&self) -> bool {
81        self.vendor_ref.is_some() && self.line.is_some()
82    }
83}
84
85impl QBDeletable for Bill {}
86impl QBFullUpdatable for Bill {
87    fn can_full_update(&self) -> bool {
88        self.has_read() && self.vendor_ref.is_some() && self.line.is_some()
89    }
90}