Add batch to update CORE member records directly via SQL

This commit is contained in:
Lance Edgar 2021-11-04 21:21:10 -05:00
parent 7522dd14cb
commit 5f1d6d76ed
5 changed files with 439 additions and 0 deletions

View file

@ -0,0 +1,91 @@
# -*- coding: utf-8; -*-
"""add corepos_member batch
Revision ID: 50961b4b854a
Revises: 7fea5aebddfb
Create Date: 2021-11-04 18:36:23.494783
"""
from __future__ import unicode_literals
# revision identifiers, used by Alembic.
revision = '50961b4b854a'
down_revision = '7fea5aebddfb'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
import rattail.db.types
def upgrade():
# batch_corepos_member
op.create_table('batch_corepos_member',
sa.Column('uuid', sa.String(length=32), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('description', sa.String(length=255), nullable=True),
sa.Column('created', sa.DateTime(), nullable=False),
sa.Column('created_by_uuid', sa.String(length=32), nullable=False),
sa.Column('cognized', sa.DateTime(), nullable=True),
sa.Column('cognized_by_uuid', sa.String(length=32), nullable=True),
sa.Column('rowcount', sa.Integer(), nullable=True),
sa.Column('complete', sa.Boolean(), nullable=False),
sa.Column('executed', sa.DateTime(), nullable=True),
sa.Column('executed_by_uuid', sa.String(length=32), nullable=True),
sa.Column('purge', sa.Date(), nullable=True),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('params', rattail.db.types.JSONTextDict(), nullable=True),
sa.Column('extra_data', sa.Text(), nullable=True),
sa.Column('status_code', sa.Integer(), nullable=True),
sa.Column('status_text', sa.String(length=255), nullable=True),
sa.Column('input_file', sa.String(length=255), nullable=True),
sa.ForeignKeyConstraint(['cognized_by_uuid'], ['user.uuid'], name='batch_corepos_member_fk_cognized_by'),
sa.ForeignKeyConstraint(['created_by_uuid'], ['user.uuid'], name='batch_corepos_member_fk_created_by'),
sa.ForeignKeyConstraint(['executed_by_uuid'], ['user.uuid'], name='batch_corepos_member_fk_executed_by'),
sa.PrimaryKeyConstraint('uuid')
)
# batch_corepos_member_row
op.create_table('batch_corepos_member_row',
sa.Column('uuid', sa.String(length=32), nullable=False),
sa.Column('batch_uuid', sa.String(length=32), nullable=False),
sa.Column('sequence', sa.Integer(), nullable=False),
sa.Column('status_code', sa.Integer(), nullable=True),
sa.Column('status_text', sa.String(length=255), nullable=True),
sa.Column('modified', sa.DateTime(), nullable=True),
sa.Column('removed', sa.Boolean(), nullable=False),
sa.Column('card_number', sa.Integer(), nullable=True),
sa.Column('first_name', sa.String(length=30), nullable=True),
sa.Column('first_name_old', sa.String(length=30), nullable=True),
sa.Column('last_name', sa.String(length=30), nullable=True),
sa.Column('last_name_old', sa.String(length=30), nullable=True),
sa.Column('street', sa.String(length=255), nullable=True),
sa.Column('street_old', sa.String(length=255), nullable=True),
sa.Column('city', sa.String(length=20), nullable=True),
sa.Column('city_old', sa.String(length=20), nullable=True),
sa.Column('state', sa.String(length=2), nullable=True),
sa.Column('state_old', sa.String(length=2), nullable=True),
sa.Column('zipcode', sa.String(length=10), nullable=True),
sa.Column('zipcode_old', sa.String(length=10), nullable=True),
sa.Column('phone', sa.String(length=30), nullable=True),
sa.Column('phone_old', sa.String(length=30), nullable=True),
sa.Column('email1', sa.String(length=50), nullable=True),
sa.Column('email1_old', sa.String(length=50), nullable=True),
sa.Column('email2', sa.String(length=50), nullable=True),
sa.Column('email2_old', sa.String(length=50), nullable=True),
sa.Column('member_type_id', sa.SmallInteger(), nullable=True),
sa.Column('member_type_id_old', sa.SmallInteger(), nullable=True),
sa.ForeignKeyConstraint(['batch_uuid'], ['batch_corepos_member.uuid'], name='batch_corepos_member_row_fk_batch_uuid'),
sa.PrimaryKeyConstraint('uuid')
)
def downgrade():
# batch_corepos_member*
op.drop_table('batch_corepos_member_row')
op.drop_table('batch_corepos_member')

View file

@ -28,3 +28,5 @@ from .stores import CoreStore
from .people import CorePerson, CoreCustomer, CoreMember
from .products import (CoreDepartment, CoreSubdepartment,
CoreVendor, CoreProduct, CoreProductCost)
from .batch.coremember import CoreMemberBatch, CoreMemberBatchRow

View file

@ -0,0 +1,98 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2021 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/>.
#
################################################################################
"""
Schema for CORE member update batch
"""
import sqlalchemy as sa
from rattail.db import model
from rattail.db.core import filename_column
class CoreMemberBatch(model.BatchMixin, model.Base):
"""
Hopefully generic batch for adding / updating member data in CORE.
"""
batch_key = 'corepos_member'
__tablename__ = 'batch_corepos_member'
__batchrow_class__ = 'CoreMemberBatchRow'
model_title = "CORE Member Batch"
model_title_plural = "CORE Member Batches"
STATUS_OK = 1
STATUS_CANNOT_PARSE_FILE = 2
STATUS = {
STATUS_OK : "ok",
STATUS_CANNOT_PARSE_FILE : "cannot parse file",
}
input_file = filename_column(nullable=True, doc="""
Base name of the input data file.
""")
class CoreMemberBatchRow(model.BatchRowMixin, model.Base):
"""
Row of data within a CORE member batch.
"""
__tablename__ = 'batch_corepos_member_row'
__batch_class__ = CoreMemberBatch
STATUS_NO_CHANGE = 1
STATUS_MEMBER_NOT_FOUND = 2
STATUS_FIELDS_CHANGED = 3
STATUS = {
STATUS_NO_CHANGE : "no change",
STATUS_MEMBER_NOT_FOUND : "member not found",
STATUS_FIELDS_CHANGED : "update member",
}
card_number = sa.Column(sa.Integer(), nullable=True)
first_name = sa.Column(sa.String(length=30), nullable=True)
first_name_old = sa.Column(sa.String(length=30), nullable=True)
last_name = sa.Column(sa.String(length=30), nullable=True)
last_name_old = sa.Column(sa.String(length=30), nullable=True)
street = sa.Column(sa.String(length=255), nullable=True)
street_old = sa.Column(sa.String(length=255), nullable=True)
city = sa.Column(sa.String(length=20), nullable=True)
city_old = sa.Column(sa.String(length=20), nullable=True)
state = sa.Column(sa.String(length=2), nullable=True)
state_old = sa.Column(sa.String(length=2), nullable=True)
zipcode = sa.Column(sa.String(length=10), nullable=True)
zipcode_old = sa.Column(sa.String(length=10), nullable=True)
phone = sa.Column(sa.String(length=30), nullable=True)
phone_old = sa.Column(sa.String(length=30), nullable=True)
email1 = sa.Column(sa.String(length=50), nullable=True)
email1_old = sa.Column(sa.String(length=50), nullable=True)
email2 = sa.Column(sa.String(length=50), nullable=True)
email2_old = sa.Column(sa.String(length=50), nullable=True)
member_type_id = sa.Column(sa.SmallInteger(), nullable=True)
member_type_id_old = sa.Column(sa.SmallInteger(), nullable=True)