def test_create(self):
        bill_payment = BillPayment()

        bill_payment.PayType = "Check"
        bill_payment.TotalAmt = 200
        bill_payment.PrivateNote = "Private Note"

        vendor = Vendor.all(max_results=1)[0]
        bill_payment.VendorRef = vendor.to_ref()

        bill_payment.CheckPayment = CheckPayment()
        account = Account.where("AccountSubType = 'Checking'")[0]
        bill_payment.CheckPayment.BankAccountRef = account.to_ref()

        ap_account = Account.where("AccountSubType = 'AccountsPayable'")[0]
        bill_payment.APAccountRef = ap_account.to_ref()

        bill = Bill.all(max_results=1)[0]

        line = BillPaymentLine()
        line.LinkedTxn.append(bill.to_linked_txn())
        line.Amount = 200

        bill_payment.Line.append(line)
        bill_payment.save()

        query_bill_payment = BillPayment.get(bill_payment.Id)

        self.assertEquals(query_bill_payment.PayType, "Check")
        self.assertEquals(query_bill_payment.TotalAmt, 200.0)
        self.assertEquals(query_bill_payment.PrivateNote,"Private Note")

        self.assertEquals(len(query_bill_payment.Line), 1)
        self.assertEquals(query_bill_payment.Line[0].Amount, 200.0)
    def test_create(self):
        bill_payment = BillPayment()

        bill_payment.PayType = "Check"
        bill_payment.TotalAmt = 200
        bill_payment.PrivateNote = "Private Note"

        vendor = Vendor.all(max_results=1, qb=self.qb_client)[0]
        bill_payment.VendorRef = vendor.to_ref()

        bill_payment.CheckPayment = CheckPayment()
        account = Account.where("AccountSubType = 'Checking'", qb=self.qb_client)[0]
        bill_payment.CheckPayment.BankAccountRef = account.to_ref()

        ap_account = Account.where("AccountSubType = 'AccountsPayable'", qb=self.qb_client)[0]
        bill_payment.APAccountRef = ap_account.to_ref()

        bill = Bill.all(max_results=1, qb=self.qb_client)[0]

        line = BillPaymentLine()
        line.LinkedTxn.append(bill.to_linked_txn())
        line.Amount = 200

        bill_payment.Line.append(line)
        bill_payment.save(qb=self.qb_client)

        query_bill_payment = BillPayment.get(bill_payment.Id, qb=self.qb_client)

        self.assertEquals(query_bill_payment.PayType, "Check")
        self.assertEquals(query_bill_payment.TotalAmt, 200.0)
        self.assertEquals(query_bill_payment.PrivateNote, "Private Note")

        self.assertEquals(len(query_bill_payment.Line), 1)
        self.assertEquals(query_bill_payment.Line[0].Amount, 200.0)
    def test_update(self):
        account = Account.filter(Name=self.name, qb=self.qb_client)[0]

        account.Name = "Updated Name {0}".format(self.account_number)
        account.save(qb=self.qb_client)

        query_account = Account.get(account.Id, qb=self.qb_client)
        self.assertEqual(query_account.Name, "Updated Name {0}".format(self.account_number))
    def setUp(self):
        self.account_number = datetime.now().strftime('%d%H%M')
        self.name = "Test Item {0}".format(self.account_number)

        self.income_account = Account.where(
            "AccountType = 'Income' and AccountSubType = 'SalesOfProductIncome'", max_results=1)[0]

        self.expense_account = Account.where("AccountSubType = 'SuppliesMaterialsCogs'", max_results=1)[0]
        self.asset_account = Account.where("AccountSubType = 'Inventory'", max_results=1)[0]
Beispiel #5
0
    def test_update(self):
        account = Account.filter(Name=self.name)[0]

        account.Name = "Updated Name {0}".format(self.account_number)
        account.save()

        query_account = Account.get(account.Id)

        self.assertEquals(query_account.Name, "Updated Name {0}".format(self.account_number))
    def test_update(self):
        account = Account.filter(Name=self.name, qb=self.qb_client)[0]

        account.Name = "Updated Name {0}".format(self.account_number)
        account.save(qb=self.qb_client)

        query_account = Account.get(account.Id, qb=self.qb_client)

        self.assertEquals(query_account.Name, "Updated Name {0}".format(self.account_number))
    def test_to_ref(self):
        account = Account()
        account.FullyQualifiedName = "test"
        account.Id = 12

        ref = account.to_ref()

        self.assertEquals(ref.name, "test")
        self.assertEquals(ref.type, "Account")
        self.assertEquals(ref.value, 12)
    def test_to_ref(self):
        account = Account()
        account.FullyQualifiedName = "test"
        account.Id = 12

        ref = account.to_ref()

        self.assertEquals(ref.name, "test")
        self.assertEquals(ref.type, "Account")
        self.assertEquals(ref.value, 12)
    def setUp(self):
        super(ItemTest, self).setUp()

        self.account_number = datetime.now().strftime('%d%H%M')
        self.name = "Test Item {0}".format(self.account_number)

        self.income_account = Account.where(
            "AccountType = 'Income' and AccountSubType = 'SalesOfProductIncome'", max_results=1, qb=self.qb_client)[0]

        self.expense_account = Account.where(
            "AccountSubType = 'SuppliesMaterialsCogs'", max_results=1, qb=self.qb_client)[0]
        self.asset_account = Account.where("AccountSubType = 'Inventory'", max_results=1, qb=self.qb_client)[0]
Beispiel #10
0
    def test_create(self):
        accounts = Account.where(
            "Classification = 'Asset' AND FullyQualifiedName != 'Accounts Receivable (A/R)'",
            max_results=2,
            qb=self.qb_client)

        from_account = accounts[0]
        to_account = accounts[1]

        transfer = Transfer()
        transfer.Amount = 100
        transfer.FromAccountRef = from_account.to_ref()
        transfer.ToAccountRef = to_account.to_ref()

        transfer.save(qb=self.qb_client)

        query_transfer = Transfer.get(transfer.Id, qb=self.qb_client)

        self.assertEquals(query_transfer.Id, transfer.Id)
        self.assertEquals(query_transfer.Amount, 100)
        self.assertEquals(query_transfer.FromAccountRef.value, from_account.Id)
        self.assertEquals(query_transfer.ToAccountRef.value, to_account.Id)

        # reset transfer (so the from_account doesn't run out of cash)
        transfer = Transfer()
        transfer.Amount = 100
        transfer.FromAccountRef = to_account.to_ref()
        transfer.ToAccountRef = from_account.to_ref()

        transfer.save(qb=self.qb_client)
Beispiel #11
0
    def test_create(self):
        accounts = Account.where(
            "Classification = 'Asset' AND FullyQualifiedName != 'Accounts Receivable (A/R)'",
            max_results=2, qb=self.qb_client)

        from_account = accounts[0]
        to_account = accounts[1]

        transfer = Transfer()
        transfer.Amount = 100
        transfer.FromAccountRef = from_account.to_ref()
        transfer.ToAccountRef = to_account.to_ref()

        transfer.save(qb=self.qb_client)

        query_transfer = Transfer.get(transfer.Id, qb=self.qb_client)

        self.assertEquals(query_transfer.Id, transfer.Id)
        self.assertEquals(query_transfer.Amount, 100)
        self.assertEquals(query_transfer.FromAccountRef.value, from_account.Id)
        self.assertEquals(query_transfer.ToAccountRef.value, to_account.Id)

        # reset transfer (so the from_account doesn't run out of cash)
        transfer = Transfer()
        transfer.Amount = 100
        transfer.FromAccountRef = to_account.to_ref()
        transfer.ToAccountRef = from_account.to_ref()

        transfer.save(qb=self.qb_client)
    def test_create(self):
        deposit = Deposit()
        account = Account.filter(AccountType="Bank",
                                 max_results=2,
                                 qb=self.qb_client)

        account_ref = account[0].to_ref()
        deposit_to_account_ref = account[1].to_ref()

        deposit_line_detail = DepositLineDetail()
        deposit_line_detail.AccountRef = account_ref

        line = DepositLine()
        line.Amount = 20.00
        line.DetailType = "DepositLineDetail"
        line.DepositLineDetail = deposit_line_detail

        deposit.DepositToAccountRef = deposit_to_account_ref
        deposit.Line.append(line)

        deposit.save(qb=self.qb_client)

        query_deposit = Deposit.get(deposit.Id, qb=self.qb_client)

        self.assertEqual(deposit.Id, query_deposit.Id)
Beispiel #13
0
def account(request):
    auth_client = AuthClient(
        settings.CLIENT_ID,
        settings.CLIENT_SECRET,
        settings.REDIRECT_URI,
        settings.ENVIRONMENT,
        access_token=request.session.get('access_token', None),
        refresh_token=request.session.get('refresh_token', None),
        realm_id=request.session.get('realm_id', None),
    )
    client = QuickBooks(
        auth_client=auth_client,
        refresh_token=request.session.get('refresh_token', None),
        company_id=4620816365030839390,
    )

    from quickbooks.objects.account import Account
    accounts = Account.all(qb=client)
    print(accounts)
    if auth_client.access_token is not None:
        access_token = auth_client.access_token

    if auth_client.realm_id is None:
        raise ValueError('Realm id not specified.')
    response = get_account_info(auth_client.access_token, auth_client.realm_id)
    if not response.ok:
        return HttpResponse(' '.join([response.content, str(response.status_code)]))
    else:
        response = response.json()["QueryResponse"]
        return JsonResponse(response)
Beispiel #14
0
def purchase(vendor, account, amount, client, description=None):
    purchase_acct = Account.filter(AccountType='Accounts Payable',
                                   AccountSubType='Accounts Payable',
                                   qb=client)
    if len(purchase_acct) == 0:
        purchase_acct = create_purchase_account(client)
    else:
        purchase_acct = purchase_acct[0]

    purchase = Purchase().from_json({
        "PaymentType":
        "Check",
        "AccountRef": {
            "value": account.Id
        },
        "EntityRef": {
            "type": "Vendor",
            "value": vendor.Id
        },
        "PrivateNote":
        description,
        "Line": [{
            "DetailType": "AccountBasedExpenseLineDetail",
            "Amount": amount,
            "AccountBasedExpenseLineDetail": {
                "AccountRef": {
                    "value": purchase_acct.Id
                }
            }
        }]
    })
    return purchase.save(qb=client)
Beispiel #15
0
def lookup_deposit_account(account_name):
    try:
        default_deposit_account_result = Account.where("Active = True AND Name = '" + DEFAULT_DEPOSIT_ACCOUNT + "'", qb=qb_client)
        if default_deposit_account_result is not None:
            return default_deposit_account_result[0].Id
    except Exception as e:
        logging.error("Error assigning default account info [{}], Error:{}".format(DEFAULT_DEPOSIT_ACCOUNT, e.message))
Beispiel #16
0
def qbo_create_item(soi):
    client = create_qbc()
    item = Item()

    print(soi.title)
    print(soi.price)

    item.Name = soi.title
    item.UnitPrice = soi.price
    item.Type = "Service"
    item.Sku = soi.sku

    account = Account.filter(Active=True, Name="Sales", qb=client)
    account_ref = Account.get(account[0].Id, qb=client).to_ref()

    item.IncomeAccountRef = account_ref
    item.save(qb=client)
    return item.Id
Beispiel #17
0
    def setUp(self):
        self.qb_client = QuickBooks(
            sandbox=True,
            consumer_key=os.environ.get('CONSUMER_KEY'),
            consumer_secret=os.environ.get('CONSUMER_SECRET'),
            access_token=os.environ.get('ACCESS_TOKEN'),
            access_token_secret=os.environ.get('ACCESS_TOKEN_SECRET'),
            company_id=os.environ.get('COMPANY_ID')
        )

        self.account_number = datetime.now().strftime('%d%H%M')
        self.name = "Test Item {0}".format(self.account_number)

        self.income_account = Account.where(
            "AccountType = 'Income' and AccountSubType = 'SalesOfProductIncome'", max_results=1, qb=self.qb_client)[0]

        self.expense_account = Account.where(
            "AccountSubType = 'SuppliesMaterialsCogs'", max_results=1, qb=self.qb_client)[0]
        self.asset_account = Account.where("AccountSubType = 'Inventory'", max_results=1, qb=self.qb_client)[0]
Beispiel #18
0
def do_payment(event, context):
    data = json.loads(event['Records'][0]['body'])
    amount = data['amount']
    user = data['user']
    company = data['company']
    client = get_qbo_client(user, company)
    account = Account.filter(Name='Left Coast Financial', qb=client)[0]
    customer = create_customer(user, company, data['from'])
    payment(customer, account, amount, client, data['description'])
    return {'statusCode': 200}
    def test_create(self):
        account = Account()
        account.AcctNum = self.account_number
        account.Name = self.name
        account.AccountSubType = "CashOnHand"
        account.save(qb=self.qb_client)

        self.id = account.Id
        query_account = Account.get(account.Id, qb=self.qb_client)

        self.assertEqual(account.Id, query_account.Id)
        self.assertEqual(query_account.Name, self.name)
        self.assertEqual(query_account.AcctNum, self.account_number)
Beispiel #20
0
def do_purchase(event, context):
    data = json.loads(event['Records'][0]['body'])
    #bill = create_bill(vendor[0], account[0], data['amount'], client)
    amount = float(data['amount'])
    user = data['user']
    client = get_qbo_client(user, data['company'])
    account = Account.filter(Name='Left Coast Financial', qb=client)[0]
    vendor = create_vendor(user, data['company'], data['to'])
    #pay_bill(bill, vendor[0], account[0], amount, client)
    purchase(vendor, account, amount, client, data['description'])
    return {'statusCode': 200}
Beispiel #21
0
def create_equity_account(name, client):
    logger.info("Creating equity account")
    account = Account.filter(Active=True,
                             AccountType="Equity",
                             AccountSubType="OpeningBalanceEquity",
                             qb=client)
    if len(account) == 0:
        account = Account()
        account.Name = name
        account.AccountType = "Equity"
        account.AccountSubType = "OpeningBalanceEquity"
        try:
            account.save(qb=client)
        except QuickbooksException:
            account = Account.filter(AccountType="Equity",
                                     AccountSubType="OpeningBalanceEquity",
                                     qb=client)
            return account[0]
        return account.save(qb=client)
    else:
        return account[0]
Beispiel #22
0
def create_purchase_account(client):
    logger.info("Creating purchase account")
    account = Account()
    account.Name = "LCFS Accounts Payable"
    account.AccountType = "Accounts Payable"
    account.AccountSubType = "Accounts Payable"
    return account.save(qb=client)
Beispiel #23
0
def create_lcfs_account(name, client):
    logger.info("Setting up LCFS account...")
    account = Account()
    account.Name = name
    account.AccountType = "Bank"
    account.AccountSubType = "Checking"
    return account.save(qb=client)
    def test_create(self):
        customer = Customer.all(max_results=1, qb=self.qb_client)[0]
        taxcode = TaxCode.all(max_results=1, qb=self.qb_client)[0]
        item = Item.filter(Type='Inventory', max_results=1,
                           qb=self.qb_client)[0]
        vendor = Vendor.all(max_results=1, qb=self.qb_client)[0]
        account = Account.all(max_results=1, qb=self.qb_client)[0]

        purchaseorder = PurchaseOrder()

        detail_line = ItemBasedExpenseLine()
        detail_line.Amount = 100
        detail_line.ItemBasedExpenseLineDetail = ItemBasedExpenseLineDetail()
        detail_line.ItemBasedExpenseLineDetail.BillableStatus = "NotBillable"
        detail_line.ItemBasedExpenseLineDetail.UnitPrice = 100
        detail_line.ItemBasedExpenseLineDetail.Qty = 1
        detail_line.ItemBasedExpenseLineDetail.CustomerRef = customer.to_ref()
        detail_line.ItemBasedExpenseLineDetail.TaxCodeRef = taxcode.to_ref()
        detail_line.ItemBasedExpenseLineDetail.ItemRef = item.to_ref()

        purchaseorder.Line.append(detail_line)
        purchaseorder.VendorRef = vendor.to_ref()
        purchaseorder.APAccountRef = account.to_ref()
        purchaseorder.TotalAmt = 100

        #print purchaseorder.to_json()
        purchaseorder.save(qb=self.qb_client)

        query_purchaseorder = PurchaseOrder.get(purchaseorder.Id,
                                                qb=self.qb_client)

        self.assertEqual(query_purchaseorder.VendorRef.value, vendor.Id)
        self.assertEqual(query_purchaseorder.APAccountRef.value, account.Id)
        self.assertEqual(query_purchaseorder.TotalAmt, 100)

        query_detail_line = query_purchaseorder.Line[0]

        self.assertEqual(query_detail_line.Amount, 100)
        self.assertEqual(
            query_detail_line.ItemBasedExpenseLineDetail.UnitPrice, 100)
        self.assertEqual(query_detail_line.ItemBasedExpenseLineDetail.Qty, 1)
        self.assertEqual(
            query_detail_line.ItemBasedExpenseLineDetail.CustomerRef.value,
            customer.Id)
        self.assertEqual(
            query_detail_line.ItemBasedExpenseLineDetail.TaxCodeRef.value,
            taxcode.Name)
        self.assertEqual(
            query_detail_line.ItemBasedExpenseLineDetail.ItemRef.value,
            item.Id)
    def test_create(self):
        account = Account()
        account.AcctNum = self.account_number
        account.Name = self.name
        account.AccountSubType = "CashOnHand"
        account.save(qb=self.qb_client)

        self.id = account.Id
        query_account = Account.get(account.Id, qb=self.qb_client)

        self.assertEquals(account.Id, query_account.Id)
        self.assertEquals(query_account.Name, self.name)
        self.assertEquals(query_account.AcctNum, self.account_number)
Beispiel #26
0
    def setUp(self):
        self.session_manager = Oauth1SessionManager(
            sandbox=True,
            consumer_key=os.environ.get('CONSUMER_KEY'),
            consumer_secret=os.environ.get('CONSUMER_SECRET'),
            access_token=os.environ.get('ACCESS_TOKEN'),
            access_token_secret=os.environ.get('ACCESS_TOKEN_SECRET'),
        )

        self.qb_client = QuickBooks(
            session_manager=self.session_manager,
            sandbox=True,
            company_id=os.environ.get('COMPANY_ID')
        )

        self.account_number = datetime.now().strftime('%d%H%M')
        self.name = "Test Item {0}".format(self.account_number)

        self.income_account = Account.where(
            "AccountType = 'Income' and AccountSubType = 'SalesOfProductIncome'", max_results=1, qb=self.qb_client)[0]

        self.expense_account = Account.where(
            "AccountSubType = 'SuppliesMaterialsCogs'", max_results=1, qb=self.qb_client)[0]
        self.asset_account = Account.where("AccountSubType = 'Inventory'", max_results=1, qb=self.qb_client)[0]
Beispiel #27
0
    def test_create(self):
        credit_card_account = Account()
        credit_card_account.Name = "Credit Card Account {0}".format(
            self.account_number)
        credit_card_account.AccountType = "Credit Card"
        credit_card_account.AccountSubType = "CreditCard"
        credit_card_account.save(qb=self.qb_client)

        accounts = Account.where(
            "Classification = 'Asset' AND FullyQualifiedName != 'Accounts Receivable (A/R)'",
            max_results=1,
            qb=self.qb_client)

        from_account = accounts[0]
        to_account = credit_card_account

        credit_card_payment = CreditCardPayment()
        credit_card_payment.Amount = 100
        credit_card_payment.BankAccountRef = from_account.to_ref()
        credit_card_payment.CreditCardAccountRef = to_account.to_ref()

        credit_card_payment.save(qb=self.qb_client)

        query_credit_card_payment = CreditCardPayment.get(
            credit_card_payment.Id, qb=self.qb_client)

        self.assertEquals(query_credit_card_payment.Id, credit_card_payment.Id)
        self.assertEquals(query_credit_card_payment.Amount, 100)
        self.assertEquals(query_credit_card_payment.BankAccountRef.value,
                          from_account.Id)
        self.assertEquals(query_credit_card_payment.CreditCardAccountRef.value,
                          to_account.Id)

        # reset transfer (so the from_account doesn't run out of cash)
        # I wonder if we can do a transfer from credit_card_account to a bank_account
        transfer = Transfer()
        transfer.Amount = 100
        transfer.FromAccountRef = to_account.to_ref()
        transfer.ToAccountRef = from_account.to_ref()

        transfer.save(qb=self.qb_client)
    def test_create(self):
        customer = Customer.all(max_results=1, qb=self.qb_client)[0]
        taxcode = TaxCode.all(max_results=1, qb=self.qb_client)[0]
        item = Item.filter(Type='Inventory', max_results=1, qb=self.qb_client)[0]
        vendor = Vendor.all(max_results=1, qb=self.qb_client)[0]
        account = Account.all(max_results=1, qb=self.qb_client)[0]

        purchaseorder = PurchaseOrder()

        detail_line = ItemBasedExpenseLine()
        detail_line.Amount = 100
        detail_line.ItemBasedExpenseLineDetail = ItemBasedExpenseLineDetail()
        detail_line.ItemBasedExpenseLineDetail.BillableStatus = "NotBillable"
        detail_line.ItemBasedExpenseLineDetail.UnitPrice = 100
        detail_line.ItemBasedExpenseLineDetail.Qty = 1
        detail_line.ItemBasedExpenseLineDetail.CustomerRef = customer.to_ref()
        detail_line.ItemBasedExpenseLineDetail.TaxCodeRef = taxcode.to_ref()
        detail_line.ItemBasedExpenseLineDetail.ItemRef = item.to_ref()

        purchaseorder.Line.append(detail_line)
        purchaseorder.VendorRef = vendor.to_ref()
        purchaseorder.APAccountRef = account.to_ref()
        purchaseorder.TotalAmt = 100

        print purchaseorder.to_json()
        purchaseorder.save(qb=self.qb_client)

        query_purchaseorder = PurchaseOrder.get(purchaseorder.Id, qb=self.qb_client)

        self.assertEquals(query_purchaseorder.VendorRef.value, vendor.Id)
        self.assertEquals(query_purchaseorder.APAccountRef.value, account.Id)
        self.assertEquals(query_purchaseorder.TotalAmt, 100)

        query_detail_line = query_purchaseorder.Line[0]

        self.assertEquals(query_detail_line.Amount, 100)
        self.assertEquals(query_detail_line.ItemBasedExpenseLineDetail.UnitPrice, 100)
        self.assertEquals(query_detail_line.ItemBasedExpenseLineDetail.Qty, 1)
        self.assertEquals(query_detail_line.ItemBasedExpenseLineDetail.CustomerRef.value, customer.Id)
        self.assertEquals(query_detail_line.ItemBasedExpenseLineDetail.TaxCodeRef.value, taxcode.Name)
        self.assertEquals(query_detail_line.ItemBasedExpenseLineDetail.ItemRef.value, item.Id)
Beispiel #29
0
    def test_create(self):
        deposit = Deposit()
        account = Account.filter(AccountType="Bank", max_results=2, qb=self.qb_client)

        account_ref = account[0].to_ref()
        deposit_to_account_ref = account[1].to_ref()

        deposit_line_detail = DepositLineDetail()
        deposit_line_detail.AccountRef = account_ref

        line = DepositLine()
        line.Amount = 20.00
        line.DetailType = "DepositLineDetail"
        line.DepositLineDetail = deposit_line_detail

        deposit.DepositToAccountRef = deposit_to_account_ref
        deposit.Line.append(line)

        deposit.save(qb=self.qb_client)

        query_deposit = Deposit.get(deposit.Id, qb=self.qb_client)

        self.assertEqual(deposit.Id, query_deposit.Id)
Beispiel #30
0
def get_account(name, user, company, client):
    account = Account.filter(Active=True, Name=name, qb=client)
    if len(account) == 0:
        return None
    else:
        return account[0]
Beispiel #31
0
    def test_valid_object_name(self):
        account = Account()
        client = QuickBooks()
        result = client.isvalid_object_name(account.qbo_object_name)

        self.assertTrue(result)
Beispiel #32
0
# Your app needs an OAuth 2.0 Access Token to access QuickBooks Online data. The OAuth 2.0 playground is the easiest way to get your access token.
#  https://developer.intuit.com/app/developer/playground
# CAN GET THE AUTH TOKEN FOR EITHER SANDBOX OR PRODUCTION APP!!!

# ALSO, this test API page lets you try things out...
# https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/account

# https://developer.intuit.com/app/developer/qbo/docs/get-started

#  By now, you have your Client ID, Client Secret, and OAuth access token. Next, you can try making an API call. In the snippet below:
from quickbooks import QuickBooks
client = QuickBooks(
    auth_client=auth_client,
    refresh_token=oauth2_token_from_auth['refreshToken'],  #'REFRESH_TOKEN',
    company_id=realm_id,  #'COMPANY_ID',
    # minorversion=4
)

from quickbooks.objects.customer import Customer
customers = Customer.all(qb=client)
# Note: The maximum number of entities that can be returned in a response is 1000. If the result size is not specified, the default number is 100. (See Intuit developer guide for details)
print("####################\nShow CUSTOMER NAMES\n####################")
for (cnt, a) in enumerate(customers):
    print(cnt, a.DisplayName)

from quickbooks.objects.account import Account
accounts = Account.all(qb=client)
print("####################\nShow ACCOUNT NAMES\n####################")
for (cnt, a) in enumerate(accounts):
    print(cnt, a.Name)
Beispiel #33
0
CLIENT_SECRET = "risgBjg1RqjqK8AVDHnYmbwnY46vG0K45v6kG3FH"
# REDIRECT_URI = "https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl"
REDIRECT_URI = "https://sandbox-quickbooks.api.intuit.com/v3"
REFRESH_TOKEN = "AB11584091105kCAQoexKsxQzQ6XGgrhDRMUl2TX5cPoowTTXa"
auth_client = AuthClient(
    client_id=CLIENT_ID,
    client_secret=CLIENT_SECRET,
    environment='sandbox',
    redirect_uri=REDIRECT_URI,
)

client = QuickBooks(auth_client=auth_client,
                    refresh_token=REFRESH_TOKEN,
                    company_id='4620816365025351930')

account = Account.count(qb=client)
# print(account)
# res = json.loads(account)
# for r in account:
#     print(r)
print(account)

# account = Account.get(1, qb=client)
# account = Account.all(1, qb=client)
# json_data = account.to_json()
# print(json_data)

# customers = Customer.query("SELECT * FROM Customer WHERE Active = True", qb=client)
# print(customers)
# print(client.company_id)
    def test_unicode(self):
        account = Account()
        account.FullyQualifiedName = "test"

        self.assertEquals(str(account), "test")
    def test_unicode(self):
        account = Account()
        account.FullyQualifiedName = "test"

        self.assertEquals(str(account), "test")
Beispiel #36
0
def post_payment(doc_number="", amount=0, btcp_id=''):
    # post payment to QBO
    '''
    doc_number: QBO invoice number
    amount: payment amount
    btcp_id: BTCPay invoice number
    '''
    refresh_stored_tokens()
    qb = fetch('qbclient')
    # check if BTCPay is already in QBO as a pmt method
    pmt_method_list = PaymentMethod.filter(Name="BTCPay", qb=qb)
    try:
        # if BTCPay is already in QBO, set it as pmt method
        pmt_method = pmt_method_list[0]
    except IndexError:
        # if BTCPay is not in QBO, create it as pmt method
        new_pmt_method = PaymentMethod()
        new_pmt_method.Name = "BTCPay"
        new_pmt_method.save(qb=qb)
        # set newly created BTCPay pmt method as pmt method
        pmt_method_list = PaymentMethod.filter(Name="BTCPay", qb=qb)
        pmt_method = pmt_method_list[0]
    # check if QBO has asset acct for Bitcoin-BTCPay
    deposit_acct_list = Account.filter(Name="Bitcoin-BTCPay", qb=qb)
    try:
        # if Bitcoin-BTCPay is in QBO, set as deposit acct
        deposit_acct = deposit_acct_list[0]
    except IndexError:
        # if Bitcoin-BTCPay is not in QBO, create it as deposit acct
        new_acct = Account()
        new_acct.Name = "Bitcoin-BTCPay"
        new_acct.AccountSubType = "OtherCurrentAssets"
        new_acct.save(qb=qb)
        # set newly created Bitcoin-BTCPay acct as deposit acct
        deposit_acct_list = Account.filter(Name="Bitcoin-BTCPay", qb=qb)
        deposit_acct = deposit_acct_list[0]
    # pull list of invoice objects matching invoice number from QBO
    invoice_list = Invoice.filter(DocNumber=doc_number, qb=qb)
    try:
        # only one invoice can match the inv #, so pull it from list
        invoice = invoice_list[0]
    except IndexError:
        app.logger.warning(f'No such invoice exists: {doc_number}')
        return None
    else:
        # convert invoice object to linked invoice object
        linked_invoice = invoice.to_linked_txn()
        description = 'BTCPay: ' + btcp_id
        payment_line = PaymentLine()
        payment_line.Amount = amount
        payment_line.Description = description
        # attach linked invoice object to payment line object
        payment_line.LinkedTxn.append(linked_invoice)
        payment = Payment()
        payment.TotalAmt = amount
        payment.CustomerRef = invoice.CustomerRef
        # create deposit acct reference object from deposit acct object
        deposit_account_ref = Ref()
        deposit_account_ref.value = deposit_acct.Id
        # create pmt method reference object from pmt method object
        pmt_method_ref = Ref()
        pmt_method_ref.name = pmt_method.Name
        # attach pmt method ref, dep acct ref, and pmt line obj to pmt obj
        payment.PaymentMethodRef = pmt_method_ref
        payment.DepositToAccountRef = deposit_account_ref
        payment.Line.append(payment_line)
        payment.save(qb=qb)
        # save payment to temp redis store to fliter duplicates
        app.redis.set(btcp_id, 'payment', ex=21600)
        return "Payment Made: " + str(payment)
Beispiel #37
0
def post_deposit(amount, tax, btcp_id):
    # post deposit to QBO
    if tax is None:
        tax = float(0)
    refresh_stored_tokens()
    qb = fetch('qbclient')
    # check if BTCPay income  acct is already in QBO
    income_acct_list = Account.filter(Name="BTCPay Sales", qb=qb)
    try:
        # if income acct exits, grab it
        income_acct = income_acct_list[0]
    except IndexError:
        # if income acct is not in QBO, create it
        new_acct = Account()
        new_acct.Name = "BTCPay Sales"
        new_acct.AccountSubType = "OtherPrimaryIncome"
        new_acct.save(qb=qb)
        # set newly created acct as income acct
        income_acct_list = Account.filter(Name="BTCPay Sales", qb=qb)
        income_acct = income_acct_list[0]
    # check if BTCPay Sales Tax acct is already in QBO
    sales_tax_acct_list = Account.filter(Name="Sales Tax from BTCPay", qb=qb)
    try:
        # if sales tax liability acct exits, grab it
        sales_tax_acct = sales_tax_acct_list[0]
    except IndexError:
        # if sales tax acct is not in QBO, create it
        new_acct = Account()
        new_acct.Name = "Sales Tax from BTCPay"
        new_acct.AccountSubType = "OtherCurrentLiabilities"
        new_acct.save(qb=qb)
        # set newly created acct as sales tax account
        sales_tax_acct_list = Account.filter(Name="Sales Tax from BTCPay",
                                             qb=qb)
        sales_tax_acct = sales_tax_acct_list[0]
    # check if QBO has asset acct for Bitcoin-BTCPay
    deposit_acct_list = Account.filter(Name="Bitcoin-BTCPay", qb=qb)
    try:
        # if Bitcoin-BTCPay is in QBO, set as deposit acct
        deposit_acct = deposit_acct_list[0]
    except IndexError:
        # if Bitcoin-BTCPay is not in QBO, create it as deposit acct
        new_acct = Account()
        new_acct.Name = "Bitcoin-BTCPay"
        new_acct.AccountSubType = "OtherCurrentAssets"
        new_acct.save(qb=qb)
    # set newly created Bitcoin-BTCPay acct as deposit acct
    deposit_acct_list = Account.filter(Name="Bitcoin-BTCPay", qb=qb)
    deposit_acct = deposit_acct_list[0]
    # create deposit
    description = 'BTCPay: ' + btcp_id
    income_acct_ref = Ref()
    income_acct_ref.value = income_acct.Id
    detail = DepositLineDetail()
    detail.AccountRef = income_acct_ref
    line = DepositLine()
    line.DepositLineDetail = detail
    deposit_account_ref = Ref()
    deposit_account_ref.value = deposit_acct.Id
    line.Amount = amount - tax
    line.Description = description
    # create sales tax line
    sales_tax_acct_ref = Ref()
    sales_tax_acct_ref.value = sales_tax_acct.Id
    line2 = DepositLine()
    detail2 = DepositLineDetail()
    detail2.AccountRef = sales_tax_acct_ref
    line2.DepositLineDetail = detail2
    line2.Description = description
    line2.Amount = tax
    deposit = Deposit()
    deposit.Line.append(line)
    deposit.Line.append(line2)
    deposit.DepositToAccountRef = deposit_account_ref
    deposit.save(qb=qb)
    # save payment to temp redis store to fliter duplicates
    app.redis.set(btcp_id, 'deposit', ex=21600)
    return 'Deposit Made: ' + str(deposit)
 def testFundAccount(self):
     '''Test funding the account Assert Balance equal to deposit'''
     account = fund_account(self.account, 1000, self.client)
     account = Account.get(account.Id, qb=self.client)
     self.assertEqual(account.CurrentBalance, 1000)