コード例 #1
0
    def syncContactData(self):
        page = 0

        date = datetime.datetime.now().strftime("%Y-%m-%d") + '%'

        contactData = self.getContactDataByDate(date, page)

        while contactData:
            for contact in contactData:
                tContact = Contact.objects.filter(CrmId=contact['Id'])
                if tContact.exists():
                    tContact.update(FirstName=contact['FirstName'], LastName=contact['LastName'],
                                        PhoneNumber=contact['Phone1'], Company=contact['Company'])
                else:
                    if 'LastName' not in contact:
                        contact['LastName'] = ""
                    if 'FirstName' not in contact:
                        contact['FirstName'] = ""
                    if 'Phone1' not in contact:
                        contact['Phone1'] = ""
                    if 'Company' not in contact:
                        contact['Company'] = ""
                    tContact = Contact(FirstName=contact['FirstName'], LastName=contact['LastName'],
                                            PhoneNumber=contact['Phone1'], Company=contact['Company'], CrmId=contact['Id'])
                    tContact.save()

            page = page + 1
            contactData = self.getContactDataByDate(date, page)
            print("Contact Synced\n")
コード例 #2
0
    def syncInvoiceData(self):
        page = 0

        date = datetime.datetime.now().strftime("%Y-%m-%d") + '%'

        invoiceData = self.getInvoiceDataByDate(date, page)

        while invoiceData:
            for invoice in invoiceData:
                tInvoice = Invoice.objects.filter(InvoiceId=invoice['Id'])
                if not tInvoice.exists():
                   tInvoice = Contact(ContactId=invoice['ContactId'], TotalPaid=invoice['TotalPaid'],
                                            TotalDue=invoice['TotalDue'], InvoiceId=invoice['Id'],
                                            InvoiceTotal=invoice['InvoiceTotal'], RefundStatus=invoice['RefundStatus'],
                                            DateCreated=invoice['DateCreated'])
                   tInvoice.save()
                   print("Invoice inserted\n")

            page = page + 1
            invoiceData = self.getInvoiceDataByDate(date, page)
        print("Invoice Synced\n")