Giter Club home page Giter Club logo

django-quickbooks's Introduction

Django Quickbooks

This is an ongoing project to integrate any Django project with Quickbooks Desktop and Quickbooks Online. Quickbooks integration support for Python 3.6+ and Django 2.0+

Join our active, engaged community:
| Spectrum |
Version: 0.6.4.2
Download: https://pypi.org/project/django-quickbooks/
Source: https://github.com/weltlink/django-quickbooks/
Keywords: quickbooks,quickbooks-django,django,quickbooks-desktop,quickbooks-online,qb,qbwc,qwc,integration,django-quickbooks

Features

Quickbooks Desktop

  • Soap session handling for 8 basic quickbooks web connector operations:
    1. authenticate()
    2. clientVersion()
    3. closeConnection()
    4. connectionError()
    5. getLastError()
    6. getServerVersion()
    7. receiveResponseXML()
    8. sendRequestXML()
    9. interactiveDone() - not really implemented
    10. interactiveRejected() - not really implemented
    11. interactiveUrl() - not really implemented
  • Several Realm management model (for handling multiple web connector integration)
  • Realm Session management model (for handling concurrent web connector connections)
  • QuickBooks Task management model (for handling object synchronization updates)
  • Abstract Processor implementation for easier QBXML response handling
  • Abstract Object implementation for easier QBXML bidirectional data conversion
  • Abstract Service implementation for easier QBXML object manipulation

Quickbooks Online

...

Roadmap

  • Quickbooks Desktop Integration (most of the job is done, but can be improved)
  • Add all other remaining quickbooks objects (or most important ones)
  • Add all other remaining services (or most important ones)
  • Add all other remaining processors (or most important ones)
  • Quickbooks Online Integration (or most important ones)

Requirements

  • Python 3.6+
  • Django 2.0+
  • RabbitMQ (or reimplementation of QueueManager)
  • Redis (or reimplementation of QueueManager)
  • Celery (for handling asynchronous tasks)

Notice

Soap server for Quickbooks Web Connector is built on top of Spyne and Lxml.

Setup & Documentation

Installation

Installation from pypi:

pip install django-quickbooks

OR

Installation from source (github):

pip install -e git+https://github.com/weltlink/django-quickbooks.git@master#egg=django-quickbooks

You can run pip install django-quickbooks pika spyne celery redis to install all of the dependencies.

Run migrations: manage.py makemigrations , manage.py migrate

Create a new record in django_quickbooks_realm

You should create a new realm for each of your users.
We will do that from the django shell.
Execute the command manage.py shell and follow these instructions:

from django_quickbooks.models import Realm
realm = Realm(name='TEST NAME', is_active=True, schema_name='default')
realm.set_password('RAW PASSWORD')
# django-quickbooks hashes the raw password and only store the hash similar to what django user do.
# this password is what the user will be using in QBWC
realm.save()

You should automate the previous steps in your code to create a new realm for each user of yours

If you want to communicate with QBPOS instead of QB Desktop you should edit the settings.py file in django-quickbooks itself, Go to setting.py and change QB_TYPE = 'QBPOS' instead of 'QBFS' in DEFAULTS dict. this will be changed to a better approach later.

QBWC and .qwc file

Download QBWC from [http://marketplace.intuit.com/webconnector].

Make sure to use the compatible QBWC versions with your QB Desktop or QB POS version, Note that latest != compatible, you may need an older version to work with your QB solution.

Now we need to create a qwc file manage.py create_qwc choose a realm and walk through the steps, copy the output to a .txt file and change the extension to .qwc open your QB or QB POS company file double click the .qwc file, give permission to QBWC to access your company file enter the realm password for this user

RabbitMQ

You need to install RabbitMQ (if you want to use default QueueManager) which is a widely known message broker. However, RabbitMQ implementation of QueueManager is being deprecated as it could not be implemented in the right way to keep robust connection, instead it is recommended to use Redis. You can find instructions on how to install RabbitMQ here.

Redis

You can also install Redis (as an alternative to RabbitMQ implementation of QueueManager) which is a widely known as in-memory data structure. You can find instructions on how to install Redis here.

Implementation

Add django_quickbooks to your installed apps in settings.py.
Add the following line to urlspatterns list inside urls.py:

path(r'^qwc/', include("django_quickbooks.urls"))

Inherit the QBDModelMixin to the model that you want to sync with QB or QBPOS. Make sure to add and implement these 2 methods: to_qbd_obj() and from_qbd_obj() inside your model, so that django_quickbooks can communicate with your project model

from django_quickbooks.models import QBDModelMixin

# This is just an example, you should have your own fields
class Customer(models.Model, QBDModelMixin):
    first_name = models.CharField(max_length=255, null=True)
    last_name = models.CharField(max_length=255, null=True)
    email = models.CharField(max_length=255, blank=True, null=True)
    phone = models.CharField(max_length=10)
    street = models.CharField(max_length=255, blank=True, null=True)
    zip = models.CharField(max_length=255, blank=True, null=True)
    city = models.CharField(max_length=255, blank=True, null=True)
    state = models.CharField(max_length=255, blank=True, null=True)
    
    def __str__(self):
        return f'{self.first_name} {self.last_name}'
	
    def to_qbd_obj(self, **fields):
        from django_quickbooks.objects import Customer as QBCustomer
        # map your fields to the qbd_obj fields
        return QBCustomer(Name=self.__str__(),
                          IsActive=True,
                          Phone=self.phone,
                          )

    @classmethod			  
    def from_qbd_obj(cls, qbd_obj):
        # map qbd_obj fields to your model fields
        return cls(
            first_name=qbd_obj.Name,
	    phone=qbd_obj.Phone,
            qbd_object_id=qbd_obj.ListID,
            qbd_object_version=qbd_obj.EditSequence
        )

Signal Handler

We are almost finished, add a signal handler for the desired events i.e. post_save, post_delete, etc

from django.db.models.signals import pre_delete, post_save
@receiver(post_save, sender=Customer)
def send_customer_to_qbtask(sender, instance, **kwargs):
	QBDTask.objects.create(qb_operation=QUICKBOOKS_ENUMS.OPP_ADD,
                       qb_resource=QUICKBOOKS_ENUMS.RESOURCE_CUSTOMER,
                       object_id=instance.id,
                       content_type=ContentType.objects.get_for_model(instance),
                       realm_id="YOUR REALM ID"
                       )

You can use any method you would like to create a record in QBDTask, make sure to populate all these fields correctly.

Contributing

Check out our smaller-roadmap or larger-roadmap to see on what you can help us to improve. Or if you have any problem just drop us a line or open an issue and we’ll work out how to handle it.

Links

References

This library could not be possible without contributions from other open-source projects. Thanks for quickbooks-php for giving the concept of creating quickbooks toolkit. Thanks for Django_to_QuickBooks_API and pyqwc for giving core realization of soap server which made this library possible.

django-quickbooks's People

Contributors

bedilbek avatar hassaanalansary avatar nrkfred avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-quickbooks's Issues

queue_manager.py _get_connection failing

For some reason pika's BlockingConnection is just getting stuck. Not sure if I need to do anything to the rabbitmq settings? I followed the documentation and trying to simply add a customer.

This function inside of queue manager fails.

    def _get_connection(self) -> BlockingConnection:
        if hasattr(self, '_connection') and self._connection and self._connection.is_open:
            return self._connection
        self._connection = BlockingConnection(
            ConnectionParameters(
                host=qbwc_settings.RABBITMQ_DEFAULT_HOST,
                virtual_host=qbwc_settings.RABBITMQ_DEFAULT_VHOST,
                credentials=PlainCredentials(
                    username=qbwc_settings.RABBITMQ_DEFAULT_USER,
                    password=qbwc_settings.RABBITMQ_DEFAULT_PASS
                ),
                heartbeat=600,
                blocked_connection_timeout=300,
                connection_attempts=1000,
            )
        )

        return self._connection

Stability

Hi, this project looks great and seems to be exactly what I'm looking for. However, I am curious about stability. Is the project as a whole ready for production use? Are the QB Desktop features ready for production use?

Thanks!

Is there an easy way to create an customer/invoice via this project?

I see there's classes such as Customer, Invoice which I presume are created for common use cases.

Say my goal is to programmatically create a customer/invoice, is there a quickstart guide for doing so?

I.e once I'm authed with QB desktop, is there a way to create a customer and send that request to the webconnector to process?
either via raw xml or a model?

If yall could post a short snippet on either this README example https://github.com/weltlink/django-quickbooks#implementation

or provide guidance on how I would add this customer to the QBD Task queue, that would be greatly appreciated!
Trying to understand what the django_quickbooks.services is used for....

from django_quickbooks.objects import BillAddress, ShipAddress, Customer
from django_quickbooks.services.customer import CustomerService
from lxml import etree

customer_xml = """<?xml version="1.0"?><?qbxml version="13.0"?>
<QBXML>
    <QBXMLMsgsRq onError="stopOnError">
        <CustomerAddRq>
            <CustomerAdd>
                <Name>Amazon</Name>
                <FullName>Amazon</FullName>
                <IsActive>true</IsActive>
                <CompanyName>Amazon</CompanyName>
                <BillAddress>
                    <Addr1>2305 Litton Ln</Addr1>
                    <City>Hebron</City>
                    <State>Kentucky</State>
                    <PostalCode>41048</PostalCode>
                    <Country>United States</Country>
                    <Note>Nice address</Note>
                </BillAddress>
                <ShipAddress>
                    <Addr1>2305 Litton Ln</Addr1>
                    <City>Hebron</City>
                    <State>Kentucky</State>
                    <PostalCode>41048</PostalCode>
                    <Country>United States</Country>
                    <Note>Nice address</Note>
                </ShipAddress>
                <Phone>998909090909</Phone>
                <AltPhone>998909090910</AltPhone>
                <Fax>998909090911</Fax>
                <Email>[email protected]</Email>
                <Contact>Someone from Amazon</Contact>
                <AltContact>Some other one from Amazon</AltContact>
            </CustomerAdd>
        </CustomerAddRq>
    </QBXMLMsgsRq>
</QBXML>"""

root_lxml = etree.fromstring(customer_xml)
customer = Customer.from_lxml(root_lxml)
cs = CustomerService()
cs.add(customer)

How to only send XML data using this library

class create_xml_customer(Service):
def run_test(self):
sample_customer_xml = """

800004ED-1525972764
2018-03-24T00:31:04+05:00
2018-03-24T00:31:04+05:00
1525972764
Amazon
Amazon
true
Amazon

2305 Litton Ln




Hebron
Kentucky
41048
United States
Nice address


2305 Litton Ln




Hebron
Kentucky
41048
United States
Nice address

998909090909
998909090910
998909090911
[email protected]
Someone from Amazon
Some other one from Amazon

"""
sample_customer_data = dict(
ListID='800004ED-1525972764',
TimeCreated='2018-03-24T00:31:04+05:00',
TimeModified='2018-03-24T00:31:04+05:00',
EditSequence='1525972764',
Name='Amazon',
FullName='Amazon',
IsActive=True,
CompanyName='Amazon',
Phone='998909090909',
AltPhone='998909090910',
Fax='998909090911',
Email='[email protected]',
Contact='Someone from Amazon',
AltContact='Some other one from Amazon',
)
sample_address_data = dict(
Addr1='2305 Litton Ln',
City='Hebron',
State='Kentucky',
PostalCode='41048',
Country='United States',
Note='Nice address'
)
root_lxml = etree.fromstring(sample_customer_xml)
customer = Customer.from_lxml(root_lxml)
assert customer.ListID == sample_customer_data['ListID']
assert customer.TimeCreated == sample_customer_data['TimeCreated']
assert customer.TimeModified == sample_customer_data['TimeModified']
assert customer.EditSequence == sample_customer_data['EditSequence']
assert customer.Name == sample_customer_data['Name']
assert customer.FullName == sample_customer_data['FullName']
assert customer.IsActive == sample_customer_data['IsActive']
assert customer.CompanyName == sample_customer_data['CompanyName']
assert customer.Phone == sample_customer_data['Phone']
assert customer.AltPhone == sample_customer_data['AltPhone']
assert customer.Fax == sample_customer_data['Fax']
assert customer.Email == sample_customer_data['Email']
assert customer.Contact == sample_customer_data['Contact']
assert customer.AltContact == sample_customer_data['AltContact']

    # assert customer.BillAddress == BillAddress(**sample_address_data)
    # assert customer.ShipAddress == ShipAddress(**sample_address_data)

    from django_quickbooks.objects import Customer as QBCustomer
    # map your fields to the qbd_obj fields
    xx = QBCustomer(customer)
    # QBDTask.objects.create(qb_operation=QUICKBOOKS_ENUMS.OPP_ADD,
    #                        qb_resource=QUICKBOOKS_ENUMS.RESOURCE_CUSTOMER,
    #                        object_id=instance.id,
    #                        content_type=ContentType.objects.get_for_model(instance),
    #                        realm_id="6aea80599dad4469920d0d633b67d0f4",
    #
    #                        )
    xx = CustomerService.add(self, customer)
    if xx:
        return xx
    else:
        return xx

This is the code, try to run without sending object_id how can I add this in the queue manager

Is this project still active?

Hi - I'm looking for a tool to sync Quickbooks desktop data with MySQL. Is this project still active? Can it be used for this use case?
Thanks
Toby

queue_manager.py _get_connection function failing

When BlockingConnection is being called it is basically just timing out.
Is there additional setup that is not documented? I get that there is a link to formal documentation.
So is there more to what I need in order to get this working?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.