示例#1
0
from models import Customer
from quickbooks.objects.customer import Customer as QbCustomer
from qbclient import client

customersLeft = True 
totalCustomers = []
startPosition = 1
maxResults = 1000
page = 1
qbLastUpdate = None

while customersLeft:
	startPosition = (page - 1) * maxResults + 1
	customers = QbCustomer.query("SELECT * FROM Customer STARTPOSITION {0} MAXRESULTS {1}".format(startPosition, maxResults),qb=client)
	totalCustomers.extend(customers)

	page += 1

	if len(customers) < 1000:
		customersLeft = False

for customer in totalCustomers:

	newCustomer = Customer()
	newCustomer.from_quickbooks(customer)
	newCustomer.save()
示例#2
0
 def sync_dues(self, request):
     """
     This will sync with quickbooks
     """
     client = get_quickbooks_client()
     chapter_name = self.name
     if "Chapter" in chapter_name:
         chapter_name = chapter_name.replace(" Chapter", "")
     customer = Customer.query(
         select=f"SELECT * FROM Customer WHERE CompanyName LIKE '{chapter_name} chapter%'",
         qb=client,
     )
     if customer:
         customer = customer[0]
     else:
         messages.add_message(
             request,
             messages.ERROR,
             f"Quickbooks Customer matching name: '{chapter_name} Chapter...' not found",
         )
         return
     invoice, linenumber_count = invoice_search("1", customer, client)
     count = self.active_actives().count()
     if not self.candidate_chapter:
         # D1; Service; Semiannual Chapter Dues payable @ $80 each # Minimum per chapter is $1600.
         line = create_line(
             count, linenumber_count, name="D1", minimum=1600, client=client
         )
         l1_min = 250
         if self.house:
             l1_min = 1125
     else:
         # D2; Service; Semiannual Colony Dues
         line = create_line(count, linenumber_count, name="D2", client=client)
         l1_min = 125
     linenumber_count += 1
     invoice.Line.append(line)
     # L1; Service; Health and Safety Assessment - Semesterly
     #   minimum for housed chapters ($1125)
     #   unhoused chapters ($250)
     #   Colony Minimum is $125
     line = create_line(
         count, linenumber_count, name="L1", minimum=l1_min, client=client
     )
     linenumber_count += 1
     invoice.Line.append(line)
     if self.health_safety_surcharge != "none":
         line = create_line(
             line.Amount,
             linenumber_count,
             name=self.health_safety_surcharge,
             client=client,
         )
         invoice.Line.append(line)
     memo = f"Actives: {count}; Surcharge: {self.SURCHARGE.get_value(self.health_safety_surcharge)}"
     memo = memo[0:999]
     invoice.CustomerMemo.value = memo
     invoice.DeliveryInfo = None
     invoice_obj = invoice.save(qb=client)
     attachment_path = self.generate_dues_attachment(file_obj=True)
     attachment = Attachable()
     attachable_ref = AttachableRef()
     attachable_ref.EntityRef = invoice.to_ref()
     attachable_ref.IncludeOnSend = True
     attachment.AttachableRef.append(attachable_ref)
     attachment.FileName = attachment_path.name
     attachment._FilePath = str(attachment_path.absolute())
     attachment.ContentType = "text/csv"
     attachment.save(qb=client)
     if attachment_path.exists():
         attachment_path.unlink()  # Delete the file when we are done
     return invoice_obj.DocNumber