Add schema, logic for importing CORE VendorItem -> ProductCost

This commit is contained in:
Lance Edgar 2020-09-04 19:10:48 -05:00
parent b96a4bc7b9
commit 580f2093ae
5 changed files with 200 additions and 1 deletions

View file

@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
"""add corepos_product_cost
Revision ID: 130e4632a28a
Revises: 9c5029effe93
Create Date: 2020-09-04 18:30:17.041521
"""
# revision identifiers, used by Alembic.
revision = '130e4632a28a'
down_revision = '9c5029effe93'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
import rattail.db.types
def upgrade():
# corepos_product_cost
op.create_table('corepos_product_cost',
sa.Column('uuid', sa.String(length=32), nullable=False),
sa.Column('corepos_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['uuid'], ['product_cost.uuid'], name='corepos_product_cost_fk_cost'),
sa.PrimaryKeyConstraint('uuid')
)
op.create_table('corepos_product_cost_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_product_cost_version_end_transaction_id'), 'corepos_product_cost_version', ['end_transaction_id'], unique=False)
op.create_index(op.f('ix_corepos_product_cost_version_operation_type'), 'corepos_product_cost_version', ['operation_type'], unique=False)
op.create_index(op.f('ix_corepos_product_cost_version_transaction_id'), 'corepos_product_cost_version', ['transaction_id'], unique=False)
def downgrade():
# corepos_product_cost
op.drop_index(op.f('ix_corepos_product_cost_version_transaction_id'), table_name='corepos_product_cost_version')
op.drop_index(op.f('ix_corepos_product_cost_version_operation_type'), table_name='corepos_product_cost_version')
op.drop_index(op.f('ix_corepos_product_cost_version_end_transaction_id'), table_name='corepos_product_cost_version')
op.drop_table('corepos_product_cost_version')
op.drop_table('corepos_product_cost')

View file

@ -26,4 +26,4 @@ Database schema extensions for CORE-POS integration
from .people import CorePerson, CoreCustomer, CoreMember
from .products import (CoreDepartment, CoreSubdepartment,
CoreVendor, CoreProduct)
CoreVendor, CoreProduct, CoreProductCost)

View file

@ -168,3 +168,38 @@ class CoreProduct(model.Base):
return str(self.product)
CoreProduct.make_proxy(model.Product, '_corepos', 'corepos_id')
class CoreProductCost(model.Base):
"""
CORE-specific extensions to :class:`rattail:rattail.db.model.ProductCost`.
"""
__tablename__ = 'corepos_product_cost'
__table_args__ = (
sa.ForeignKeyConstraint(['uuid'], ['product_cost.uuid'],
name='corepos_product_cost_fk_cost'),
)
__versioned__ = {}
uuid = model.uuid_column(default=None)
cost = orm.relationship(
model.ProductCost,
doc="""
Reference to the actual ProductCost 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 product cost.
"""))
corepos_id = sa.Column(sa.Integer(), nullable=False, doc="""
``vendorItemID`` value for the corresponding record within CORE-POS.
""")
def __str__(self):
return str(self.cost)
CoreProductCost.make_proxy(model.ProductCost, '_corepos', 'corepos_id')