Skip to main content

quickbooks_types/models/
term.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4use crate::{common::MetaData, QBCreatable, QBFullUpdatable, QBItem};
5
6#[skip_serializing_none]
7#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
8#[serde(rename_all = "PascalCase", default)]
9#[cfg_attr(
10    feature = "builder",
11    derive(Builder),
12    builder(default, build_fn(error = "QBTypeError"), setter(into, strip_option))
13)]
14/// Term
15///
16/// represents the terms under which a sale is made, typically expressed in the form of days due after the goods are received.
17///
18/// API reference:
19/// <https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/term>
20pub struct Term {
21    /// The unique ID of the entity
22    pub id: Option<String>,
23    /// The unique sync token of the entity, used for concurrency control
24    pub sync_token: Option<String>,
25    /// Name of the term
26    pub name: Option<String>,
27    /// Percentage discount offered if paid within "DiscountDays"
28    pub discount_percent: Option<u16>,
29    /// Number of days within which a payment must be made to avail the discount
30    ///
31    /// used only when "due_days" is set
32    pub discount_days: Option<u16>,
33    /// Indicates if the term is active
34    pub active: Option<bool>,
35    /// Type of the term
36    #[serde(rename = "type")]
37    pub term_type: Option<TermType>,
38    /// Metadata about the entity
39    pub meta_data: Option<MetaData>,
40    /// Day of the month when the payment is due
41    ///
42    /// required if "due_days" is not set
43    pub day_of_month_due: Option<u16>,
44    /// Day of the month when the discount is applicable
45    ///
46    /// required if "due_days" is not set
47    pub discount_day_of_month: Option<u16>,
48    /// Payment due next month if issued that many days before the DayOfMonthDue. Required if DueDays not present.
49    pub due_next_month_days: Option<u16>,
50    /// Number of days from delivery of goods or services until the payment is due. Required if DayOfMonthDue not present
51    pub due_days: Option<u16>,
52}
53
54#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
55#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
56pub enum TermType {
57    Standard,
58    DateDriven,
59}
60
61impl QBCreatable for Term {
62    fn can_create(&self) -> bool {
63        self.name.is_some() && (self.day_of_month_due.is_some() || self.due_days.is_some())
64    }
65}
66
67impl QBFullUpdatable for Term {
68    fn can_full_update(&self) -> bool {
69        self.has_read() && self.can_create()
70    }
71}