Skip to content

Commit 30cc12c

Browse files
authored
Fix BigDecimal (#29)
Based on #24
1 parent ea5e997 commit 30cc12c

File tree

2 files changed

+158
-1
lines changed

2 files changed

+158
-1
lines changed

lib/qbxml/types.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Qbxml::Types
1111
TIME_CAST = Proc.new {|d| d ? Time.parse(d).xmlschema : Time.now.xmlschema }
1212
INT_CAST = Proc.new {|d| d ? Integer(d.to_i) : 0 }
1313
STR_CAST = Proc.new {|d| d ? String(d) : ''}
14-
BIGDECIMAL_CAST = Proc.new {|d| d ? BigDecimal.new(d) : 0.0}
14+
BIGDECIMAL_CAST = Proc.new {|d| d ? BigDecimal(d) : 0.0}
1515

1616
TYPE_MAP= {
1717
"AMTTYPE" => FLOAT_CAST,

test/unit/xml_to_hash_test.rb

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,161 @@ def test_float_percentage
121121
assert_equal h, qbxml.from_qbxml(xml)
122122
end
123123

124+
def test_bigdecimal
125+
injected_time = Time.now.strftime("%Y-%m-%dT%H:%M:%S%:z")
126+
127+
qbxml = Qbxml.new
128+
h = {
129+
"qbxml" => {
130+
"xml_attributes" => {},
131+
"qbxml_msgs_rs"=> {
132+
"xml_attributes" => {},
133+
"sales_receipt_add_rs" => {
134+
"xml_attributes" => {
135+
"statusCode" => "0",
136+
"statusSeverity" => "Info",
137+
"statusMessage" => "Status OK"
138+
},
139+
"sales_receipt_ret" => {
140+
"xml_attributes" => {},
141+
"txn_id" => "1C0-1433857054",
142+
"time_created" => injected_time,
143+
"time_modified" => injected_time,
144+
"edit_sequence" => "1433850554",
145+
"txn_number" => 89,
146+
"customer_ref" => {
147+
"xml_attributes" => {},
148+
"list_id" => "80000013-1433852150",
149+
"full_name" => "custfullname"
150+
},
151+
"template_ref" => {
152+
"xml_attributes" => {},
153+
"list_id" => "80000009-1433199758",
154+
"full_name" => "Custom Sales Receipt"
155+
},
156+
"txn_date" => "2019-06-09",
157+
"ref_number" => "1040000529",
158+
"is_pending" => false,
159+
"payment_method_ref" => {
160+
"xml_attributes" => {},
161+
"list_id" => "8000000A-1433718272",
162+
"full_name" => "paymentmethod"
163+
},
164+
"due_date" => "2019-06-09",
165+
"ship_date" => "2019-06-09",
166+
"subtotal" => 0.2,
167+
"item_sales_tax_ref" => {
168+
"xml_attributes" => {},
169+
"list_id" => "80000009-1433719484",
170+
"full_name" => "Tax agency"
171+
},
172+
"sales_tax_percentage" => 8.25,
173+
"sales_tax_total" => 0.02,
174+
"total_amount" => 0.22,
175+
"is_to_be_printed" => true,
176+
"is_to_be_emailed" => false,
177+
"customer_sales_tax_code_ref" => {
178+
"xml_attributes" => {},
179+
"list_id" => "80000002-1403304324",
180+
"full_name" => "Non"
181+
},
182+
"deposit_to_account_ref" => {
183+
"xml_attributes" => {},
184+
"list_id" => "8000003D-1433719666",
185+
"full_name" => "Undeposited Funds"
186+
},
187+
"sales_receipt_line_ret" => {
188+
"xml_attributes" => {},
189+
"txn_line_id" => "1C2-1433632154",
190+
"item_ref" => {
191+
"xml_attributes" => {},
192+
"list_id" => "8000001F-1433854453",
193+
"full_name" => "ABCD0000"
194+
},
195+
"desc" => "description",
196+
"quantity" => 0.2,
197+
"rate" => 1.0,
198+
"amount" => 0.2,
199+
"service_date" => "2019-06-09",
200+
"sales_tax_code_ref"=> {
201+
"xml_attributes" => {},
202+
"list_id" => "80000001-1403304324",
203+
"full_name"=>"Tax"
204+
}
205+
}
206+
}
207+
}
208+
}
209+
}
210+
}
211+
212+
xml = <<-XML
213+
<QBXML>
214+
<QBXMLMsgsRs>
215+
<SalesReceiptAddRs statusCode="0" statusSeverity="Info" statusMessage="Status OK">
216+
<SalesReceiptRet>
217+
<TxnID>1C0-1433857054</TxnID>
218+
<TimeCreated>#{injected_time}</TimeCreated>
219+
<TimeModified>#{injected_time}</TimeModified>
220+
<EditSequence>1433850554</EditSequence>
221+
<TxnNumber>89</TxnNumber>
222+
<CustomerRef>
223+
<ListID>80000013-1433852150</ListID>
224+
<FullName>custfullname</FullName>
225+
</CustomerRef>
226+
<TemplateRef>
227+
<ListID>80000009-1433199758</ListID>
228+
<FullName>Custom Sales Receipt</FullName>
229+
</TemplateRef>
230+
<TxnDate>2019-06-09</TxnDate>
231+
<RefNumber>1040000529</RefNumber>
232+
<IsPending>false</IsPending>
233+
<PaymentMethodRef>
234+
<ListID>8000000A-1433718272</ListID>
235+
<FullName>paymentmethod</FullName>
236+
</PaymentMethodRef>
237+
<DueDate>2019-06-09</DueDate>
238+
<ShipDate>2019-06-09</ShipDate>
239+
<Subtotal>0.20</Subtotal>
240+
<ItemSalesTaxRef>
241+
<ListID>80000009-1433719484</ListID>
242+
<FullName>Tax agency</FullName>
243+
</ItemSalesTaxRef>
244+
<SalesTaxPercentage>8.25</SalesTaxPercentage>
245+
<SalesTaxTotal>0.02</SalesTaxTotal>
246+
<TotalAmount>0.22</TotalAmount>
247+
<IsToBePrinted>true</IsToBePrinted>
248+
<IsToBeEmailed>false</IsToBeEmailed>
249+
<CustomerSalesTaxCodeRef>
250+
<ListID>80000002-1403304324</ListID>
251+
<FullName>Non</FullName>
252+
</CustomerSalesTaxCodeRef>
253+
<DepositToAccountRef>
254+
<ListID>8000003D-1433719666</ListID>
255+
<FullName>Undeposited Funds</FullName>
256+
</DepositToAccountRef>
257+
<SalesReceiptLineRet>
258+
<TxnLineID>1C2-1433632154</TxnLineID>
259+
<ItemRef>
260+
<ListID>8000001F-1433854453</ListID>
261+
<FullName>ABCD0000</FullName>
262+
</ItemRef>
263+
<Desc>description</Desc>
264+
<Quantity>0.2</Quantity>
265+
<Rate>1.00</Rate>
266+
<Amount>0.20</Amount>
267+
<ServiceDate>2019-06-09</ServiceDate>
268+
<SalesTaxCodeRef>
269+
<ListID>80000001-1403304324</ListID>
270+
<FullName>Tax</FullName>
271+
</SalesTaxCodeRef>
272+
</SalesReceiptLineRet>
273+
</SalesReceiptRet>
274+
</SalesReceiptAddRs>
275+
</QBXMLMsgsRs>
276+
</QBXML>
277+
XML
278+
279+
assert_equal h, qbxml.from_qbxml(xml)
280+
end
124281
end

0 commit comments

Comments
 (0)