From cb6ed15eb8c162a9aa9a4c4644a8105a6d8fdc6b Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 11 Jan 2025 21:51:28 -0600 Subject: [PATCH 1/3] fix: add model for `MasterSuperDepartment` --- corepos/db/office_op/model.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/corepos/db/office_op/model.py b/corepos/db/office_op/model.py index 8590375..12688af 100644 --- a/corepos/db/office_op/model.py +++ b/corepos/db/office_op/model.py @@ -169,6 +169,25 @@ class Store(Base): return self.description or "" +class MasterSuperDepartment(Base): + """ + A department may belong to more than one superdepartment, but has + one "master" superdepartment. This avoids duplicating rows in + some reports. By convention, a department's "master" + superdepartment is the one with the lowest superID. + """ + __tablename__ = 'MasterSuperDepts' + + super_id = sa.Column('superID', sa.Integer(), primary_key=True, autoincrement=False, nullable=False) + + department_id = sa.Column('dept_ID', sa.Integer(), primary_key=True, autoincrement=False, nullable=False) + + super_name = sa.Column(sa.String(length=50), nullable=True) + + def __str__(self): + return self.super_name or "" + + class SuperDepartment(Base): """ Represents a "super" (parent/child) department mapping. From 464f107a88ed996dc5d627206f55a3d41fa453cf Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 11 Jan 2025 21:52:22 -0600 Subject: [PATCH 2/3] fix: add `MemberType.ignore_sales` column --- corepos/db/office_op/model.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/corepos/db/office_op/model.py b/corepos/db/office_op/model.py index 12688af..5e9a34a 100644 --- a/corepos/db/office_op/model.py +++ b/corepos/db/office_op/model.py @@ -1037,6 +1037,9 @@ class MemberType(Base): ssi = sa.Column(sa.Boolean(), nullable=True) + ignoreSales = sa.Column(sa.Boolean(), nullable=True, default=False) + ignore_sales = orm.synonym('ignoreSales') + # TODO: this was apparently added "recently" - isn't present in all DBs # (need to figure out how to conditionally include it in model?) # sales_code = sa.Column('salesCode', sa.Integer(), nullable=True) From 47c23a65aee63fa4018d3b66d6610a837e5aea8a Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 11 Jan 2025 21:55:54 -0600 Subject: [PATCH 3/3] 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