qbxml icon indicating copy to clipboard operation
qbxml copied to clipboard

Cast to BigDecimal doesn't work with localized decimal strings

Open mhelmetag opened this issue 3 years ago • 0 comments

In some places in the world (in this case Quebec), commas are used as decimal delimiters instead of periods (e.g. "0,02943" instead of "0.02943").

Here's an anonymized QBWC response from one of our Canadian customers for a BillAddRq including these localized decimal values:

<?xml version="1.0" ?>
<QBXML>
  <QBXMLMsgsRs>
    <BillAddRs requestID="requestID" statusCode="0" statusSeverity="Info" statusMessage="Status OK">
      <BillRet>
        <TxnID>TxnID</TxnID>
        <TimeCreated>2021-04-12T08:35:25-05:00</TimeCreated>
        <TimeModified>2021-04-12T08:35:25-05:00</TimeModified>
        <EditSequence>1618230925</EditSequence>
        <TxnNumber>376</TxnNumber>
        <VendorRef>
          <ListID>ListID</ListID>
          <FullName>Foo</FullName>
        </VendorRef>
        <APAccountRef>
          <ListID>ListID</ListID>
          <FullName>Bar</FullName>
        </APAccountRef>
        <TxnDate>2021-03-31</TxnDate>
        <DueDate>2021-04-10</DueDate>
        <AmountDue>7038,20</AmountDue>
        <RefNumber>007122</RefNumber>
        <IsTaxIncluded>false</IsTaxIncluded>
        <IsPaid>false</IsPaid>
        <LinkedTxn>
          <TxnID>TxnID</TxnID>
          <TxnType>PurchaseOrder</TxnType>
          <TxnDate>2021-02-16</TxnDate>
          <RefNumber>RefNumber</RefNumber>
          <LinkType>QUANTYPE</LinkType>
          <Amount>0.00</Amount>
        </LinkedTxn>
        <ItemLineRet>
          <TxnLineID>TxnLineID</TxnLineID>
          <ItemRef>
            <ListID>ListID</ListID>
            <FullName>1:10</FullName>
          </ItemRef>
          <Desc>Baz</Desc>
          <Quantity>0,02943</Quantity>
          <Cost>208002,03874</Cost>
          <Amount>6121,50</Amount>
          <CustomerRef>
            <ListID>ListID</ListID>
            <FullName>Buzz</FullName>
          </CustomerRef>
          <SalesTaxCodeRef>
            <ListID>ListID</ListID>
            <FullName>Fizz</FullName>
          </SalesTaxCodeRef>
          <BillableStatus>Billable</BillableStatus>
        </ItemLineRet>
        <OpenAmount>7038,20</OpenAmount>
      </BillRet>
    </BillAddRs>
  </QBXMLMsgsRs>
</QBXML>

Using that as response, here's the result of parsing it with Qbxml:

>Qbxml.new(:qb).from_qbxml(response)
ArgumentError: invalid value for BigDecimal(): "0,02943"
from /Users/maxhelmetag/.rbenv/versions/2.6.3/lib/ruby/2.6.0/bigdecimal.rb:5:in `BigDecimal'

I'm not sure what the solution would be besides subbing out commas for periods but... I'm sure that could go awry in some other places. Are there any tips out there for dealing with customers using this localized number formatting? Or are there settings to force the QBWC to drop the localized number formatting?

Thanks!

mhelmetag avatar Apr 12 '21 21:04 mhelmetag