Skip to content

Fixed: Incorrect unit price calculation during PO receiving under non-US locales (OFBIZ-13449)#1396

Open
toaditi wants to merge 1 commit into
apache:trunkfrom
toaditi:ofbiz-13449-receiving-unitprice-locale
Open

Fixed: Incorrect unit price calculation during PO receiving under non-US locales (OFBIZ-13449)#1396
toaditi wants to merge 1 commit into
apache:trunkfrom
toaditi:ofbiz-13449-receiving-unitprice-locale

Conversation

@toaditi

@toaditi toaditi commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Jira: https://issues.apache.org/jira/browse/OFBIZ-13449

Problem

Receiving a purchase order under a locale whose decimal separator is a comma (e.g. pl_PL) corrupts the order item unit price: 7,41 is stored as 741.

Root cause

The receiving form submits the order-currency unit price as a locale-formatted string. OFBiz's generic String→BigDecimal conversion (ObjectType.simpleTypeOrObjectConvertNumberConverters.fromString) ignores the caller locale and falls back to Locale.getDefault() unless the testBigDecimal system property is set:

// framework/base/.../conversion/NumberConverters.java
locale = null != System.getProperty("testBigDecimal") ? locale : Locale.getDefault();

So simpleTypeOrObjectConvert("7,41","BigDecimal",...,pl_PL,...) returns 741 (comma read as grouping), even though raw NumberFormat.getNumberInstance(pl_PL).parse("7,41") returns 7.41. Declaring the service attribute as BigDecimal does not help, because the same converter runs — verified by integration test (it stored 741.000).

Fix

Parse the submitted order-currency unit price explicitly with the request locale (parameters.locale) in updateIssuanceShipmentAndPoOnReceiveInventory, bypassing the generic converter.

Verification

Added ReceivePoLocaleTest (registered in FacilityTest.xml) that drives the service in a real container under pl_PL with orderCurrencyUnitPrice="7,41" and asserts the stored unitPrice == 7.41:

  • Before this change: 741.000 (fails).
  • After: [JUNIT] Pass: true | # Tests: 1 | # Failed: 0.

checkstyleMain / codenarcMain / codenarcTest pass.

Note

The underlying NumberConverters.fromString behaviour (discarding the caller locale) looks like a broader framework issue and is probably worth a separate ticket; this PR fixes the receiving flow without changing that shared converter.

…-US locales (OFBIZ-13449)

When receiving a purchase order under a locale whose decimal separator is a comma
(e.g. pl_PL), the order item unit price was corrupted: 7,41 was stored as 741.

The receiving form submits the order-currency unit price as a locale-formatted string.
OFBiz's generic String->BigDecimal conversion (ObjectType / NumberConverters.fromString)
ignores the caller locale and falls back to Locale.getDefault(), so "7,41" is parsed with
comma-as-grouping and becomes 741. Declaring the service attribute as BigDecimal does not
help, because the same converter is used.

Parse the submitted order-currency unit price explicitly with the request locale
(parameters.locale) in updateIssuanceShipmentAndPoOnReceiveInventory, so the value is
interpreted correctly regardless of the server's default locale.

Add an integration test (ReceivePoLocaleTest) that drives the service under pl_PL and
asserts the stored unit price is 7.41; it fails before this change and passes after.
orderItem.unitPrice = new BigDecimal (parameters.orderCurrencyUnitPrice)
BigDecimal orderCurrencyUnitPrice = parseLocalizedAmount((String) parameters.orderCurrencyUnitPrice, (Locale) parameters.locale)
if (orderCurrencyUnitPrice != orderItem.unitPrice) {
orderItem.unitPrice = orderCurrencyUnitPrice
orderItem.store()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@toaditi
ObjectType.simpleTypeOrObjectConvert also handles this conversion.
price = (BigDecimal) ObjectType.simpleTypeOrObjectConvert(parameters.orderCurrencyUnitPrice, "BigDecimal", null, locale);

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants