Skip to content

Commit

Permalink
Add rust_decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
bugproof committed Jun 25, 2022
1 parent ac7ed99 commit b24c9e6
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 47 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ chrono = { version = "0.4", features = ["serde"] }
reqwest = "0.11.11"
thiserror = "1.0"
tower = { version = "0.4", features = ["limit"] }
rust_decimal = "1.25"
rust_decimal_macros = "1.25"

[dev-dependencies]
tokio = { version = "1.8.1", features = ["rt-multi-thread", "macros"] }
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::common::RequestTrait;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use rust_decimal::Decimal;

#[derive(Serialize, Deserialize)]
pub struct Variant {
pub variant_id: String,
pub name: String,
pub price: String,
pub price: Decimal,
pub quantity: String,
pub sku: String,
pub ean: String,
Expand All @@ -15,10 +16,10 @@ pub struct Variant {
#[derive(Serialize, Deserialize)]
pub struct Product {
pub product_id: i64,
pub price_wholesale_netto: serde_json::Number,
pub price_netto: serde_json::Number,
pub price_brutto: serde_json::Number,
pub tax_rate: serde_json::Number,
pub price_wholesale_netto: Decimal,
pub price_netto: Decimal,
pub price_brutto: Decimal,
pub tax_rate: Decimal,
pub name: String,
pub quantity: i64,
pub category_id: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rust_decimal::Decimal;
use crate::common::RequestTrait;
use serde::{Deserialize, Serialize};

Expand All @@ -8,7 +9,7 @@ pub struct Product {
pub sku: String,
pub name: String,
pub quantity: i64,
pub price_brutto: serde_json::Number,
pub price_brutto: Decimal,
}

#[derive(Serialize, Deserialize)]
Expand All @@ -26,8 +27,8 @@ pub struct GetExternalStorageProductsList {
pub filter_ean: Option<String>,
pub filter_sku: Option<String>,
pub filter_name: Option<String>,
pub filter_price_from: Option<f64>,
pub filter_price_to: Option<f64>,
pub filter_price_from: Option<Decimal>,
pub filter_price_to: Option<Decimal>,
pub filter_quantity_from: Option<i64>,
pub filter_quantity_to: Option<i64>,
pub filter_available: Option<i64>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use rust_decimal::Decimal;
use crate::common::RequestTrait;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
pub struct Product {
pub product_id: String,
pub price: serde_json::Number,
pub price: Decimal,
pub variants: Vec<Variant>,
}

#[derive(Serialize, Deserialize)]
pub struct Variant {
pub variant_id: String,
pub price: serde_json::Number,
pub price: Decimal,
}

#[derive(Serialize, Deserialize)]
Expand Down
7 changes: 4 additions & 3 deletions src/requests/orders/add_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::common::RequestTrait;
use crate::serialization::inconsistent_bool;
use chrono::serde::ts_seconds;
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
Expand All @@ -21,8 +22,8 @@ pub struct Product {
pub ean: String,
pub location: String,
pub warehouse_id: i64,
pub price_brutto: serde_json::Number,
pub tax_rate: serde_json::Number,
pub price_brutto: Decimal,
pub tax_rate: Decimal,
pub quantity: i64,
pub weight: f64,
}
Expand All @@ -44,7 +45,7 @@ pub struct AddOrder {
pub payment_method_cod: String,
pub paid: String,
pub delivery_method: String,
pub delivery_price: String,
pub delivery_price: Decimal,
pub delivery_fullname: String,
pub delivery_company: String,
pub delivery_address: String,
Expand Down
5 changes: 3 additions & 2 deletions src/requests/orders/add_order_product.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rust_decimal::Decimal;
use crate::common::RequestTrait;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -39,9 +40,9 @@ pub struct AddOrderProduct {
/// The detailed product attributes, e.g. "Colour: blue" (Variant name)
pub attributes: String,
/// Single item gross price
pub price_brutto: serde_json::Number,
pub price_brutto: Decimal,
/// VAT rate
pub tax_rate: serde_json::Number,
pub tax_rate: Decimal,
/// Number of pieces
pub quantity: i64,
/// Single piece weight
Expand Down
11 changes: 6 additions & 5 deletions src/requests/orders/get_invoices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ use crate::common::RequestTrait;
use chrono::serde::ts_seconds;
use chrono::serde::ts_seconds_option;
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
pub struct InvoiceItem {
pub name: String,
pub sku: String,
pub ean: String,
pub price_brutto: serde_json::Number,
pub price_netto: serde_json::Number,
pub tax_rate: serde_json::Number,
pub price_brutto: Decimal,
pub price_netto: Decimal,
pub tax_rate: Decimal,
pub quantity: i64,
}

Expand All @@ -34,7 +35,7 @@ pub struct Invoice {
#[serde(with = "ts_seconds")]
pub date_pay_to: DateTime<Utc>,
pub currency: String,
pub total_price_brutto: serde_json::Number,
pub total_price_brutto: Decimal,
pub payment: String,
pub additional_info: String,
pub invoice_fullname: String,
Expand All @@ -53,7 +54,7 @@ pub struct Invoice {
pub correcting_data: Option<bool>,
pub external_invoice_number: String,
pub exchange_currency: Option<String>,
pub exchange_rate: Option<serde_json::Number>,
pub exchange_rate: Option<Decimal>,
pub exchange_date: String, // unknown date format
pub exchange_info: String,
pub external_id: i64,
Expand Down
5 changes: 3 additions & 2 deletions src/requests/orders/get_new_receipts.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::common::RequestTrait;
use chrono::serde::ts_seconds;
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
pub struct ReceiptOrderProduct {
pub name: String,
pub price_brutto: serde_json::Number,
pub tax_rate: serde_json::Number,
pub price_brutto: Decimal,
pub tax_rate: Decimal,
pub quantity: i64,
pub sku: String,
pub ean: String,
Expand Down
7 changes: 4 additions & 3 deletions src/requests/orders/get_order_payments_history.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use crate::common::RequestTrait;
use chrono::serde::ts_seconds;
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
pub struct Payment {
/// total amount paid before the given change
pub paid_before: serde_json::Number,
pub paid_before: Decimal,
/// total amount paid after the change
pub paid_after: serde_json::Number,
pub total_price: serde_json::Number,
pub paid_after: Decimal,
pub total_price: Decimal,
pub currency: String,
/// external payment identifier
pub external_payment_id: String,
Expand Down
7 changes: 4 additions & 3 deletions src/requests/orders/get_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::serialization::inconsistent_bool_option;
use chrono::serde::ts_seconds;
use chrono::serde::ts_seconds_option;
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -32,7 +33,7 @@ pub struct Order {
pub payment_method_cod: String,
pub payment_done: String,
pub delivery_method: String,
pub delivery_price: String,
pub delivery_price: Decimal,
pub delivery_package_module: String,
pub delivery_package_nr: String,
pub delivery_fullname: String,
Expand Down Expand Up @@ -76,8 +77,8 @@ pub struct Product {
pub location: String,
pub warehouse_id: i64,
pub auction_id: String,
pub price_brutto: serde_json::Number,
pub tax_rate: serde_json::Number,
pub price_brutto: Decimal,
pub tax_rate: Decimal,
pub quantity: i64,
pub weight: i64,
}
Expand Down
9 changes: 5 additions & 4 deletions src/requests/orders/get_receipt.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::common::RequestTrait;
use chrono::serde::ts_seconds;
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
pub struct ReceiptItem {
pub name: String,
pub price_brutto: serde_json::Number,
pub tax_rate: serde_json::Number,
pub price_brutto: Decimal,
pub tax_rate: Decimal,
pub quantity: i64,
pub sku: String,
pub ean: String,
Expand All @@ -27,10 +28,10 @@ pub struct GetReceiptResponse {
pub payment_method: String,
pub nip: String,
pub currency: String,
pub total_price_brutto: serde_json::Number,
pub total_price_brutto: Decimal,
pub external_receipt_number: String,
pub exchange_currency: String,
pub exchange_rate: serde_json::Number,
pub exchange_rate: Decimal,
pub exchange_date: String,
pub exchange_info: String,
pub items: Vec<ReceiptItem>,
Expand Down
3 changes: 2 additions & 1 deletion src/requests/orders/set_order_fields.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::HashMap;
use rust_decimal::Decimal;
use crate::common::RequestTrait;
use serde::de::IgnoredAny;
use serde::{Deserialize, Serialize};
Expand All @@ -17,7 +18,7 @@ pub struct SetOrderFields {
pub phone: Option<String>,
pub user_login: Option<String>,
pub delivery_method: Option<String>,
pub delivery_price: Option<serde_json::Number>,
pub delivery_price: Option<Decimal>,
pub delivery_fullname: Option<String>,
pub delivery_company: Option<String>,
pub delivery_address: Option<String>,
Expand Down
3 changes: 2 additions & 1 deletion src/requests/orders/set_order_payment.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::common::RequestTrait;
use chrono::serde::ts_seconds;
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde::de::IgnoredAny;
use serde::{Deserialize, Serialize};

Expand All @@ -13,7 +14,7 @@ pub struct SetOrderPayment {
/// The value changes the current payment in the order (not added to the previous value).
///
/// If the amount matches the order value, the order will be marked as paid.
pub payment_done: serde_json::Number,
pub payment_done: Decimal,
#[serde(with = "ts_seconds")]
pub payment_date: DateTime<Utc>,
pub payment_comment: String,
Expand Down
5 changes: 3 additions & 2 deletions src/requests/orders/set_order_product_fields.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rust_decimal::Decimal;
use crate::common::RequestTrait;
use serde::de::IgnoredAny;
use serde::{Deserialize, Serialize};
Expand All @@ -20,8 +21,8 @@ pub struct SetOrderProductFields {
pub location: String,
pub warehouse_id: i64,
pub attributes: String,
pub price_brutto: serde_json::Number,
pub tax_rate: serde_json::Number,
pub price_brutto: Decimal,
pub tax_rate: Decimal,
pub quantity: i64,
pub weight: f64,
}
Expand Down
5 changes: 3 additions & 2 deletions src/requests/product_catalog/add_inventory_product.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::common::RequestTrait;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use rust_decimal::Decimal;

#[derive(Serialize, Deserialize)]
pub struct AddInventoryProductResponse {
Expand All @@ -25,15 +26,15 @@ pub struct AddInventoryProduct {
pub is_bundle: bool,
pub ean: String,
pub sku: String,
pub tax_rate: serde_json::Number,
pub tax_rate: Decimal,
pub weight: f64,
pub height: f64,
pub width: f64,
pub length: f64,
pub star: i64,
pub manufacturer_id: i64,
pub category_id: i64,
pub prices: HashMap<i64, serde_json::Number>,
pub prices: HashMap<i64, Decimal>,
pub stock: HashMap<String, i64>,
pub locations: HashMap<String, String>,
pub text_fields: HashMap<String, String>,
Expand Down
3 changes: 2 additions & 1 deletion src/requests/product_catalog/get_inventory_product_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ use crate::common::RequestTrait;
use chrono::serde::ts_seconds;
use chrono::serde::ts_seconds_option;
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};

// TODO: verify this

#[derive(Serialize, Deserialize)]
pub enum StockOrPrice {
Stock(i64),
Price(serde_json::Number),
Price(Decimal),
}

#[derive(Serialize, Deserialize)]
Expand Down
5 changes: 3 additions & 2 deletions src/requests/product_catalog/get_inventory_products_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ use crate::common::RequestTrait;
use crate::requests::product_catalog::add_inventory_product::ProductLink;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use rust_decimal::Decimal;

#[derive(Serialize, Deserialize)]
pub struct DetailedProductData {
pub ean: String,
pub sku: String,
pub tax_rate: serde_json::Number,
pub tax_rate: Decimal,
pub weight: f64,
pub height: f64,
pub width: f64,
pub length: f64,
pub star: i64,
pub category_id: i64,
pub manufacturer_id: i64,
pub prices: HashMap<i64, serde_json::Number>,
pub prices: HashMap<i64, Decimal>,
pub stock: HashMap<String, i64>,
pub locations: HashMap<String, String>,
pub text_fields: HashMap<String, String>,
Expand Down
Loading

0 comments on commit b24c9e6

Please sign in to comment.