Misc. tweaks to product-related schema, for sake of generating SQL

e.g. from IFPS data
This commit is contained in:
Lance Edgar 2020-12-09 13:09:58 -06:00
parent 29638c062c
commit ff428c4635

View file

@ -24,6 +24,7 @@
Data model for CORE POS "office_op" DB
"""
import datetime
import logging
import sqlalchemy as sa
@ -37,6 +38,23 @@ log = logging.getLogger(__name__)
Base = declarative_base()
class StringableDateTime(sa.TypeDecorator):
"""
Sort of a hack, to let us string-ify certain DateTime values when
generating "raw" SQL output.
cf. https://docs.sqlalchemy.org/en/14/faq/sqlexpressions.html#rendering-bound-parameters-inline
"""
impl = sa.DateTime
def process_literal_param(self, value, dialect):
if value is None:
return 'NULL'
if isinstance(value, datetime.datetime):
return "'{}'".format(value.strftime('%Y-%m-%d %H:%M:%S'))
raise NotImplementedError
class Change(Base):
"""
Represents a changed (or deleted) record, which is pending synchronization
@ -135,11 +153,11 @@ class Department(Base):
modified_by_id = sa.Column('modifiedby', sa.Integer(), nullable=True)
margin = sa.Column(sa.Float(), nullable=False, default=0)
margin = sa.Column(sa.Float(), nullable=False)
sales_code = sa.Column('salesCode', sa.Integer(), nullable=False, default=0)
sales_code = sa.Column('salesCode', sa.Integer(), nullable=False)
member_only = sa.Column('memberOnly', sa.SmallInteger(), nullable=False, default=0)
member_only = sa.Column('memberOnly', sa.SmallInteger(), nullable=False)
def __str__(self):
return self.name or ''
@ -488,6 +506,8 @@ class Product(Base):
mix_match_code = sa.Column('mixmatchcode', sa.String(length=13), nullable=True)
created = sa.Column(StringableDateTime(), nullable=True)
modified = sa.Column(sa.DateTime(), nullable=True)
# advertised = sa.Column(sa.Boolean(), nullable=True)
@ -649,7 +669,7 @@ class ProductUser(Base):
enable_online = sa.Column('enableOnline', sa.Boolean(), nullable=True)
sold_out = sa.Column('soldOut', sa.Boolean(), nullable=True, default=False)
sold_out = sa.Column('soldOut', sa.Boolean(), nullable=True)
# TODO: this was not in some older DBs
# sign_count = sa.Column('signCount', sa.SmallInteger(), nullable=True, default=1)
@ -657,6 +677,9 @@ class ProductUser(Base):
# TODO: this was not in some older DBs
# narrow = sa.Column(sa.Boolean(), nullable=True, default=False)
def __str__(self):
return str(self.product or '')
class VendorItem(Base):
"""