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)
Exemple #2
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)
    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 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))
Exemple #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))
Exemple #6
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}
Exemple #7
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}
Exemple #8
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]
Exemple #9
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
    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)
Exemple #11
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]
Exemple #12
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)
Exemple #13
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)