def test_create_note(self): attachable = Attachable() vendor = Vendor.all(max_results=1, qb=self.qb_client)[0] attachable_ref = AttachableRef() attachable_ref.EntityRef = vendor.to_ref() attachable.AttachableRef.append(attachable_ref) attachable.Note = "Test note added on {}".format(self.time.strftime("%Y-%m-%d %H:%M:%S")) attachable.save(qb=self.qb_client) query_attachable = Attachable.get(attachable.Id, qb=self.qb_client) self.assertEquals(query_attachable.AttachableRef[0].EntityRef.value, vendor.Id) self.assertEquals(query_attachable.Note, "Test note added on {}".format(self.time.strftime("%Y-%m-%d %H:%M:%S")))
def test_create_file(self): attachable = Attachable() vendor = Vendor.all(max_results=1, qb=self.qb_client)[0] attachable_ref = AttachableRef() attachable_ref.EntityRef = vendor.to_ref() attachable.AttachableRef.append(attachable_ref) attachable.FileName = 'TestFileName' attachable._FilePath = __file__ attachable.ContentType = 'application/txt' attachable.save(qb=self.qb_client) query_attachable = Attachable.get(attachable.Id, qb=self.qb_client) self.assertEquals(query_attachable.AttachableRef[0].EntityRef.value, vendor.Id)
def test_create_file(self): attachable = Attachable() test_file = tempfile.NamedTemporaryFile(suffix=".txt") vendor = Vendor.all(max_results=1, qb=self.qb_client)[0] attachable_ref = AttachableRef() attachable_ref.EntityRef = vendor.to_ref() attachable.AttachableRef.append(attachable_ref) attachable.FileName = os.path.basename(test_file.name) attachable._FilePath = test_file.name attachable.ContentType = 'text/plain' attachable.save(qb=self.qb_client) query_attachable = Attachable.get(attachable.Id, qb=self.qb_client) self.assertEquals(query_attachable.AttachableRef[0].EntityRef.value, vendor.Id)
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