def test_unicode(self): ref = Ref() ref.type = "type" ref.name = "test" ref.value = 1 self.assertEquals(str(ref), "test")
def test_create(self): bill = Bill() line = AccountBasedExpenseLine() line.Amount = 200 line.DetailType = "AccountBasedExpenseLineDetail" account_ref = Ref() account_ref.type = "Account" account_ref.value = 1 line.AccountBasedExpenseLineDetail = AccountBasedExpenseLineDetail() line.AccountBasedExpenseLineDetail.AccountRef = account_ref bill.Line.append(line) vendor = Vendor.all(max_results=1, qb=self.qb_client)[0] bill.VendorRef = vendor.to_ref() bill.save(qb=self.qb_client) query_bill = Bill.get(bill.Id, qb=self.qb_client) self.assertEquals(query_bill.Id, bill.Id) self.assertEquals(len(query_bill.Line), 1) self.assertEquals(query_bill.Line[0].Amount, 200.0)
def test_create(self): bill = Bill() line = BillLine() line.Amount = 200 line.DetailType = "AccountBasedExpenseLineDetail" account_ref = Ref() account_ref.type = "Account" account_ref.value = 1 line.AccountBasedExpenseLineDetail = AccountBasedExpenseLineDetail() line.AccountBasedExpenseLineDetail.AccountRef = account_ref bill.Line.append(line) vendor = Vendor.all(max_results=1, qb=self.qb_client)[0] bill.VendorRef = vendor.to_ref() bill.save(qb=self.qb_client) query_bill = Bill.get(bill.Id, qb=self.qb_client) self.assertEquals(query_bill.Id, bill.Id) self.assertEquals(len(query_bill.Line), 1) self.assertEquals(query_bill.Line[0].Amount, 200.0)
def test_create(self): self.customer = Customer.all(max_results=1, qb=self.qb_client)[0] estimate = Estimate() estimate.TotalAmt = 31.5 estimate.ApplyTaxAfterDiscount = False estimate.PrintStatus = "NeedToPrint" estimate.EmailStatus = "NotSet" estimate.BillAddr = Address() estimate.BillAddr.Line1 = "65 Ocean Dr." estimate.BillAddr.City = "Half Moon Bay" estimate.BillAddr.CountrySubDivisionCode = "CA" estimate.BillAddr.PostalCode = "94213" estimate.BillAddr.Lat = "37.4300318" estimate.BillAddr.Long = "-122.4336537" estimate.ShipAddr = Address() estimate.ShipAddr.Id = "2" + datetime.now().strftime('%d%H%M') estimate.ShipAddr.Line1 = "65 Ocean Dr." estimate.ShipAddr.City = "Half Moon Bay" estimate.ShipAddr.CountrySubDivisionCode = "CA" estimate.ShipAddr.PostalCode = "94213" estimate.ShipAddr.Lat = "37.4300318" estimate.ShipAddr.Long = "-122.4336537" estimate.BillEmail = EmailAddress() estimate.BillEmail.Address = "*****@*****.**" estimate.CustomerMemo = CustomerMemo() estimate.CustomerMemo.value = "Thank you for your business and have a great day!" estimate.CustomerRef = Ref() estimate.CustomerRef.value = self.customer.Id estimate.CustomerRef.name = self.customer.DisplayName estimate.TxnTaxDetail = TxnTaxDetail() estimate.TxnTaxDetail.TotalTax = 0 line = SalesItemLine() line.LineNum = 1 line.Description = "Pest Control Services" line.Amount = 35.0 line.SalesItemLineDetail = SalesItemLineDetail() line.SalesItemLineDetail.UnitPrice = 35 line.SalesItemLineDetail.Qty = 1 item_ref = Ref() item_ref.value = "10" item_ref.name = "Pest Control" line.SalesItemLineDetail.ItemRef = item_ref tax_code_ref = Ref() tax_code_ref.value = "NON" line.SalesItemLineDetail.TaxCodeRef = tax_code_ref estimate.Line.append(line) line2 = DiscountLine() line2.Amount = 3.5 line2.DiscountLineDetail = DiscountLineDetail() line2.DiscountLineDetail.PercentBased = True line2.DiscountLineDetail.DiscountPercent = 10 line2.DiscountLineDetail.DiscountAccountRef = Ref() line2.DiscountLineDetail.DiscountAccountRef.value = "86" line2.DiscountLineDetail.DiscountAccountRef.name = "Discounts given" line2.DetailType = "DiscountLineDetail" estimate.Line.append(line2) estimate.save(qb=self.qb_client) query_estimate = Estimate.get(estimate.Id, qb=self.qb_client) self.assertEqual(query_estimate.Id, estimate.Id) self.assertEqual(query_estimate.TotalAmt, estimate.TotalAmt) self.assertEqual(query_estimate.ApplyTaxAfterDiscount, estimate.ApplyTaxAfterDiscount) self.assertEqual(query_estimate.PrintStatus, estimate.PrintStatus) self.assertEqual(query_estimate.EmailStatus, estimate.EmailStatus) self.assertEqual(query_estimate.BillAddr.Line1, estimate.BillAddr.Line1) self.assertEqual(query_estimate.BillAddr.City, estimate.BillAddr.City) self.assertEqual(query_estimate.BillAddr.CountrySubDivisionCode, estimate.BillAddr.CountrySubDivisionCode) self.assertEqual(query_estimate.BillAddr.PostalCode, estimate.BillAddr.PostalCode) self.assertEqual(query_estimate.ShipAddr.Line1, estimate.ShipAddr.Line1) self.assertEqual(query_estimate.ShipAddr.City, estimate.ShipAddr.City) self.assertEqual(query_estimate.ShipAddr.CountrySubDivisionCode, estimate.ShipAddr.CountrySubDivisionCode) self.assertEqual(query_estimate.ShipAddr.PostalCode, estimate.ShipAddr.PostalCode) self.assertEqual(query_estimate.BillEmail.Address, estimate.BillEmail.Address) self.assertEqual(query_estimate.CustomerMemo.value, estimate.CustomerMemo.value) self.assertEqual(query_estimate.CustomerRef.value, estimate.CustomerRef.value) self.assertEqual(query_estimate.CustomerRef.name, estimate.CustomerRef.name) self.assertEqual(query_estimate.TxnTaxDetail.TotalTax, estimate.TxnTaxDetail.TotalTax) self.assertEqual(query_estimate.Line[0].LineNum, estimate.Line[0].LineNum) self.assertEqual(query_estimate.Line[0].Description, estimate.Line[0].Description) self.assertEqual(query_estimate.Line[0].Amount, estimate.Line[0].Amount) self.assertEqual(query_estimate.Line[0].SalesItemLineDetail.UnitPrice, estimate.Line[0].SalesItemLineDetail.UnitPrice) self.assertEqual(query_estimate.Line[0].SalesItemLineDetail.Qty, estimate.Line[0].SalesItemLineDetail.Qty) self.assertEqual(query_estimate.Line[2].Amount, estimate.Line[1].Amount) self.assertEqual( query_estimate.Line[2].DiscountLineDetail.PercentBased, estimate.Line[1].DiscountLineDetail.PercentBased) self.assertEqual( query_estimate.Line[2].DiscountLineDetail.DiscountPercent, estimate.Line[1].DiscountLineDetail.DiscountPercent) self.assertEqual( query_estimate.Line[2].DiscountLineDetail.DiscountAccountRef.value, estimate.Line[1].DiscountLineDetail.DiscountAccountRef.value) self.assertEqual( query_estimate.Line[2].DiscountLineDetail.DiscountAccountRef.name, estimate.Line[1].DiscountLineDetail.DiscountAccountRef.name)
def test_create(self): estimate = Estimate() estimate.TotalAmt = 31.5 estimate.ApplyTaxAfterDiscount = False estimate.PrintStatus = "NeedToPrint" estimate.EmailStatus = "NotSet" estimate.BillAddr = Address() # estimate.BillAddr.Id = "1" + datetime.now().strftime('%d%H%M') estimate.BillAddr.Line1 = "65 Ocean Dr." estimate.BillAddr.City = "Half Moon Bay" estimate.BillAddr.CountrySubDivisionCode = "CA" estimate.BillAddr.PostalCode = "94213" estimate.BillAddr.Lat = "37.4300318" estimate.BillAddr.Long = "-122.4336537" estimate.ShipAddr = Address() estimate.ShipAddr.Id = "2" + datetime.now().strftime('%d%H%M') estimate.ShipAddr.Line1 = "65 Ocean Dr." estimate.ShipAddr.City = "Half Moon Bay" estimate.ShipAddr.CountrySubDivisionCode = "CA" estimate.ShipAddr.PostalCode = "94213" estimate.ShipAddr.Lat = "37.4300318" estimate.ShipAddr.Long = "-122.4336537" estimate.BillEmail = EmailAddress() estimate.BillEmail.Address = "*****@*****.**" estimate.CustomerMemo = CustomerMemo() estimate.CustomerMemo.value = "Thank you for your business and have a great day!" estimate.CustomerRef = Ref() estimate.CustomerRef.value = self.customer.Id estimate.CustomerRef.name = self.customer.DisplayName estimate.TxnTaxDetail = TxnTaxDetail() estimate.TxnTaxDetail.TotalTax = 0 line = SalesItemLine() line.LineNum = 1 line.Description = "Pest Control Services" line.Amount = 35.0 line.SalesItemLineDetail = SalesItemLineDetail() line.SalesItemLineDetail.UnitPrice = 35 line.SalesItemLineDetail.Qty = 1 item_ref = Ref() item_ref.value = "10" item_ref.name = "Pest Control" line.SalesItemLineDetail.ItemRef = item_ref tax_code_ref = Ref() tax_code_ref.value = "NON" line.SalesItemLineDetail.TaxCodeRef = tax_code_ref estimate.Line.append(line) line2 = DetailLine() line2.Amount = 3.5 discount_line_detail = DiscountLineDetail() discount_line_detail.PercentBased = True discount_line_detail.DiscountPercent = 10 discount_account_ref = Ref() discount_account_ref.value = "86" discount_account_ref.name = "Discounts given" discount_line_detail.DiscountAccountRef = discount_account_ref line2.DetailType = "DiscountLineDetail" line2.DiscountLineDetail = discount_line_detail estimate.Line.append(line2) estimate.save(qb=self.qb_client) query_estimate = Estimate.get(estimate.Id, qb=self.qb_client) self.assertEqual(query_estimate.Id, estimate.Id) self.assertEqual(query_estimate.TotalAmt, estimate.TotalAmt) self.assertEqual(query_estimate.ApplyTaxAfterDiscount, estimate.ApplyTaxAfterDiscount) self.assertEqual(query_estimate.PrintStatus, estimate.PrintStatus) self.assertEqual(query_estimate.EmailStatus, estimate.EmailStatus) self.assertEqual(query_estimate.BillAddr.Line1, estimate.BillAddr.Line1) self.assertEqual(query_estimate.BillAddr.City, estimate.BillAddr.City) self.assertEqual(query_estimate.BillAddr.CountrySubDivisionCode, estimate.BillAddr.CountrySubDivisionCode) self.assertEqual(query_estimate.BillAddr.PostalCode, estimate.BillAddr.PostalCode) self.assertEqual(query_estimate.ShipAddr.Line1, estimate.ShipAddr.Line1) self.assertEqual(query_estimate.ShipAddr.City, estimate.ShipAddr.City) self.assertEqual(query_estimate.ShipAddr.CountrySubDivisionCode, estimate.ShipAddr.CountrySubDivisionCode) self.assertEqual(query_estimate.ShipAddr.PostalCode, estimate.ShipAddr.PostalCode) self.assertEqual(query_estimate.BillEmail.Address, estimate.BillEmail.Address) self.assertEqual(query_estimate.CustomerMemo.value, estimate.CustomerMemo.value) self.assertEqual(query_estimate.CustomerRef.value, estimate.CustomerRef.value) self.assertEqual(query_estimate.CustomerRef.name, estimate.CustomerRef.name) self.assertEqual(query_estimate.TxnTaxDetail.TotalTax, estimate.TxnTaxDetail.TotalTax) self.assertEqual(query_estimate.Line[0].LineNum, estimate.Line[0].LineNum) self.assertEqual(query_estimate.Line[0].Description, estimate.Line[0].Description) self.assertEqual(query_estimate.Line[0].Amount, estimate.Line[0].Amount)
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 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)