Exemple #1
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)
Exemple #2
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)
    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)
    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)
Exemple #5
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)
Exemple #6
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 #7
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 #8
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)