Oerhaul the Vendor import/export between Rattail and CORE
also, add new DB schema specific to this integration, to hold PKs etc.
This commit is contained in:
		
							parent
							
								
									f9071ac6e9
								
							
						
					
					
						commit
						af1e38aa18
					
				
					 10 changed files with 311 additions and 30 deletions
				
			
		| 
						 | 
				
			
			@ -0,0 +1,51 @@
 | 
			
		|||
# -*- coding: utf-8 -*-
 | 
			
		||||
"""initial CORE-POS integration tables
 | 
			
		||||
 | 
			
		||||
Revision ID: b43e93d32275
 | 
			
		||||
Revises: dfc1ed686f3f
 | 
			
		||||
Create Date: 2020-03-04 14:21:23.625568
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
# revision identifiers, used by Alembic.
 | 
			
		||||
revision = 'b43e93d32275'
 | 
			
		||||
down_revision = None
 | 
			
		||||
branch_labels = ('rattail_corepos',)
 | 
			
		||||
depends_on = None
 | 
			
		||||
 | 
			
		||||
from alembic import op
 | 
			
		||||
import sqlalchemy as sa
 | 
			
		||||
import rattail.db.types
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def upgrade():
 | 
			
		||||
 | 
			
		||||
    # corepos_vendor
 | 
			
		||||
    op.create_table('corepos_vendor',
 | 
			
		||||
                    sa.Column('uuid', sa.String(length=32), nullable=False),
 | 
			
		||||
                    sa.Column('corepos_id', sa.Integer(), nullable=False),
 | 
			
		||||
                    sa.ForeignKeyConstraint(['uuid'], ['vendor.uuid'], name='corepos_vendor_fk_vendor'),
 | 
			
		||||
                    sa.PrimaryKeyConstraint('uuid')
 | 
			
		||||
    )
 | 
			
		||||
    op.create_table('corepos_vendor_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_vendor_version_end_transaction_id'), 'corepos_vendor_version', ['end_transaction_id'], unique=False)
 | 
			
		||||
    op.create_index(op.f('ix_corepos_vendor_version_operation_type'), 'corepos_vendor_version', ['operation_type'], unique=False)
 | 
			
		||||
    op.create_index(op.f('ix_corepos_vendor_version_transaction_id'), 'corepos_vendor_version', ['transaction_id'], unique=False)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def downgrade():
 | 
			
		||||
 | 
			
		||||
    # corepos_vendor
 | 
			
		||||
    op.drop_index(op.f('ix_corepos_vendor_version_transaction_id'), table_name='corepos_vendor_version')
 | 
			
		||||
    op.drop_index(op.f('ix_corepos_vendor_version_operation_type'), table_name='corepos_vendor_version')
 | 
			
		||||
    op.drop_index(op.f('ix_corepos_vendor_version_end_transaction_id'), table_name='corepos_vendor_version')
 | 
			
		||||
    op.drop_table('corepos_vendor_version')
 | 
			
		||||
    op.drop_table('corepos_vendor')
 | 
			
		||||
							
								
								
									
										68
									
								
								rattail_corepos/db/model.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								rattail_corepos/db/model.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,68 @@
 | 
			
		|||
# -*- coding: utf-8; -*-
 | 
			
		||||
################################################################################
 | 
			
		||||
#
 | 
			
		||||
#  Rattail -- Retail Software Framework
 | 
			
		||||
#  Copyright © 2010-2020 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/>.
 | 
			
		||||
#
 | 
			
		||||
################################################################################
 | 
			
		||||
"""
 | 
			
		||||
Database schema extensions for CORE-POS integration
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
import sqlalchemy as sa
 | 
			
		||||
from sqlalchemy import orm
 | 
			
		||||
 | 
			
		||||
from rattail.db import model
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
__all__ = ['CoreVendor']
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CoreVendor(model.Base):
 | 
			
		||||
    """
 | 
			
		||||
    CORE-specific extensions to :class:`rattail:rattail.db.model.Vendor`.
 | 
			
		||||
    """
 | 
			
		||||
    __tablename__ = 'corepos_vendor'
 | 
			
		||||
    __table_args__ = (
 | 
			
		||||
        sa.ForeignKeyConstraint(['uuid'], ['vendor.uuid'],
 | 
			
		||||
                                name='corepos_vendor_fk_vendor'),
 | 
			
		||||
    )
 | 
			
		||||
    __versioned__ = {}
 | 
			
		||||
 | 
			
		||||
    uuid = model.uuid_column(default=None)
 | 
			
		||||
    vendor = orm.relationship(
 | 
			
		||||
        model.Vendor,
 | 
			
		||||
        doc="""
 | 
			
		||||
        Reference to the actual vendor 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 vendor.
 | 
			
		||||
            """))
 | 
			
		||||
 | 
			
		||||
    corepos_id = sa.Column(sa.Integer(), nullable=False, doc="""
 | 
			
		||||
    ``vendorID`` value for the vendor, within CORE-POS.
 | 
			
		||||
    """)
 | 
			
		||||
 | 
			
		||||
    def __str__(self):
 | 
			
		||||
        return str(self.vendor)
 | 
			
		||||
 | 
			
		||||
CoreVendor.make_proxy(model.Vendor, '_corepos', 'corepos_id')
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue