ruckus / quickbooks-ruby

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

Adding line item to invoice fails to update taxable totals #591

Closed timmyd87 closed 1 year ago

timmyd87 commented 1 year ago

I can successfully update an invoice and add a line item for a credit card fee when they process in my app. However in Quickbooks the line appears excluding tax (which is perfect) but it doesn't update the invoice subtotal to apply the taxable amounts to. Unless i actually go into QBO, click on edit invoice and click on the line item does it trigger this.....Is there any way to force QBO to recalculate the item and invoice totals through the API?

`line = Quickbooks::Model::Line.new line.description = 'Credit Card Processing Fee' line.amount = ActionController::Base.helpers.number_to_currency( @fee, delimiter: '', unit: '') line.sales_item! do |detail| detail.unit_price = ActionController::Base.helpers.number_to_currency(@fee, delimiter: '', unit: '') detail.quantity = 1 detail.tax_code_ref = Quickbooks::Model::BaseReference.new(10) end

  intuit_account.perform_authenticated_request do |access_token|
    service = Quickbooks::Service::Invoice.new
    service.company_id = intuit_account.realm_id
    service.access_token = access_token
    invoice = service.fetch_by_id(@invoice.quickbooks_id)
    invoice.line_items << line
    service.update(invoice)
  rescue Quickbooks::Error => e
    Rails.logger.info("QuickbooksError.perform: #{e.message}")

  end`
ruckus commented 1 year ago

Is the Product in QBO marked as taxable? I think that's needed to trigger an automatic tax calculation.

If its not taxable then it sounds like it falls back to the human to trigger that on edit invoice.

timmyd87 commented 1 year ago

Thank you for your reply, yes the line item was taxable, tick.

needed to pass the invoice.txn_tax_detail to trigger the calculations - found it here in the docs for anyone that comes across it. - https://developer.intuit.com/app/developer/qbo/docs/workflows/manage-sales-tax-for-us-locales#working-with-tax-codes

Appreciate the point in the right direction