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