From 47c23a65aee63fa4018d3b66d6610a837e5aea8a Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 11 Jan 2025 21:55:54 -0600 Subject: [PATCH] fix: add base class for all transaction tables, views also rename some classes; add `dlogBig` for archive view --- corepos/db/office_arch/model.py | 19 +++++++++++++---- corepos/db/office_trans/model.py | 36 +++++++++++++++++++++++++------- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/corepos/db/office_arch/model.py b/corepos/db/office_arch/model.py index bf01a4d..49b0bbd 100644 --- a/corepos/db/office_arch/model.py +++ b/corepos/db/office_arch/model.py @@ -2,7 +2,7 @@ ################################################################################ # # pyCOREPOS -- Python Interface to CORE POS -# Copyright © 2018-2023 Lance Edgar +# Copyright © 2018-2024 Lance Edgar # # This file is part of pyCOREPOS. # @@ -26,14 +26,25 @@ CORE Office "arch" data model from sqlalchemy import orm -from corepos.db.office_trans.model import TransactionDetailBase +from corepos.db.office_trans.model import DTransactionBase, DLogBase Base = orm.declarative_base() -class TransactionDetail(TransactionDetailBase, Base): +class BigArchive(DTransactionBase, Base): """ - Represents a POS transaction detail record. + Represents a record from ``bigArchive`` table. """ __tablename__ = 'bigArchive' + + +# TODO: deprecate / remove this +TransactionDetail = BigArchive + + +class DLogBig(DLogBase, Base): + """ + Represents a record from ``dlogBig`` view. + """ + __tablename__ = 'dlogBig' diff --git a/corepos/db/office_trans/model.py b/corepos/db/office_trans/model.py index 2848af5..b4659cd 100644 --- a/corepos/db/office_trans/model.py +++ b/corepos/db/office_trans/model.py @@ -2,7 +2,7 @@ ################################################################################ # # pyCOREPOS -- Python Interface to CORE POS -# Copyright © 2018-2023 Lance Edgar +# Copyright © 2018-2024 Lance Edgar # # This file is part of pyCOREPOS. # @@ -68,7 +68,7 @@ class EquityLiveBalance(Base): start_date = sa.Column('startdate', sa.DateTime(), nullable=True) -class TransactionDetailBase(object): +class TransactionDetailBase: """ Represents a POS transaction detail record. """ @@ -86,10 +86,12 @@ class TransactionDetailBase(object): transaction_number = sa.Column('trans_no', sa.Integer(), nullable=True) transaction_type = sa.Column('trans_type', sa.String(length=1), nullable=True) transaction_subtype = sa.Column('trans_subtype', sa.String(length=2), nullable=True) - transaction_status = sa.Column('trans_status', sa.String(length=1), nullable=True) - # timestamps - date_time = sa.Column('datetime', sa.DateTime(), nullable=True) + trans_status = sa.Column(sa.String(length=1), nullable=True) + + @declared_attr + def transaction_status(self): + return orm.synonym('trans_status') # cashier employee_number = sa.Column('emp_no', sa.Integer(), nullable=True) @@ -115,7 +117,11 @@ class TransactionDetailBase(object): cost = sa.Column(sa.Numeric(precision=10, scale=2), nullable=True) - unit_price = sa.Column('unitPrice', sa.Numeric(precision=10, scale=2), nullable=True) + unitPrice = sa.Column('unitPrice', sa.Numeric(precision=10, scale=2), nullable=True) + + @declared_attr + def unit_price(self): + return orm.synonym('unitPrice') total = sa.Column(sa.Numeric(precision=10, scale=2), nullable=True) @@ -161,8 +167,22 @@ class TransactionDetailBase(object): return self.description or '' -class TransactionDetail(TransactionDetailBase, Base): +class DTransactionBase(TransactionDetailBase): + + date_time = sa.Column('datetime', sa.DateTime(), nullable=True) + + +class DLogBase(TransactionDetailBase): + + date_time = sa.Column('tdate', sa.DateTime(), nullable=True) + + +class DTransaction(DTransactionBase, Base): """ - Represents a POS transaction detail record. + Represents a record from ``dtransactions`` table. """ __tablename__ = 'dtransactions' + + +# TODO: deprecate / remove this +TransactionDetail = DTransaction