8

I am creating the invoice using python-quickbooks. I am creating multiple line-entries in the using the following code:

        #------------------------------------------------------
        #   Line Details
        #------------------------------------------------------

        line_detail = SalesItemLineDetail()
        line_detail.UnitPrice = 100  # in dollars
        line_detail.Qty = 1  # quantity can be decimal
        line_detail.ServiceDate = "2020-03-18"
       
        item_ref = Ref()
        item_ref.value = "1"
        item_ref.name = "Services"
        
        line = SalesItemLine()
        line.Amount = 100  # in dollars
        line.Description = "Line Entry Description"
        line.SalesItemLineDetail = line_detail
        line.SalesItemLineDetail.ItemRef = item_ref

However, I would to enable tax for each of the line entries and set the overall tax as "Federal Tax" at 12%

Any idea how to do it?

enter image description here

Kiran
  • 8,034
  • 36
  • 110
  • 176

2 Answers2

3

Since your bounty states you are looking for an answer from a reputable source, I thought I'd give sources and the specific example you asked for.

Using default QuickBooks Rates

Applying the default Federal Tax is straigthforward. This issue on the python-quickbooks GitHub shows how:

line_detail.TaxRef = Ref()
line_detail.TaxRef.value = #TAX CODE HERE#

You will need to use the correct Tax Reference code for your country/region.

The only allowed values for the USA are "TAX" for standard sales tax or "NON" for no tax.

i.e.:

Sales tax for USA would be done like this:

line_detail.TaxRef = Ref()
line_detail.TaxRef.value = "TAX" 

If you want no tax for an item:

line_detail.TaxRef = Ref()
line_detail.TaxRef.value = "NON"  

Specifying a tax rate yourself

You can find more details about TaxCodes in Intuit's API Reference here.

You can find details about how the actual tax calculations are made at Manage sales tax for US locales.

The gist of it is that the ref tag is first checked, with the only valid values being "TAX" and "NON". The associated TaxService will use those codes to calculate the actual tax. You can create more codes that apply specific rates you specify yourself using TaxService.

To create your own TaxCode that is "Federal Tax" at a rate of 12%, you would do this:

from quickbooks.objects.taxservice import TaxService, TaxRateDetails

taxservice = TaxService()
taxservice.TaxCode = "Federal Tax"

tax_rate_detail = TaxRateDetails()
tax_rate_detail.TaxRateName = "Federal Tax"
tax_rate_detail.RateValue = 12
tax_rate_detail.TaxAgencyId = 1
tax_rate_detail.TaxApplicableOn = "Sales"   

taxservice.TaxRateDetails.append(tax_rate_detail)
created_taxservice = taxservice.save(qb=handle_to_your_quickbooks_client)
Salvatore
  • 10,815
  • 4
  • 31
  • 69
0

If I understand your Problem correctly I would say adding tax to SalesItem's can be done with the follwing code.

line_detail.TaxRef = Ref()
line_detail.TaxRef.value = "YOUR COUTRY TAX CODE"

This should also set the correct standard/overall tax from the supplied tax code.