From d1c8c1bd9effe7d6439ee633728087de0bed4b81 Mon Sep 17 00:00:00 2001 From: Jason Barnabe Date: Sat, 12 Dec 2020 13:41:14 -0600 Subject: [PATCH] Fix BigDecimal Based on #24 --- lib/qbxml/types.rb | 2 +- test/unit/xml_to_hash_test.rb | 157 ++++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+), 1 deletion(-) diff --git a/lib/qbxml/types.rb b/lib/qbxml/types.rb index 2c62232..aa13339 100644 --- a/lib/qbxml/types.rb +++ b/lib/qbxml/types.rb @@ -11,7 +11,7 @@ module Qbxml::Types TIME_CAST = Proc.new {|d| d ? Time.parse(d).xmlschema : Time.now.xmlschema } INT_CAST = Proc.new {|d| d ? Integer(d.to_i) : 0 } STR_CAST = Proc.new {|d| d ? String(d) : ''} - BIGDECIMAL_CAST = Proc.new {|d| d ? BigDecimal.new(d) : 0.0} + BIGDECIMAL_CAST = Proc.new {|d| d ? BigDecimal(d) : 0.0} TYPE_MAP= { "AMTTYPE" => FLOAT_CAST, diff --git a/test/unit/xml_to_hash_test.rb b/test/unit/xml_to_hash_test.rb index 49c6e99..76c8d6e 100644 --- a/test/unit/xml_to_hash_test.rb +++ b/test/unit/xml_to_hash_test.rb @@ -121,4 +121,161 @@ def test_float_percentage assert_equal h, qbxml.from_qbxml(xml) end + def test_bigdecimal + injected_time = Time.now.strftime("%Y-%m-%dT%H:%M:%S%:z") + + qbxml = Qbxml.new + h = { + "qbxml" => { + "xml_attributes" => {}, + "qbxml_msgs_rs"=> { + "xml_attributes" => {}, + "sales_receipt_add_rs" => { + "xml_attributes" => { + "statusCode" => "0", + "statusSeverity" => "Info", + "statusMessage" => "Status OK" + }, + "sales_receipt_ret" => { + "xml_attributes" => {}, + "txn_id" => "1C0-1433857054", + "time_created" => injected_time, + "time_modified" => injected_time, + "edit_sequence" => "1433850554", + "txn_number" => 89, + "customer_ref" => { + "xml_attributes" => {}, + "list_id" => "80000013-1433852150", + "full_name" => "custfullname" + }, + "template_ref" => { + "xml_attributes" => {}, + "list_id" => "80000009-1433199758", + "full_name" => "Custom Sales Receipt" + }, + "txn_date" => "2019-06-09", + "ref_number" => "1040000529", + "is_pending" => false, + "payment_method_ref" => { + "xml_attributes" => {}, + "list_id" => "8000000A-1433718272", + "full_name" => "paymentmethod" + }, + "due_date" => "2019-06-09", + "ship_date" => "2019-06-09", + "subtotal" => 0.2, + "item_sales_tax_ref" => { + "xml_attributes" => {}, + "list_id" => "80000009-1433719484", + "full_name" => "Tax agency" + }, + "sales_tax_percentage" => 8.25, + "sales_tax_total" => 0.02, + "total_amount" => 0.22, + "is_to_be_printed" => true, + "is_to_be_emailed" => false, + "customer_sales_tax_code_ref" => { + "xml_attributes" => {}, + "list_id" => "80000002-1403304324", + "full_name" => "Non" + }, + "deposit_to_account_ref" => { + "xml_attributes" => {}, + "list_id" => "8000003D-1433719666", + "full_name" => "Undeposited Funds" + }, + "sales_receipt_line_ret" => { + "xml_attributes" => {}, + "txn_line_id" => "1C2-1433632154", + "item_ref" => { + "xml_attributes" => {}, + "list_id" => "8000001F-1433854453", + "full_name" => "ABCD0000" + }, + "desc" => "description", + "quantity" => 0.2, + "rate" => 1.0, + "amount" => 0.2, + "service_date" => "2019-06-09", + "sales_tax_code_ref"=> { + "xml_attributes" => {}, + "list_id" => "80000001-1403304324", + "full_name"=>"Tax" + } + } + } + } + } + } + } + + xml = <<-XML + + + + + 1C0-1433857054 + #{injected_time} + #{injected_time} + 1433850554 + 89 + + 80000013-1433852150 + custfullname + + + 80000009-1433199758 + Custom Sales Receipt + + 2019-06-09 + 1040000529 + false + + 8000000A-1433718272 + paymentmethod + + 2019-06-09 + 2019-06-09 + 0.20 + + 80000009-1433719484 + Tax agency + + 8.25 + 0.02 + 0.22 + true + false + + 80000002-1403304324 + Non + + + 8000003D-1433719666 + Undeposited Funds + + + 1C2-1433632154 + + 8000001F-1433854453 + ABCD0000 + + description + 0.2 + 1.00 + 0.20 + 2019-06-09 + + 80000001-1403304324 + Tax + + + + + + + XML + + assert_equal h, qbxml.from_qbxml(xml) + end end