Add model, handler for CORE equity import batch
This commit is contained in:
parent
64048db92f
commit
ac34a494e3
107
rattail_corepos/batch/equityimport.py
Normal file
107
rattail_corepos/batch/equityimport.py
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
# -*- coding: utf-8; -*-
|
||||||
|
################################################################################
|
||||||
|
#
|
||||||
|
# Rattail -- Retail Software Framework
|
||||||
|
# Copyright © 2010-2023 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/>.
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
"""
|
||||||
|
Handler for CORE equity import batches
|
||||||
|
"""
|
||||||
|
|
||||||
|
from rattail.batch import BatchHandler
|
||||||
|
from rattail_corepos.db.model import CoreEquityImportBatch
|
||||||
|
|
||||||
|
|
||||||
|
class CoreEquityImportBatchHandler(BatchHandler):
|
||||||
|
"""
|
||||||
|
Handler for CORE member batches.
|
||||||
|
"""
|
||||||
|
batch_model_class = CoreEquityImportBatch
|
||||||
|
|
||||||
|
def refresh_row(self, row):
|
||||||
|
session = self.app.get_session(row)
|
||||||
|
model = self.model
|
||||||
|
|
||||||
|
if not row.card_number:
|
||||||
|
row.status_code = row.STATUS_MISSING_VALUES
|
||||||
|
row.status_text = "card_number"
|
||||||
|
return
|
||||||
|
|
||||||
|
if not row.payment_amount:
|
||||||
|
row.status_code = row.STATUS_MISSING_VALUES
|
||||||
|
row.status_text = "payment_amount"
|
||||||
|
return
|
||||||
|
|
||||||
|
if not row.department_number:
|
||||||
|
row.status_code = row.STATUS_MISSING_VALUES
|
||||||
|
row.status_text = "department_number"
|
||||||
|
return
|
||||||
|
|
||||||
|
if not row.timestamp:
|
||||||
|
row.status_code = row.STATUS_MISSING_VALUES
|
||||||
|
row.status_text = "timestamp"
|
||||||
|
return
|
||||||
|
|
||||||
|
payment = row.payment
|
||||||
|
member = payment.member if payment else None
|
||||||
|
row.member = member
|
||||||
|
if not member:
|
||||||
|
row.status_code = row.STATUS_MEMBER_NOT_FOUND
|
||||||
|
return
|
||||||
|
|
||||||
|
memtype = member.membership_type
|
||||||
|
row.member_type_id = memtype.number if memtype else None
|
||||||
|
|
||||||
|
if member.person:
|
||||||
|
person = member.person
|
||||||
|
row.first_name = person.first_name
|
||||||
|
row.last_name = person.last_name
|
||||||
|
|
||||||
|
membership = self.app.get_membership_handler()
|
||||||
|
row.rattail_equity_total = membership.get_equity_total(member)
|
||||||
|
|
||||||
|
row.status_code = row.STATUS_OK
|
||||||
|
|
||||||
|
def describe_execution(self, batch, **kwargs):
|
||||||
|
return "New payment transactions will be added directly to CORE-POS."
|
||||||
|
|
||||||
|
def get_effective_rows(self, batch):
|
||||||
|
return [row for row in batch.active_rows()
|
||||||
|
if row.status_code not in (row.STATUS_MISSING_VALUES,
|
||||||
|
row.STATUS_MEMBER_NOT_FOUND)]
|
||||||
|
|
||||||
|
def execute(self, batch, progress=None, **kwargs):
|
||||||
|
if self.config.production():
|
||||||
|
raise NotImplementedError("TODO: not yet implemented for production")
|
||||||
|
|
||||||
|
session = self.app.get_session(batch)
|
||||||
|
rows = self.get_effective_rows(batch)
|
||||||
|
|
||||||
|
def process(row, i):
|
||||||
|
payment = row.payment
|
||||||
|
if payment:
|
||||||
|
payment.corepos_card_number = row.card_number
|
||||||
|
payment.corepos_department_number = row.department_number
|
||||||
|
payment.corepos_transaction_number = 'pending'
|
||||||
|
if i % 200 == 0:
|
||||||
|
session.flush()
|
||||||
|
|
||||||
|
self.progress_loop(process, rows, progress,
|
||||||
|
message="Processing payments")
|
||||||
|
return True
|
|
@ -177,6 +177,10 @@ class RattailCOREPOSExtension(ConfigExtension):
|
||||||
config.setdefault('rattail.batch', 'corepos_member.handler.default',
|
config.setdefault('rattail.batch', 'corepos_member.handler.default',
|
||||||
'rattail_corepos.batch.coremember:CoreMemberBatchHandler')
|
'rattail_corepos.batch.coremember:CoreMemberBatchHandler')
|
||||||
|
|
||||||
|
# corepos_equity_import
|
||||||
|
config.setdefault('rattail.batch', 'corepos_equity_import.handler.default',
|
||||||
|
'rattail_corepos.batch.equityimport:CoreEquityImportBatchHandler')
|
||||||
|
|
||||||
|
|
||||||
def core_office_url(config, require=False, **kwargs):
|
def core_office_url(config, require=False, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
# -*- coding: utf-8; -*-
|
||||||
|
"""add equity import batch
|
||||||
|
|
||||||
|
Revision ID: 93978a7adc66
|
||||||
|
Revises: 08d879bbe118
|
||||||
|
Create Date: 2023-09-12 23:09:09.148879
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '93978a7adc66'
|
||||||
|
down_revision = '08d879bbe118'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
import rattail.db.types
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
|
||||||
|
# batch_corepos_equity_import
|
||||||
|
op.create_table('batch_corepos_equity_import',
|
||||||
|
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.ForeignKeyConstraint(['cognized_by_uuid'], ['user.uuid'], name='batch_corepos_equity_import_fk_cognized_by'),
|
||||||
|
sa.ForeignKeyConstraint(['created_by_uuid'], ['user.uuid'], name='batch_corepos_equity_import_fk_created_by'),
|
||||||
|
sa.ForeignKeyConstraint(['executed_by_uuid'], ['user.uuid'], name='batch_corepos_equity_import_fk_executed_by'),
|
||||||
|
sa.PrimaryKeyConstraint('uuid')
|
||||||
|
)
|
||||||
|
op.create_table('batch_corepos_equity_import_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('last_name', sa.String(length=30), nullable=True),
|
||||||
|
sa.Column('member_type_id', sa.Integer(), nullable=True),
|
||||||
|
sa.Column('payment_amount', sa.Numeric(precision=10, scale=2), nullable=True),
|
||||||
|
sa.Column('department_number', sa.Integer(), nullable=True),
|
||||||
|
sa.Column('timestamp', sa.DateTime(), nullable=True),
|
||||||
|
sa.Column('corepos_equity_total', sa.Numeric(precision=10, scale=2), nullable=True),
|
||||||
|
sa.Column('rattail_equity_total', sa.Numeric(precision=10, scale=2), nullable=True),
|
||||||
|
sa.Column('other_equity_total', sa.Numeric(precision=10, scale=2), nullable=True),
|
||||||
|
sa.Column('payment_uuid', sa.String(length=32), nullable=True),
|
||||||
|
sa.Column('member_uuid', sa.String(length=32), nullable=True),
|
||||||
|
sa.ForeignKeyConstraint(['batch_uuid'], ['batch_corepos_equity_import.uuid'], name='batch_corepos_equity_import_row_fk_batch_uuid'),
|
||||||
|
sa.ForeignKeyConstraint(['payment_uuid'], ['member_equity_payment.uuid'], name='batch_corepos_equity_import_row_fk_payment'),
|
||||||
|
sa.ForeignKeyConstraint(['member_uuid'], ['member.uuid'], name='batch_corepos_equity_import_row_fk_member'),
|
||||||
|
sa.PrimaryKeyConstraint('uuid')
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
|
||||||
|
# batch_corepos_equity_import
|
||||||
|
op.drop_table('batch_corepos_equity_import_row')
|
||||||
|
op.drop_table('batch_corepos_equity_import')
|
|
@ -31,3 +31,4 @@ from .products import (CoreDepartment, CoreSubdepartment,
|
||||||
CoreVendor, CoreProduct, CoreProductCost)
|
CoreVendor, CoreProduct, CoreProductCost)
|
||||||
|
|
||||||
from .batch.coremember import CoreMemberBatch, CoreMemberBatchRow
|
from .batch.coremember import CoreMemberBatch, CoreMemberBatchRow
|
||||||
|
from .batch.equityimport import CoreEquityImportBatch, CoreEquityImportBatchRow
|
||||||
|
|
94
rattail_corepos/db/model/batch/equityimport.py
Normal file
94
rattail_corepos/db/model/batch/equityimport.py
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
# -*- coding: utf-8; -*-
|
||||||
|
################################################################################
|
||||||
|
#
|
||||||
|
# Rattail -- Retail Software Framework
|
||||||
|
# Copyright © 2010-2023 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 equity import batch
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy import orm
|
||||||
|
from sqlalchemy.ext.declarative import declared_attr
|
||||||
|
|
||||||
|
from rattail.db import model
|
||||||
|
|
||||||
|
|
||||||
|
class CoreEquityImportBatch(model.BatchMixin, model.Base):
|
||||||
|
"""
|
||||||
|
Hopefully generic batch for CORE equity import
|
||||||
|
"""
|
||||||
|
batch_key = 'corepos_equity_import'
|
||||||
|
__tablename__ = 'batch_corepos_equity_import'
|
||||||
|
__batchrow_class__ = 'CoreEquityImportBatchRow'
|
||||||
|
model_title = "CORE-POS Equity Import Batch"
|
||||||
|
model_title_plural = "CORE-POS Equity Import Batches"
|
||||||
|
|
||||||
|
STATUS_OK = 1
|
||||||
|
|
||||||
|
STATUS = {
|
||||||
|
STATUS_OK : "ok",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class CoreEquityImportBatchRow(model.BatchRowMixin, model.Base):
|
||||||
|
"""
|
||||||
|
Row of data within a CORE equity import batch.
|
||||||
|
"""
|
||||||
|
__tablename__ = 'batch_corepos_equity_import_row'
|
||||||
|
__batch_class__ = CoreEquityImportBatch
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def __table_args__(cls):
|
||||||
|
return cls.__default_table_args__() + (
|
||||||
|
sa.ForeignKeyConstraint(['payment_uuid'], ['member_equity_payment.uuid'],
|
||||||
|
name='batch_corepos_equity_import_row_fk_payment'),
|
||||||
|
sa.ForeignKeyConstraint(['member_uuid'], ['member.uuid'],
|
||||||
|
name='batch_corepos_equity_import_row_fk_member'),
|
||||||
|
)
|
||||||
|
|
||||||
|
STATUS_OK = 1
|
||||||
|
STATUS_MEMBER_NOT_FOUND = 2
|
||||||
|
STATUS_MISSING_VALUES = 3
|
||||||
|
STATUS_NEEDS_ATTENTION = 4
|
||||||
|
|
||||||
|
STATUS = {
|
||||||
|
STATUS_OK : "ok",
|
||||||
|
STATUS_MEMBER_NOT_FOUND : "member not found",
|
||||||
|
STATUS_MISSING_VALUES : "missing values",
|
||||||
|
STATUS_NEEDS_ATTENTION : "needs attention",
|
||||||
|
}
|
||||||
|
|
||||||
|
payment_uuid = sa.Column(sa.String(length=32), nullable=True)
|
||||||
|
payment = orm.relationship(model.MemberEquityPayment)
|
||||||
|
|
||||||
|
member_uuid = sa.Column(sa.String(length=32), nullable=True)
|
||||||
|
member = orm.relationship(model.Member)
|
||||||
|
|
||||||
|
card_number = sa.Column(sa.Integer(), nullable=True)
|
||||||
|
first_name = sa.Column(sa.String(length=30), nullable=True)
|
||||||
|
last_name = sa.Column(sa.String(length=30), nullable=True)
|
||||||
|
member_type_id = sa.Column(sa.Integer(), nullable=True)
|
||||||
|
payment_amount = sa.Column(sa.Numeric(precision=10, scale=2), nullable=True)
|
||||||
|
department_number = sa.Column(sa.Integer(), nullable=True)
|
||||||
|
timestamp = sa.Column(sa.DateTime(), nullable=True)
|
||||||
|
corepos_equity_total = sa.Column(sa.Numeric(precision=10, scale=2), nullable=True)
|
||||||
|
rattail_equity_total = sa.Column(sa.Numeric(precision=10, scale=2), nullable=True)
|
||||||
|
other_equity_total = sa.Column(sa.Numeric(precision=10, scale=2), nullable=True)
|
Loading…
Reference in a new issue