Add schema for mapping QB bank accounts to vendor+store combo

This commit is contained in:
Lance Edgar 2024-04-16 18:19:07 -05:00
parent 60139e75fc
commit 5ffd764edb
3 changed files with 102 additions and 3 deletions

View file

@ -0,0 +1,56 @@
# -*- coding: utf-8; -*-
"""add QuickbooksVendorBankAccount
Revision ID: 73ec806dc87b
Revises: 6a6791ac0961
Create Date: 2024-04-15 16:48:38.145370
"""
# revision identifiers, used by Alembic.
revision = '73ec806dc87b'
down_revision = '6a6791ac0961'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
import rattail.db.types
def upgrade():
# quickbooks_vendor_bank_account
op.create_table('quickbooks_vendor_bank_account',
sa.Column('uuid', sa.String(length=32), nullable=False),
sa.Column('vendor_uuid', sa.String(length=32), nullable=False),
sa.Column('store_uuid', sa.String(length=32), nullable=False),
sa.Column('account_number', sa.String(length=100), nullable=False),
sa.ForeignKeyConstraint(['store_uuid'], ['store.uuid'], name='quickbooks_vendor_bank_account_fk_store'),
sa.ForeignKeyConstraint(['vendor_uuid'], ['vendor.uuid'], name='quickbooks_vendor_bank_account_fk_vendor'),
sa.PrimaryKeyConstraint('uuid')
)
op.create_table('quickbooks_vendor_bank_account_version',
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
sa.Column('vendor_uuid', sa.String(length=32), autoincrement=False, nullable=True),
sa.Column('store_uuid', sa.String(length=32), autoincrement=False, nullable=True),
sa.Column('account_number', 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_quickbooks_vendor_bank_account_version_end_transaction_id'), 'quickbooks_vendor_bank_account_version', ['end_transaction_id'], unique=False)
op.create_index(op.f('ix_quickbooks_vendor_bank_account_version_operation_type'), 'quickbooks_vendor_bank_account_version', ['operation_type'], unique=False)
op.create_index(op.f('ix_quickbooks_vendor_bank_account_version_transaction_id'), 'quickbooks_vendor_bank_account_version', ['transaction_id'], unique=False)
def downgrade():
# quickbooks_vendor_bank_account
op.drop_index(op.f('ix_quickbooks_vendor_bank_account_version_transaction_id'), table_name='quickbooks_vendor_bank_account_version')
op.drop_index(op.f('ix_quickbooks_vendor_bank_account_version_operation_type'), table_name='quickbooks_vendor_bank_account_version')
op.drop_index(op.f('ix_quickbooks_vendor_bank_account_version_end_transaction_id'), table_name='quickbooks_vendor_bank_account_version')
op.drop_table('quickbooks_vendor_bank_account_version')
op.drop_table('quickbooks_vendor_bank_account')

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar # Copyright © 2010-2024 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -26,7 +26,7 @@ Quickbooks integration data models
from .stores import QuickbooksStore from .stores import QuickbooksStore
from .org import QuickbooksDepartment from .org import QuickbooksDepartment
from .vendors import QuickbooksVendor from .vendors import QuickbooksVendor, QuickbooksVendorBankAccount
from .invoices import (QuickbooksExportableInvoice, from .invoices import (QuickbooksExportableInvoice,
QuickbooksExportableInvoiceDistribution, QuickbooksExportableInvoiceDistribution,
QuickbooksInvoiceExport) QuickbooksInvoiceExport)

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar # Copyright © 2010-2024 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -26,6 +26,7 @@ Vendor data model extensions
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy import orm from sqlalchemy import orm
from sqlalchemy.orm.collections import attribute_mapped_collection
from rattail.db import model from rattail.db import model
@ -72,3 +73,45 @@ class QuickbooksVendor(model.Base):
QuickbooksVendor.make_proxy(model.Vendor, '_quickbooks', 'quickbooks_name') QuickbooksVendor.make_proxy(model.Vendor, '_quickbooks', 'quickbooks_name')
QuickbooksVendor.make_proxy(model.Vendor, '_quickbooks', 'quickbooks_bank_account') QuickbooksVendor.make_proxy(model.Vendor, '_quickbooks', 'quickbooks_bank_account')
QuickbooksVendor.make_proxy(model.Vendor, '_quickbooks', 'quickbooks_terms') QuickbooksVendor.make_proxy(model.Vendor, '_quickbooks', 'quickbooks_terms')
class QuickbooksVendorBankAccount(model.Base):
"""
Quickbooks bank account for vendor+store combo.
"""
__tablename__ = 'quickbooks_vendor_bank_account'
__table_args__ = (
sa.ForeignKeyConstraint(['vendor_uuid'], ['vendor.uuid'],
name='quickbooks_vendor_bank_account_fk_vendor'),
sa.ForeignKeyConstraint(['store_uuid'], ['store.uuid'],
name='quickbooks_vendor_bank_account_fk_store'),
)
__versioned__ = {}
uuid = model.uuid_column()
vendor_uuid = sa.Column(sa.String(length=32), nullable=False)
vendor = orm.relationship(
model.Vendor,
doc="""
Vendor to which this record pertains.
""",
backref=orm.backref(
'quickbooks_bank_accounts',
collection_class=attribute_mapped_collection('store_uuid'),
cascade='all, delete-orphan',
cascade_backrefs=False,
doc="""
Quickbooks bank account records.
"""))
store_uuid = sa.Column(sa.String(length=32), nullable=False)
store = orm.relationship(
model.Store,
doc="""
Store to which this record pertains.
""")
account_number = sa.Column(sa.String(length=100), nullable=False, doc="""
Quickbooks "bank account number" for the vendor+store combo.
""")