fix(core): the audit checks a close's split at the allocation's unit
audit::closes took its unit as minor_units().unwrap_or(2), while the members allocation splits at allocation_places() (minor_units().unwrap_or(MAX_LINE_SCALE)). For a currency code with no minor unit the audit therefore checked a split made at the finest a line carries against a cent: far looser than the split it checks, so real drift passed. Add Currency::allocation_unit(), the one helper that turns allocation_places() into an amount, and take the audit's unit from it, so the split and its check cannot drift apart (BS-partner-1 statement 4: the allocation is the split to the base currency's smallest unit). A JPY close is now checked at a whole yen. Test: a_jpy_close_is_checked_at_the_allocations_unit (BS-partner-1 statement 4, WB-ledger-16 invariant 8). Co-Authored-By: Muse Wonder 1.0
This commit is contained in:
1 parent
4da1c5b30f
commit
5b1596f977
4 files changed
+96
-2
No files matched your search
@@ -474,7 +474,12 @@ pub fn check_control(checks: &[crate::arap::ControlCheck]) -> Vec<Finding> {
|
||||
}
|
||||
|
||||
fn closes(ledger: &Ledger, through: NaiveDate) -> Vec<Finding> {
|
||||
let unit = Decimal::new(1, ledger.base_currency().minor_units().unwrap_or(2));
|
||||
// The unit the allocation itself splits to, from the one helper both
|
||||
// sides use (`Currency::allocation_unit`, on `allocation_places`):
|
||||
// for a currency with no minor unit the split is far finer than a
|
||||
// cent, and the audit must not check it at a cent (BS-partner-1
|
||||
// statement 4).
|
||||
let unit = ledger.base_currency().allocation_unit();
|
||||
let mut out = Vec::new();
|
||||
for p in ledger.list_periods() {
|
||||
if p.status != PeriodStatus::Closed || p.end > through {
|
||||
|
||||
@@ -69,6 +69,17 @@ impl Currency {
|
||||
self.minor_units().unwrap_or(crate::kernel::MAX_LINE_SCALE)
|
||||
}
|
||||
|
||||
/// One allocation unit as an amount: `1` at [`Self::allocation_places`]
|
||||
/// (a cent, a whole yen, a thousandth of a dinar, the finest a line
|
||||
/// carries for a code with no minor unit). This is the one place that
|
||||
/// turns the places into an amount, so a split and a check of that
|
||||
/// split take their unit from the same rule and cannot drift apart
|
||||
/// (BS-partner-1 statement 4: the allocation is the split of the
|
||||
/// amount to the base currency's smallest unit).
|
||||
pub fn allocation_unit(&self) -> Decimal {
|
||||
Decimal::new(1, self.allocation_places())
|
||||
}
|
||||
|
||||
/// The three-letter code, e.g. `"USD"`.
|
||||
pub fn code(&self) -> &str {
|
||||
std::str::from_utf8(&self.0).expect("currency codes are ASCII by construction")
|
||||
|
||||
Reference in new issue
Block a user