Initial commit
basic import from Wave API to cache tables for Customers, Invoices
This commit is contained in:
commit
00e2a9fcb2
20 changed files with 1101 additions and 0 deletions
rattail_wave/db
0
rattail_wave/db/__init__.py
Normal file
0
rattail_wave/db/__init__.py
Normal file
|
@ -0,0 +1,162 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
"""initial Wave cache tables
|
||||
|
||||
Revision ID: 6a20ed366981
|
||||
Revises: 7d009a925f21
|
||||
Create Date: 2022-09-02 13:27:36.945137
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '6a20ed366981'
|
||||
down_revision = None
|
||||
branch_labels = ('rattail_wave',)
|
||||
depends_on = None
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
import rattail.db.types
|
||||
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
||||
##############################
|
||||
# cache tables
|
||||
##############################
|
||||
|
||||
# wave_cache_customer
|
||||
op.create_table('wave_cache_customer',
|
||||
sa.Column('uuid', sa.String(length=32), nullable=False),
|
||||
sa.Column('id', sa.String(length=100), nullable=False),
|
||||
sa.Column('internal_id', sa.String(length=100), nullable=True),
|
||||
sa.Column('name', sa.String(length=255), nullable=True),
|
||||
sa.Column('email', sa.String(length=255), nullable=True),
|
||||
sa.Column('is_archived', sa.Boolean(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('modified_at', sa.DateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('uuid'),
|
||||
sa.UniqueConstraint('id', name='wave_cache_customer_uq_id')
|
||||
)
|
||||
op.create_table('wave_cache_customer_version',
|
||||
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
|
||||
sa.Column('id', sa.String(length=100), autoincrement=False, nullable=True),
|
||||
sa.Column('internal_id', sa.String(length=100), autoincrement=False, nullable=True),
|
||||
sa.Column('name', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('email', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('is_archived', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('modified_at', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
|
||||
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
|
||||
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('uuid', 'transaction_id')
|
||||
)
|
||||
op.create_index(op.f('ix_wave_cache_customer_version_end_transaction_id'), 'wave_cache_customer_version', ['end_transaction_id'], unique=False)
|
||||
op.create_index(op.f('ix_wave_cache_customer_version_operation_type'), 'wave_cache_customer_version', ['operation_type'], unique=False)
|
||||
op.create_index(op.f('ix_wave_cache_customer_version_transaction_id'), 'wave_cache_customer_version', ['transaction_id'], unique=False)
|
||||
|
||||
# wave_cache_invoice
|
||||
op.create_table('wave_cache_invoice',
|
||||
sa.Column('uuid', sa.String(length=32), nullable=False),
|
||||
sa.Column('id', sa.String(length=100), nullable=False),
|
||||
sa.Column('internal_id', sa.String(length=100), nullable=True),
|
||||
sa.Column('customer_id', sa.String(length=100), nullable=False),
|
||||
sa.Column('status', sa.String(length=10), nullable=False),
|
||||
sa.Column('title', sa.String(length=255), nullable=False),
|
||||
sa.Column('subhead', sa.String(length=255), nullable=True),
|
||||
sa.Column('invoice_number', sa.String(length=10), nullable=False),
|
||||
sa.Column('invoice_date', sa.Date(), nullable=False),
|
||||
sa.Column('due_date', sa.Date(), nullable=False),
|
||||
sa.Column('amount_due', sa.Numeric(precision=9, scale=2), nullable=False),
|
||||
sa.Column('amount_paid', sa.Numeric(precision=9, scale=2), nullable=False),
|
||||
sa.Column('tax_total', sa.Numeric(precision=9, scale=2), nullable=False),
|
||||
sa.Column('total', sa.Numeric(precision=9, scale=2), nullable=False),
|
||||
sa.Column('discount_total', sa.Numeric(precision=9, scale=2), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('modified_at', sa.DateTime(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['customer_id'], ['wave_cache_customer.id'], name='wave_cache_invoice_fk_customer'),
|
||||
sa.PrimaryKeyConstraint('uuid'),
|
||||
sa.UniqueConstraint('id', name='wave_cache_invoice_uq_id')
|
||||
)
|
||||
op.create_table('wave_cache_invoice_version',
|
||||
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
|
||||
sa.Column('id', sa.String(length=100), autoincrement=False, nullable=True),
|
||||
sa.Column('internal_id', sa.String(length=100), autoincrement=False, nullable=True),
|
||||
sa.Column('customer_id', sa.String(length=100), autoincrement=False, nullable=True),
|
||||
sa.Column('status', sa.String(length=10), autoincrement=False, nullable=True),
|
||||
sa.Column('title', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('subhead', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('invoice_number', sa.String(length=10), autoincrement=False, nullable=True),
|
||||
sa.Column('invoice_date', sa.Date(), autoincrement=False, nullable=True),
|
||||
sa.Column('due_date', sa.Date(), autoincrement=False, nullable=True),
|
||||
sa.Column('amount_due', sa.Numeric(precision=9, scale=2), autoincrement=False, nullable=True),
|
||||
sa.Column('amount_paid', sa.Numeric(precision=9, scale=2), autoincrement=False, nullable=True),
|
||||
sa.Column('tax_total', sa.Numeric(precision=9, scale=2), autoincrement=False, nullable=True),
|
||||
sa.Column('total', sa.Numeric(precision=9, scale=2), autoincrement=False, nullable=True),
|
||||
sa.Column('discount_total', sa.Numeric(precision=9, scale=2), autoincrement=False, nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('modified_at', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
|
||||
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
|
||||
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('uuid', 'transaction_id')
|
||||
)
|
||||
op.create_index(op.f('ix_wave_cache_invoice_version_end_transaction_id'), 'wave_cache_invoice_version', ['end_transaction_id'], unique=False)
|
||||
op.create_index(op.f('ix_wave_cache_invoice_version_operation_type'), 'wave_cache_invoice_version', ['operation_type'], unique=False)
|
||||
op.create_index(op.f('ix_wave_cache_invoice_version_transaction_id'), 'wave_cache_invoice_version', ['transaction_id'], unique=False)
|
||||
|
||||
##############################
|
||||
# integration tables
|
||||
##############################
|
||||
|
||||
# wave_customer
|
||||
op.create_table('wave_customer',
|
||||
sa.Column('uuid', sa.String(length=32), nullable=False),
|
||||
sa.Column('wave_id', sa.String(length=100), nullable=False),
|
||||
sa.ForeignKeyConstraint(['uuid'], ['customer.uuid'], name='wave_customer_fk_customer'),
|
||||
sa.PrimaryKeyConstraint('uuid')
|
||||
)
|
||||
op.create_table('wave_customer_version',
|
||||
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
|
||||
sa.Column('wave_id', sa.String(length=100), autoincrement=False, nullable=True),
|
||||
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
|
||||
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
|
||||
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('uuid', 'transaction_id')
|
||||
)
|
||||
op.create_index(op.f('ix_wave_customer_version_end_transaction_id'), 'wave_customer_version', ['end_transaction_id'], unique=False)
|
||||
op.create_index(op.f('ix_wave_customer_version_operation_type'), 'wave_customer_version', ['operation_type'], unique=False)
|
||||
op.create_index(op.f('ix_wave_customer_version_transaction_id'), 'wave_customer_version', ['transaction_id'], unique=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
##############################
|
||||
# integration tables
|
||||
##############################
|
||||
|
||||
# wave_customer
|
||||
op.drop_index(op.f('ix_wave_customer_version_transaction_id'), table_name='wave_customer_version')
|
||||
op.drop_index(op.f('ix_wave_customer_version_operation_type'), table_name='wave_customer_version')
|
||||
op.drop_index(op.f('ix_wave_customer_version_end_transaction_id'), table_name='wave_customer_version')
|
||||
op.drop_table('wave_customer_version')
|
||||
op.drop_table('wave_customer')
|
||||
|
||||
##############################
|
||||
# cache tables
|
||||
##############################
|
||||
|
||||
# wave_cache_invoice
|
||||
op.drop_index(op.f('ix_wave_cache_invoice_version_transaction_id'), table_name='wave_cache_invoice_version')
|
||||
op.drop_index(op.f('ix_wave_cache_invoice_version_operation_type'), table_name='wave_cache_invoice_version')
|
||||
op.drop_index(op.f('ix_wave_cache_invoice_version_end_transaction_id'), table_name='wave_cache_invoice_version')
|
||||
op.drop_table('wave_cache_invoice_version')
|
||||
op.drop_table('wave_cache_invoice')
|
||||
|
||||
# wave_cache_customer
|
||||
op.drop_index(op.f('ix_wave_cache_customer_version_transaction_id'), table_name='wave_cache_customer_version')
|
||||
op.drop_index(op.f('ix_wave_cache_customer_version_operation_type'), table_name='wave_cache_customer_version')
|
||||
op.drop_index(op.f('ix_wave_cache_customer_version_end_transaction_id'), table_name='wave_cache_customer_version')
|
||||
op.drop_table('wave_cache_customer_version')
|
||||
op.drop_table('wave_cache_customer')
|
29
rattail_wave/db/model/__init__.py
Normal file
29
rattail_wave/db/model/__init__.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
# Rattail is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
Wave integration data models
|
||||
"""
|
||||
|
||||
from .wave_cache import WaveCacheCustomer, WaveCacheInvoice
|
||||
|
||||
from .customers import WaveCustomer
|
66
rattail_wave/db/model/customers.py
Normal file
66
rattail_wave/db/model/customers.py
Normal file
|
@ -0,0 +1,66 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
# Rattail is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
Wave integration data models
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
from rattail.db import model
|
||||
|
||||
|
||||
class WaveCustomer(model.Base):
|
||||
"""
|
||||
Wave-specific extension to Customer model
|
||||
"""
|
||||
__tablename__ = 'wave_customer'
|
||||
__table_args__ = (
|
||||
sa.ForeignKeyConstraint(['uuid'], ['customer.uuid'],
|
||||
name='wave_customer_fk_customer'),
|
||||
)
|
||||
__versioned__ = {}
|
||||
|
||||
uuid = model.uuid_column(default=None)
|
||||
customer = orm.relationship(
|
||||
model.Customer,
|
||||
doc="""
|
||||
Reference to the actual customer record, which this one extends.
|
||||
""",
|
||||
backref=orm.backref(
|
||||
'_wave',
|
||||
uselist=False,
|
||||
cascade='all, delete-orphan',
|
||||
doc="""
|
||||
Reference to the Wave extension record for this customer.
|
||||
"""))
|
||||
|
||||
wave_id = sa.Column(sa.String(length=100), nullable=False, doc="""
|
||||
``id`` value for the customer, within Wave.
|
||||
""")
|
||||
|
||||
def __str__(self):
|
||||
return str(self.customer)
|
||||
|
||||
|
||||
WaveCustomer.make_proxy(model.Customer, '_wave', 'wave_id')
|
101
rattail_wave/db/model/wave_cache.py
Normal file
101
rattail_wave/db/model/wave_cache.py
Normal file
|
@ -0,0 +1,101 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
# Rattail is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
Wave "cache" data models
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
from rattail.db import model
|
||||
|
||||
|
||||
class WaveCacheCustomer(model.Base):
|
||||
"""
|
||||
Represents a customer record in Wave.
|
||||
|
||||
https://developer.waveapps.com/hc/en-us/articles/360019968212#customer
|
||||
"""
|
||||
__tablename__ = 'wave_cache_customer'
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('id', name='wave_cache_customer_uq_id'),
|
||||
)
|
||||
__versioned__ = {}
|
||||
model_title = "Wave Customer"
|
||||
|
||||
uuid = model.uuid_column()
|
||||
|
||||
id = sa.Column(sa.String(length=100), nullable=False)
|
||||
internal_id = sa.Column(sa.String(length=100), nullable=True)
|
||||
name = sa.Column(sa.String(length=255), nullable=True)
|
||||
email = sa.Column(sa.String(length=255), nullable=True)
|
||||
is_archived = sa.Column(sa.Boolean(), nullable=True)
|
||||
created_at = sa.Column(sa.DateTime(), nullable=True)
|
||||
modified_at = sa.Column(sa.DateTime(), nullable=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name or ""
|
||||
|
||||
|
||||
class WaveCacheInvoice(model.Base):
|
||||
"""
|
||||
Represents an invoice record in Wave.
|
||||
|
||||
https://developer.waveapps.com/hc/en-us/articles/360019968212#invoice
|
||||
"""
|
||||
__tablename__ = 'wave_cache_invoice'
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('id', name='wave_cache_invoice_uq_id'),
|
||||
sa.ForeignKeyConstraint(['customer_id'], ['wave_cache_customer.id'],
|
||||
name='wave_cache_invoice_fk_customer'),
|
||||
)
|
||||
__versioned__ = {}
|
||||
model_title = "Wave Invoice"
|
||||
|
||||
uuid = model.uuid_column()
|
||||
|
||||
id = sa.Column(sa.String(length=100), nullable=False)
|
||||
internal_id = sa.Column(sa.String(length=100), nullable=True)
|
||||
|
||||
customer_id = sa.Column(sa.String(length=100), nullable=False)
|
||||
customer = orm.relationship(WaveCacheCustomer,
|
||||
backref=orm.backref('invoices'))
|
||||
|
||||
status = sa.Column(sa.String(length=10), nullable=False)
|
||||
title = sa.Column(sa.String(length=255), nullable=False)
|
||||
subhead = sa.Column(sa.String(length=255), nullable=True)
|
||||
invoice_number = sa.Column(sa.String(length=10), nullable=False)
|
||||
invoice_date = sa.Column(sa.Date(), nullable=False)
|
||||
due_date = sa.Column(sa.Date(), nullable=False)
|
||||
amount_due = sa.Column(sa.Numeric(precision=9, scale=2), nullable=False)
|
||||
amount_paid = sa.Column(sa.Numeric(precision=9, scale=2), nullable=False)
|
||||
tax_total = sa.Column(sa.Numeric(precision=9, scale=2), nullable=False)
|
||||
total = sa.Column(sa.Numeric(precision=9, scale=2), nullable=False)
|
||||
discount_total = sa.Column(sa.Numeric(precision=9, scale=2), nullable=False)
|
||||
# currency_code = sa.Column(sa.String(length=3), nullable=False)
|
||||
# exchange_rate = sa.Column(sa.Numeric(precision=10, scale=5), nullable=False)
|
||||
created_at = sa.Column(sa.DateTime(), nullable=True)
|
||||
modified_at = sa.Column(sa.DateTime(), nullable=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.title or ""
|
Loading…
Add table
Add a link
Reference in a new issue