Fix price edge cases in BOM table#1
Open
MayNiklas wants to merge 2 commits intowhinis:add-bom-pricefrom
Open
Conversation
When a part has a minimum order amount greater than the BOM quantity, calculateAvgPrice previously returned null (no price tier matched), causing the price to fall back to zero. Now the minimum order amount is used as a floor for the price lookup so a realistic price is shown.
Very small but non-zero prices would previously display as 0.00€ due to truncation. Prices are now rounded up (RoundingMode::UP) to 2 decimal places before display, so a part that costs e.g. 0.001€ shows as 0.01€. It also now uses BigDecimal::multipliedBy() to keep full precision before rounding.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses two edge cases discussed in Part-DB#1221:
When a BOM entry quantity is lower than a part's minimum order amount, calculateAvgPrice() returns null (no price tier matches), causing the price to fall back to zero. This fix uses the minimum order amount as a floor for the price lookup, so the price of the smallest orderable quantity is shown instead.
Prices were previously truncated to 2 decimal places, so parts costing e.g. 0.004€ would display as 0.00€ — implying they are free. Prices are now rounded up (RoundingMode::UP) before display.
This also fixes a bug in the ext_price column where the quantity multiplication was lost during the rounding refactor — it now uses BigDecimal::multipliedBy() to preserve full precision before rounding.
Feel free to merge this PR - this way my changes would be appended to Part-DB#1221 :)