discount profiles and discounts overall implemented and working
Some checks failed
CI / Check Style (push) Has been cancelled
CI / Run Clippy (push) Has been cancelled
CI / Run Tests (push) Has been cancelled

This commit is contained in:
Priec
2026-06-21 23:46:37 +02:00
parent c713627a2c
commit 1df8d66d5d
27 changed files with 1317 additions and 89 deletions

View File

@@ -16,7 +16,7 @@ use crate::{
models::products,
shared::{
guard,
money::{format_price, parse_price_to_cents},
money::{format_price, parse_percent, parse_price_to_cents},
},
};
@@ -29,12 +29,6 @@ struct DiscountForm {
percent: Option<String>,
}
/// Parse a percentage typed as "20", "20.5" or "20,5" into an `f64`.
fn parse_percent(value: &str) -> Option<f64> {
let parsed: f64 = value.trim().replace(',', ".").parse().ok()?;
parsed.is_finite().then_some(parsed)
}
/// Resolve a percentage off the regular price into a fixed sale price in cents.
/// Rounds the discount amount to the nearest cent.
fn percent_to_sale_cents(regular_cents: i64, percent: f64) -> i64 {