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:
parent
c0cfc7714d
commit
60bc6dd236
5 changed files with 92 additions and 11 deletions
|
@ -24,6 +24,8 @@
|
|||
Handler for CORE equity import batches
|
||||
"""
|
||||
|
||||
import datetime
|
||||
|
||||
from corepos.db.office_trans import model as coretrans, Session as CoreTransSession
|
||||
|
||||
from rattail.batch import BatchHandler
|
||||
|
@ -104,25 +106,56 @@ class CoreEquityImportBatchHandler(BatchHandler):
|
|||
self.export_payments_to_corepos(rows, progress=progress)
|
||||
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):
|
||||
coretrans_session = CoreTransSession()
|
||||
self.next_timestamp = self.app.localtime()
|
||||
|
||||
def export(row, i):
|
||||
session = self.app.get_session(row)
|
||||
|
||||
# will insert 2 records in `core_trans.dtransactions` ...
|
||||
|
||||
# they will have this data in common
|
||||
host_data = {
|
||||
'store_id': 1, # TODO: all "normal" txns have store_id=1
|
||||
'register_number': 1, # TODO: what should this be? surely can't be empty
|
||||
'transaction_number': 42, # TODO: how should we generate this? unique per register_no?
|
||||
'date_time': self.app.localtime(row.timestamp, from_utc=True, tzinfo=False),
|
||||
'store_id': self.get_store_id(row),
|
||||
'register_number': self.get_register_number(row),
|
||||
'transaction_number': self.get_next_transaction_number(session),
|
||||
'employee_number': self.get_employee_number(row),
|
||||
'card_number': row.card_number,
|
||||
'date_time': self.get_next_timestamp(row),
|
||||
'total': row.payment_amount,
|
||||
'transaction_status': self.get_transaction_status(row),
|
||||
}
|
||||
|
||||
# first a record to ring up the equity item
|
||||
detail = coretrans.TransactionDetail(**host_data)
|
||||
detail.transaction_id = 1
|
||||
detail.upc = 'TEST_ITEM' # TODO: what should this say?
|
||||
detail.description = 'TEST_EQUITY_ITEM' # TODO: what should this say?
|
||||
detail.department_number = row.department_number
|
||||
|
@ -132,16 +165,24 @@ class CoreEquityImportBatchHandler(BatchHandler):
|
|||
|
||||
# then a record to accept tender payment
|
||||
detail = coretrans.TransactionDetail(**host_data)
|
||||
detail.transaction_id = 2
|
||||
detail.upc = 'TEST_TENDER' # TODO: what should this say?
|
||||
detail.description = 'TEST_EQUITY_TENDER' # TODO: what should this say?
|
||||
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
|
||||
if payment:
|
||||
# nb. these must match exactly to be used later as importer key
|
||||
payment.corepos_card_number = row.card_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,
|
||||
message="Exporting payments to CORE-POS")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue