def test_download_pdf(self, qb_session): qb_client = client.QuickBooks(sandbox=True) qb_client.company_id = "1234" receipt = SalesReceipt() receipt.Id = 1 receipt.download_pdf(qb_client) url = "https://sandbox-quickbooks.api.intuit.com/v3/company/1234/salesreceipt/1/pdf" qb_session.request.assert_called_with( "GET", url, True, "1234", headers={'Content-Type': 'application/pdf', 'Accept': 'application/pdf, application/json'}) qb_session.request.return_value = MockPdfResponse() response = receipt.download_pdf(qb_client) self.assertEqual(response, 'sample pdf content')
def test_download_nonexistent_pdf(self): receipt = SalesReceipt() receipt.Id = 666 self.assertRaises(QuickbooksException, receipt.download_pdf)
def test_make_request_create_session(self): receipt = SalesReceipt() receipt.Id = 1 self.assertRaises(QuickbooksException, receipt.save)
def test_download_invoice(self, download_pdf): receipt = SalesReceipt() receipt.Id = 1 receipt.download_pdf(self.qb_client) download_pdf.assert_called_once_with('SalesReceipt', 1)
def test_unicode(self): sales_receipt = SalesReceipt() sales_receipt.TotalAmt = 100 self.assertEquals(unicode(sales_receipt), "100")
def test_download_invoice(self, download_pdf): receipt = SalesReceipt() receipt.Id = 1 receipt.download_pdf() download_pdf.assert_called_once_with('SalesReceipt', 1)
def test_download_missing_id(self): from quickbooks.exceptions import QuickbooksException receipt = SalesReceipt() self.assertRaises(QuickbooksException, receipt.download_pdf)
def test_download_invoice(self, download_pdf): receipt = SalesReceipt() receipt.Id = 1 receipt.download_pdf() download_pdf.assert_called_once_with("SalesReceipt", 1)
def create_order(sr): #Get the sales receipt sales_receipt = SalesReceipt() sr_body = { "domain": "QBO", "Balance": 0, "CustomerRef": { "name": "", "value": "6" }, "CustomerMemo": { "value": "" }, "sparse": "false", "Line": [{ #"Description": "Custom Design", "DetailType": "SalesItemLineDetail", #required "SalesItemLineDetail": { "Qty": 1, #"UnitPrice": 75, "ItemRef": { #required "value": "44" #black mulch (1-9) } }, "LineNum": 1, "Amount": 0, }], "CustomField": [{ "DefinitionId": "1", "Name": "Scout Credit", "Type": "StringType", "StringValue": "" }], "PaymentMethodRef": { "value": lookup_payment_method('square') }, "CustomerMemo": { "value": sr.memo }, } #amys = Customer.filter(start_position=1, max_results=25, Active=True, FamilyName="Smith", qb=qb_client) #amys = Customer.query("SELECT * from Customers where FamilyName='Smith'", qb=qb_client) #amys = qb_client.query("select count(*) from Customer Where Active=true and DisplayName LIKE '%Smith'") #customer_street_number = sr.customer_street.split(' ')[0] query = "Active=true and DisplayName = '" + sr.customer_name.lower() + "'" try: customers_count = Customer.count(query, qb=qb_client) except ValidationException as ve: print(ve.detail) if customers_count == 0: # create a new customer? if AUTO_CREATE_CUSTOMERS: answer = yesno( "Customer [{}] not found. Create the customer?".format( sr.customer_name)) if answer: logging.warning( "Creating the customer [{}] in quickbooks.".format( sr.customer_name)) customer = create_customer(sr) if customer is not None: customers_count = 1 else: logging.warning( "Customer [{}] not found. Not creating customer due to settings." .format(sr.customer_name)) if customers_count == 1: #we have found a customer customers = Customer.where("Active=true and DisplayName LIKE '%" + sr.customer_last + "'", qb=qb_client) customer_id = customers[0].Id customer_name = customers[0].DisplayName logging.debug("Customer id: {}".format(customer_id)) check_and_update_customer_information(sr, customer_id) sr_body['CustomerRef']['value'] = customer_id sr_body['CustomerRef']['name'] = customer_name sr_body['Line'][0]['Amount'] = sr.total_price product_id = lookup_product(sr.product_name) sr_body['Line'][0]['SalesItemLineDetail']['ItemRef'][ 'value'] = product_id sr_body['Line'][0]['SalesItemLineDetail']['Qty'] = sr.product_qty sr_body['Line'][0]['SalesItemLineDetail'][ 'UnitPrice'] = sr.product_price logging.debug("Revised Customer: {}".format(sr_body)) #print("SR Body: {}".format(sr_body)) #post a new one sales_receipt = sales_receipt.from_json(sr_body) sales_receipt.TxnDate = sr.date #check for duplicates #get all customer sales receipts duplicate = False srs = SalesReceipt.filter(CustomerRef=customer_id, qb=qb_client) for asr in srs: #print(asr.Line[0].SalesItemLineDetail['ItemRef']['name']) if asr.Line[0].SalesItemLineDetail['ItemRef']['name'] == sr.product_name \ and asr.Line[0].SalesItemLineDetail['Qty'] == sr.product_qty \ and float(asr.TotalAmt) == float(sr.total_price): logging.warning( "found a duplicate for this customer: {} on {} for item: {}, qty: {}, total: {}. skipping..." .format(sr.customer_name, sr.date, sr.product_name, sr.product_qty, sr.total_price)) duplicate = True #add the item if not duplicate: try: sales_receipt.save(qb_client) logging.debug("SentBody: {}".format(json.dumps(sr_body))) logging.info( "Successful entry of SalesReceipt: [{}] into quickbooks. OrderId:[{}], Item:[{}], Qty:[{}], Total:[{}]" .format(sr.customer_last, sales_receipt.Id, sr.product_name, sr.product_qty, sr.total_price)) except QuickbooksException as e: logging.error("An error saving the sales_receipt: {}".format( e.detail)) elif customers_count > 1: logging.warning( "More than one customer matches name: [{}]. Cannot process record. Skipping." .format(sr.customer_last)) else: print("no customer found")
def test_download_invoice(self, download_pdf): receipt = SalesReceipt() receipt.Id = "1" receipt.download_pdf(self.qb_client) download_pdf.assert_called_once_with('SalesReceipt', "1")