ruckus / quickbooks-ruby

Quickbooks Online REST API V3 - Ruby
MIT License
374 stars 302 forks source link

TaxInclusiveAmt has inconsistent serialization/deserialization types #588

Closed brianhenryhf closed 1 year ago

brianhenryhf commented 1 year ago

Models that include tax_inclusive_amount use #to_f when serializing to XML, landing as floats, but specify no :as type, and default to Strings when deserialized.

Example XML string from serialization of a SalesReceipt (note <TaxInclusiveAmt>0.0</TaxInclusiveAmt>):

 "<SalesReceipt xmlns=\"http://schema.intuit.com/finance/v3\" sparse=\"false\">\n<Id>11</Id>\n<SyncToken>0</SyncToken>\n<MetaData>\n<CreateTime>2022-05-29T14:59:48-0700</CreateTime>\n<LastUpdatedTime>2022-05-29T14:59:48-0700</LastUpdatedTime>\n</MetaData>\n<DocNumber>1003</DocNumber>\n<TxnDate>2022-05-27 00:00:00 +0000</TxnDate>\n<Line>\n<Id>1</Id>\n<LineNum>1</LineNum>\n<Description>Custom Design</Description>\n<Amount>337.5</Amount>\n<DetailType>SalesItemLineDetail</DetailType>\n<SalesItemLineDetail>\n<ItemRef name=\"Design\">4</ItemRef>\n<UnitPrice>75.0</UnitPrice>\n<Qty>4.5</Qty>\n<TaxCodeRef>NON</TaxCodeRef>\n<TaxInclusiveAmt>0.0</TaxInclusiveAmt>\n</SalesItemLineDetail>\n</Line>\n<Line>\n<Amount>337.5</Amount>\n<DetailType>SubTotalLineDetail</DetailType>\n<SubTotalLineDetail>\n<UnitPrice>0.0</UnitPrice>\n<Qty>0.0</Qty>\n</SubTotalLineDetail>\n</Line>\n<CustomerRef name=\"Dylan Sollfrank\">6</CustomerRef>\n<BillAddr>\n<Id>49</Id>\n<Line1>Dylan Sollfrank</Line1>\n<Lat>INVALID</Lat>\n<Long>INVALID</Long>\n</BillAddr>\n<PaymentMethodRef name=\"Check\">2</PaymentMethodRef>\n<PaymentRefNum>10264</PaymentRefNum>\n<DepositToAccountRef name=\"Checking\">35</DepositToAccountRef>\n<CustomerMemo>Thank you for your business and have a great day!</CustomerMemo>\n<TxnTaxDetail>\n<TotalTax>0.0</TotalTax>\n</TxnTaxDetail>\n<CustomField>\n<DefinitionId>1</DefinitionId>\n<Name>Crew #</Name>\n<Type>StringType</Type>\n</CustomField>\n<CustomField>\n<DefinitionId>2</DefinitionId>\n<Type>StringType</Type>\n</CustomField>\n<CurrencyRef name=\"United States Dollar\">USD</CurrencyRef>\n<ApplyTaxAfterDiscount>false</ApplyTaxAfterDiscount>\n<PrintStatus>NotSet</PrintStatus>\n<Balance>0.0</Balance>\n<EmailStatus>NotSet</EmailStatus>\n<TotalAmt>337.5</TotalAmt>\n</SalesReceipt>"

The resultant object when Quickbooks::Model::SalesReceipt.from_xml is used to deserialize (note "tax_inclusive_amount"=>"0.0", and compare with, for example, "unit_price"=>0.75e2 at same level)

 #<Quickbooks::Model::SalesReceipt global_tax_calculation: nil, id: 11, sync_token: 0, meta_data: {"create_time"=>2022-05-29 14:59:48 -0700, "last_updated_time"=>2022-05-29 14:59:48 -0700}, auto_doc_number: nil, doc_number: 1003, txn_date: 2022-05-27 00:00:00 +0000, line_items: [#<Quickbooks::Model::Line id: 1, line_num: 1, description: Custom Design, amount: 337.5, detail_type: SalesItemLineDetail, linked_transactions: [], line_extras: nil, sales_item_line_detail: {"item_ref"=>{"name"=>"Design", "value"=>"4", "type"=>nil}, "class_ref"=>nil, "unit_price"=>0.75e2, "rate_percent"=>nil, "price_level_ref"=>nil, "quantity"=>0.45e1, "tax_code_ref"=>{"name"=>nil, "value"=>"NON", "type"=>nil}, "service_date"=>nil, "tax_inclusive_amount"=>"0.0"}, sub_total_line_detail: nil, payment_line_detail: nil, discount_line_detail: nil, journal_entry_line_detail: nil, group_line_detail: nil>, #<Quickbooks::Model::Line id: nil, line_num: nil, description: nil, amount: 337.5, detail_type: SubTotalLineDetail, linked_transactions: [], line_extras: nil, sales_item_line_detail: nil, sub_total_line_detail: {"item_ref"=>nil, "class_ref"=>nil, "unit_price"=>0.0, "quantity"=>0.0, "tax_code_ref"=>nil}, payment_line_detail: nil, discount_line_detail: nil, journal_entry_line_detail: nil, group_line_detail: nil>], customer_ref: {"name"=>"Dylan Sollfrank", "value"=>"6", "type"=>nil}, department_ref: nil, bill_email: nil, bill_address: {"id"=>"49", "line1"=>"Dylan Sollfrank", "line2"=>nil, "line3"=>nil, "line4"=>nil, "line5"=>nil, "city"=>nil, "country"=>nil, "country_sub_division_code"=>nil, "postal_code"=>nil, "note"=>nil, "lat"=>"INVALID", "lon"=>"INVALID"}, delivery_info: nil, ship_address: nil, po_number: nil, ship_method_ref: nil, ship_date: nil, tracking_num: nil, payment_method_ref: {"name"=>"Check", "value"=>"2", "type"=>nil}, payment_ref_number: 10264, deposit_to_account_ref: {"name"=>"Checking", "value"=>"35", "type"=>nil}, customer_memo: Thank you for your business and have a great day!, private_note: nil, txn_tax_detail: {"txn_tax_code_ref"=>nil, "total_tax"=>0.0, "total_tax_specified"=>nil, "lines"=>[]}, custom_fields: [#<Quickbooks::Model::CustomField id: 1, name: Crew #, type: StringType, string_value: nil, boolean_value: nil, date_value: nil, number_value: nil>, #<Quickbooks::Model::CustomField id: 2, name: nil, type: StringType, string_value: nil, boolean_value: nil, date_value: nil, number_value: nil>], currency_ref: {"name"=>"United States Dollar", "value"=>"USD", "type"=>nil}, class_ref: nil, apply_tax_after_discount?: false, print_status: NotSet, balance: 0.0, linked_transactions: [], email_status: NotSet, exchange_rate: nil, total: 337.5, home_total: nil>

Looks like the same behavior will apply for:

Lines like https://github.com/ruckus/quickbooks-ruby/blob/1d5cee0600dfa6a357e8b8a374ba76895ef18e84/lib/quickbooks/model/sales_item_line_detail.rb#L12 should should perhaps be modified to specify :as => BigDecimal like https://github.com/ruckus/quickbooks-ruby/blob/1d5cee0600dfa6a357e8b8a374ba76895ef18e84/lib/quickbooks/model/sales_item_line_detail.rb#L6 ?