Add importer for tax rates from CORE

This commit is contained in:
Lance Edgar 2023-10-07 16:28:12 -05:00
parent 6ef2e67f76
commit cf90ca5704
5 changed files with 122 additions and 1 deletions

View file

@ -0,0 +1,51 @@
# -*- coding: utf-8; -*-
"""add corepos_tax
Revision ID: 673ff7088d35
Revises: 1f2e2f57c90b
Create Date: 2023-10-06 21:01:01.105790
"""
# revision identifiers, used by Alembic.
revision = '673ff7088d35'
down_revision = '1f2e2f57c90b'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
import rattail.db.types
def upgrade():
# corepos_tax
op.create_table('corepos_tax',
sa.Column('uuid', sa.String(length=32), nullable=False),
sa.Column('corepos_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['uuid'], ['tax.uuid'], name='corepos_tax_fk_tax'),
sa.PrimaryKeyConstraint('uuid')
)
op.create_table('corepos_tax_version',
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
sa.Column('corepos_id', sa.Integer(), 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_corepos_tax_version_end_transaction_id'), 'corepos_tax_version', ['end_transaction_id'], unique=False)
op.create_index(op.f('ix_corepos_tax_version_operation_type'), 'corepos_tax_version', ['operation_type'], unique=False)
op.create_index(op.f('ix_corepos_tax_version_transaction_id'), 'corepos_tax_version', ['transaction_id'], unique=False)
def downgrade():
# corepos_tax
op.drop_index(op.f('ix_corepos_tax_version_transaction_id'), table_name='corepos_tax_version')
op.drop_index(op.f('ix_corepos_tax_version_operation_type'), table_name='corepos_tax_version')
op.drop_index(op.f('ix_corepos_tax_version_end_transaction_id'), table_name='corepos_tax_version')
op.drop_table('corepos_tax_version')
op.drop_table('corepos_tax')

View file

@ -24,7 +24,7 @@
Database schema extensions for CORE-POS integration
"""
from .stores import CoreStore, CoreTender
from .stores import CoreStore, CoreTax, CoreTender
from .people import (CorePerson, CoreEmployee,
CoreCustomer, CoreCustomerShopper,
CoreMember, CoreMemberEquityPayment)

View file

@ -65,6 +65,41 @@ class CoreStore(model.Base):
CoreStore.make_proxy(model.Store, '_corepos', 'corepos_id')
class CoreTax(model.Base):
"""
CORE-specific extensions to :class:`rattail:rattail.db.model.Tax`.
"""
__tablename__ = 'corepos_tax'
__table_args__ = (
sa.ForeignKeyConstraint(['uuid'], ['tax.uuid'],
name='corepos_tax_fk_tax'),
)
__versioned__ = {}
uuid = model.uuid_column(default=None)
tax = orm.relationship(
model.Tax,
doc="""
Reference to the actual tax record, which this one extends.
""",
backref=orm.backref(
'_corepos',
uselist=False,
cascade='all, delete-orphan',
doc="""
Reference to the CORE-POS extension record for this tax.
"""))
corepos_id = sa.Column(sa.Integer(), nullable=False, doc="""
``taxrates.id`` value for this tax, within CORE-POS.
""")
def __str__(self):
return str(self.tax)
CoreTax.make_proxy(model.Tax, '_corepos', 'corepos_id')
class CoreTender(model.Base):
"""
CORE-specific extensions to :class:`rattail:rattail.db.model.Tender`.