ej2 / python-quickbooks

A Python library for accessing the Quickbooks API.
MIT License
401 stars 193 forks source link

Linked Txns are not working #366

Closed mattkatt closed 2 months ago

mattkatt commented 2 months ago

Attempting to use this SDK to convert a PO to a bill with linked transactions is proving to be a near-impossible task - I have tried my very best to adhere to what is required but I am still getting a successful bill created but with no linked transactions.

Here is my current process for creating a bill:

purchase_order = PurchaseOrder.get(<id>, <client>)

bill = Bill()
bill.VendorRef = purchase_order.VendorRef
bill.APAccountRef = purchase_order.APAccountRef
bill.DocNumber = <bill_ref>
bill.TxnDate = <bill_date>
bill.PrivateNote = f'Created from PO: {purchase_order.DocNumber}'
bill.CustomField = purchase_order.CustomField
bill.Line = []

for po_line in purchase_order.Line:
    bill_line = copy.deepcopy(po_line)
    bill_line.Id = None
    bill_line.LineNum = 0

    bill_line.LinkedTxn = []
    bill_linked_txn = LinkedTxn()
    bill_linked_txn.TxnId = purchase_order.Id
    bill_linked_txn.TxnType = 'PurchaseOrder'
    bill_linked_txn.TxnLineId = po_line.LineNum
    bill_line.LinkedTxn.append(bill_linked_txn)
    bill.Line.append(bill_line)

bill.LinkedTxn = []
bill.LinkedTxn.append({
    'TxnId': purchase_order.Id,
    'TxnType': 'PurchaseOrder'
})

bill.save(qb=<client>)

The bill is being created fine, but there are no linked txns on either the bill itself to the PO or the line items. I am using minorversion=73

mattkatt commented 2 months ago

Nevermind - this was a QBO API error - including the APAccountRef was causing this to fail to create a link