Skip to content

BasketItem.serialize does not round its amounts, Basket.serialize does #18

Description

@sveneberth

Basket.serialize puts every basket-level amount through roundAmount; BasketItem.serialize puts none of the item amounts through it. Measured:

basket amountTotalGross: 0.3
item   amountGross     : 0.30000000000000004
item   amountDiscount  : 8.881784197001252e-16

roundAmount's own docstring names both hazards: the API truncates past four decimals, and json.dumps writes a near-zero residue in scientific notation, "not a number the API accepts".

This matters more since #13 documented that v3 reconciles totalValueGross == sum((amountPerUnitGross - amountDiscountPerUnitGross) * quantity) exact to the cent (API.600.410.062) — that guidance asks the caller to do exactly the arithmetic whose residue nothing scrubs. Spreading a 90.78 discount over 7 units gives 12.968571428571428 on the wire against a rounded total; the API truncates to 12.9685 and its own sum no longer matches.

Rounding was added deliberately at the basket level and looks simply forgotten at the item level. Suggested: route amountPerUnitGross, amountDiscountPerUnitGross, amountGross, amountVat, amountPerUnit, amountNet and amountDiscount through roundAmount the same way.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions