Add CORE-specific datetime for equity payments

in case payments are added to CORE on a later date, want to keep
original timestamp separate
This commit is contained in:
Lance Edgar 2023-09-13 21:29:16 -05:00
parent c0cfc7714d
commit 60bc6dd236
5 changed files with 92 additions and 11 deletions

View file

@ -24,6 +24,8 @@
Handler for CORE equity import batches Handler for CORE equity import batches
""" """
import datetime
from corepos.db.office_trans import model as coretrans, Session as CoreTransSession from corepos.db.office_trans import model as coretrans, Session as CoreTransSession
from rattail.batch import BatchHandler from rattail.batch import BatchHandler
@ -104,25 +106,56 @@ class CoreEquityImportBatchHandler(BatchHandler):
self.export_payments_to_corepos(rows, progress=progress) self.export_payments_to_corepos(rows, progress=progress)
return True return True
def get_store_id(self, row):
# TODO: what should this be?
return 1
def get_register_number(self, row):
# TODO: what should this be?
return 1
def get_employee_number(self, row):
# TODO: what should this be?
return 0
def get_next_transaction_number(self, session):
# TODO: how should we generate this?
return self.consume_batch_id(session)
def get_next_timestamp(self, row):
dt = self.next_timestamp
self.next_timestamp += datetime.timedelta(seconds=1)
# import ipdb; ipdb.set_trace()
return self.app.localtime(dt, tzinfo=False).replace(microsecond=0)
def get_transaction_status(self, row):
# TODO: what should this be?
return 'G'
def export_payments_to_corepos(self, rows, progress=None): def export_payments_to_corepos(self, rows, progress=None):
coretrans_session = CoreTransSession() coretrans_session = CoreTransSession()
self.next_timestamp = self.app.localtime()
def export(row, i): def export(row, i):
session = self.app.get_session(row)
# will insert 2 records in `core_trans.dtransactions` ... # will insert 2 records in `core_trans.dtransactions` ...
# they will have this data in common # they will have this data in common
host_data = { host_data = {
'store_id': 1, # TODO: all "normal" txns have store_id=1 'store_id': self.get_store_id(row),
'register_number': 1, # TODO: what should this be? surely can't be empty 'register_number': self.get_register_number(row),
'transaction_number': 42, # TODO: how should we generate this? unique per register_no? 'transaction_number': self.get_next_transaction_number(session),
'date_time': self.app.localtime(row.timestamp, from_utc=True, tzinfo=False), 'employee_number': self.get_employee_number(row),
'card_number': row.card_number, 'card_number': row.card_number,
'date_time': self.get_next_timestamp(row),
'total': row.payment_amount, 'total': row.payment_amount,
'transaction_status': self.get_transaction_status(row),
} }
# first a record to ring up the equity item # first a record to ring up the equity item
detail = coretrans.TransactionDetail(**host_data) detail = coretrans.TransactionDetail(**host_data)
detail.transaction_id = 1
detail.upc = 'TEST_ITEM' # TODO: what should this say? detail.upc = 'TEST_ITEM' # TODO: what should this say?
detail.description = 'TEST_EQUITY_ITEM' # TODO: what should this say? detail.description = 'TEST_EQUITY_ITEM' # TODO: what should this say?
detail.department_number = row.department_number detail.department_number = row.department_number
@ -132,16 +165,24 @@ class CoreEquityImportBatchHandler(BatchHandler):
# then a record to accept tender payment # then a record to accept tender payment
detail = coretrans.TransactionDetail(**host_data) detail = coretrans.TransactionDetail(**host_data)
detail.transaction_id = 2
detail.upc = 'TEST_TENDER' # TODO: what should this say? detail.upc = 'TEST_TENDER' # TODO: what should this say?
detail.description = 'TEST_EQUITY_TENDER' # TODO: what should this say? detail.description = 'TEST_EQUITY_TENDER' # TODO: what should this say?
coretrans_session.add(detail) coretrans_session.add(detail)
# update payment in Rattail to indicate pending status in CORE # update payment in Rattail to indicate presence in CORE
payment = row.payment payment = row.payment
if payment: if payment:
# nb. these must match exactly to be used later as importer key
payment.corepos_card_number = row.card_number payment.corepos_card_number = row.card_number
payment.corepos_department_number = row.department_number payment.corepos_department_number = row.department_number
payment.corepos_transaction_number = 'pending' payment.corepos_transaction_number = f"{host_data['employee_number']}-{host_data['register_number']}-{host_data['transaction_number']}"
payment.corepos_transaction_id = 1
payment.corepos_datetime = self.app.make_utc(self.app.localtime(host_data['date_time']))
# TODO: stop setting these, *after* importer stops using for key
# (or perhaps config should determine whether to set?)
payment.received = payment.corepos_datetime
payment.transaction_identifier = payment.corepos_transaction_number
self.progress_loop(export, rows, progress, self.progress_loop(export, rows, progress,
message="Exporting payments to CORE-POS") message="Exporting payments to CORE-POS")

View file

@ -0,0 +1,33 @@
# -*- coding: utf-8; -*-
"""add equity_payment.corepos_datetime
Revision ID: d426a274f0c2
Revises: 93978a7adc66
Create Date: 2023-09-13 20:59:42.706994
"""
# revision identifiers, used by Alembic.
revision = 'd426a274f0c2'
down_revision = '93978a7adc66'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
import rattail.db.types
def upgrade():
# corepos_member_equity_payment
op.add_column('corepos_member_equity_payment', sa.Column('corepos_datetime', sa.DateTime(), nullable=True))
op.add_column('corepos_member_equity_payment_version', sa.Column('corepos_datetime', sa.DateTime(), autoincrement=False, nullable=True))
def downgrade():
# corepos_member_equity_payment
op.drop_column('corepos_member_equity_payment_version', 'corepos_datetime')
op.drop_column('corepos_member_equity_payment', 'corepos_datetime')

View file

@ -222,6 +222,10 @@ class CoreMemberEquityPayment(model.Base):
``stockpurchases.dept`` value for this payment, within CORE-POS. ``stockpurchases.dept`` value for this payment, within CORE-POS.
""") """)
corepos_datetime = sa.Column(sa.DateTime(), nullable=True, doc="""
``stockpurchases.datetime`` value for this payment, within CORE-POS.
""")
def __str__(self): def __str__(self):
return str(self.payment) return str(self.payment)
@ -229,3 +233,4 @@ CoreMemberEquityPayment.make_proxy(model.MemberEquityPayment, '_corepos', 'corep
CoreMemberEquityPayment.make_proxy(model.MemberEquityPayment, '_corepos', 'corepos_transaction_number') CoreMemberEquityPayment.make_proxy(model.MemberEquityPayment, '_corepos', 'corepos_transaction_number')
CoreMemberEquityPayment.make_proxy(model.MemberEquityPayment, '_corepos', 'corepos_transaction_id') CoreMemberEquityPayment.make_proxy(model.MemberEquityPayment, '_corepos', 'corepos_transaction_id')
CoreMemberEquityPayment.make_proxy(model.MemberEquityPayment, '_corepos', 'corepos_department_number') CoreMemberEquityPayment.make_proxy(model.MemberEquityPayment, '_corepos', 'corepos_department_number')
CoreMemberEquityPayment.make_proxy(model.MemberEquityPayment, '_corepos', 'corepos_datetime')

View file

@ -269,6 +269,7 @@ class MemberEquityPaymentImporter(FromCOREPOS, corepos_importing.model.MemberEqu
'corepos_transaction_number', 'corepos_transaction_number',
'corepos_transaction_id', 'corepos_transaction_id',
'corepos_department_number', 'corepos_department_number',
'corepos_datetime',
] ]
def setup(self): def setup(self):
@ -319,20 +320,20 @@ class MemberEquityPaymentImporter(FromCOREPOS, corepos_importing.model.MemberEqu
card_number, stock_purchase) card_number, stock_purchase)
return return
received = stock_purchase.datetime dt = stock_purchase.datetime
if received: if dt:
received = self.app.localtime(received) dt = self.app.make_utc(self.app.localtime(dt))
received = self.app.make_utc(received)
return { return {
'member_uuid': member.uuid, 'member_uuid': member.uuid,
'amount': stock_purchase.amount, 'amount': stock_purchase.amount,
'received': received, 'received': dt,
'transaction_identifier': stock_purchase.transaction_number, 'transaction_identifier': stock_purchase.transaction_number,
'corepos_card_number': stock_purchase.card_number, 'corepos_card_number': stock_purchase.card_number,
'corepos_transaction_number': stock_purchase.transaction_number, 'corepos_transaction_number': stock_purchase.transaction_number,
'corepos_transaction_id': stock_purchase.transaction_id, 'corepos_transaction_id': stock_purchase.transaction_id,
'corepos_department_number': stock_purchase.department_number, 'corepos_department_number': stock_purchase.department_number,
'corepos_datetime': dt,
} }
def create_object(self, key, host_data): def create_object(self, key, host_data):

View file

@ -90,6 +90,7 @@ class MemberEquityPaymentImporter(importing.model.MemberEquityPaymentImporter):
'corepos_transaction_number', 'corepos_transaction_number',
'corepos_transaction_id', 'corepos_transaction_id',
'corepos_department_number', 'corepos_department_number',
'corepos_datetime',
], ],
} }