Add tender importer from CORE; apply tender in CORE POS batch

still some work to be done yet but getting there
This commit is contained in:
Lance Edgar 2023-09-27 17:14:28 -05:00
parent 3add006b7e
commit f61ae7a7e0
6 changed files with 132 additions and 2 deletions

View file

@ -81,6 +81,10 @@ class POSBatchHandler(base.POSBatchHandler):
d = self.make_d_customer(row) d = self.make_d_customer(row)
dtransactions.append(d) dtransactions.append(d)
elif row.row_type == 'tender':
d = self.make_d_tender(row)
dtransactions.append(d)
self.progress_loop(add, rows, progress, self.progress_loop(add, rows, progress,
message="Normalizing items for CORE-POS transaction") message="Normalizing items for CORE-POS transaction")
@ -131,8 +135,9 @@ class POSBatchHandler(base.POSBatchHandler):
def make_d_item(self, row): def make_d_item(self, row):
batch = row.batch batch = row.batch
d = self.make_d_basic(batch, row) d = self.make_d_basic(batch, row)
d.transaction_type = 'I'
d.upc = row.product.item_id d.upc = row.product.item_id
d.department_number = row.department_number
d.description = row.product.description d.description = row.product.description
if d.description and len(d.description) > self.maxlen_description: if d.description and len(d.description) > self.maxlen_description:
@ -146,3 +151,12 @@ class POSBatchHandler(base.POSBatchHandler):
d.total = row.sales_total d.total = row.sales_total
# d.voided = False # TODO # d.voided = False # TODO
return d return d
def make_d_tender(self, row):
batch = row.batch
d = self.make_d_basic(batch, row)
d.transaction_type = 'T'
d.transaction_subtype = row.item_entry
d.description = row.description
d.total = row.tender_total
return d

View file

@ -0,0 +1,51 @@
# -*- coding: utf-8; -*-
"""add tender
Revision ID: c40a6ec00428
Revises: f8df04546a59
Create Date: 2023-09-26 18:22:17.804658
"""
# revision identifiers, used by Alembic.
revision = 'c40a6ec00428'
down_revision = 'f8df04546a59'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
import rattail.db.types
def upgrade():
# corepos_tender
op.create_table('corepos_tender',
sa.Column('uuid', sa.String(length=32), nullable=False),
sa.Column('corepos_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['uuid'], ['tender.uuid'], name='corepos_tender_fk_tender'),
sa.PrimaryKeyConstraint('uuid')
)
op.create_table('corepos_tender_version',
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
sa.Column('corepos_id', sa.Integer(), autoincrement=False, nullable=True),
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint('uuid', 'transaction_id')
)
op.create_index(op.f('ix_corepos_tender_version_end_transaction_id'), 'corepos_tender_version', ['end_transaction_id'], unique=False)
op.create_index(op.f('ix_corepos_tender_version_operation_type'), 'corepos_tender_version', ['operation_type'], unique=False)
op.create_index(op.f('ix_corepos_tender_version_transaction_id'), 'corepos_tender_version', ['transaction_id'], unique=False)
def downgrade():
# corepos_tender
op.drop_table('corepos_tender')
op.drop_index(op.f('ix_corepos_tender_version_transaction_id'), table_name='corepos_tender_version')
op.drop_index(op.f('ix_corepos_tender_version_operation_type'), table_name='corepos_tender_version')
op.drop_index(op.f('ix_corepos_tender_version_end_transaction_id'), table_name='corepos_tender_version')
op.drop_table('corepos_tender_version')

View file

@ -24,7 +24,7 @@
Database schema extensions for CORE-POS integration Database schema extensions for CORE-POS integration
""" """
from .stores import CoreStore from .stores import CoreStore, CoreTender
from .people import (CorePerson, CoreCustomer, CoreCustomerShopper, from .people import (CorePerson, CoreCustomer, CoreCustomerShopper,
CoreMember, CoreMemberEquityPayment) CoreMember, CoreMemberEquityPayment)
from .products import (CoreDepartment, CoreSubdepartment, from .products import (CoreDepartment, CoreSubdepartment,

View file

@ -63,3 +63,38 @@ class CoreStore(model.Base):
return str(self.store) return str(self.store)
CoreStore.make_proxy(model.Store, '_corepos', 'corepos_id') CoreStore.make_proxy(model.Store, '_corepos', 'corepos_id')
class CoreTender(model.Base):
"""
CORE-specific extensions to :class:`rattail:rattail.db.model.Tender`.
"""
__tablename__ = 'corepos_tender'
__table_args__ = (
sa.ForeignKeyConstraint(['uuid'], ['tender.uuid'],
name='corepos_tender_fk_tender'),
)
__versioned__ = {}
uuid = model.uuid_column(default=None)
tender = orm.relationship(
model.Tender,
doc="""
Reference to the actual tender record, which this one extends.
""",
backref=orm.backref(
'_corepos',
uselist=False,
cascade='all, delete-orphan',
doc="""
Reference to the CORE-POS extension record for this tender.
"""))
corepos_id = sa.Column(sa.Integer(), nullable=False, doc="""
``tenders.TenderID`` value for this tender, within CORE-POS.
""")
def __str__(self):
return str(self.tender)
CoreTender.make_proxy(model.Tender, '_corepos', 'corepos_id')

View file

@ -65,6 +65,7 @@ class FromCOREPOSToRattail(importing.FromSQLAlchemyHandler, importing.ToRattailH
def get_importers(self): def get_importers(self):
importers = OrderedDict() importers = OrderedDict()
importers['Tender'] = TenderImporter
importers['Vendor'] = VendorImporter importers['Vendor'] = VendorImporter
importers['Department'] = DepartmentImporter importers['Department'] = DepartmentImporter
importers['Subdepartment'] = SubdepartmentImporter importers['Subdepartment'] = SubdepartmentImporter
@ -87,6 +88,26 @@ class FromCOREPOS(importing.FromSQLAlchemy):
""" """
class TenderImporter(FromCOREPOS, corepos_importing.model.TenderImporter):
"""
Importer for tender data from CORE POS.
"""
host_model_class = corepos.Tender
key = 'corepos_id'
supported_fields = [
'corepos_id',
'code',
'name',
]
def normalize_host_object(self, tender):
return {
'corepos_id': tender.tender_id,
'code': tender.tender_code,
'name': tender.tender_name,
}
class VendorImporter(FromCOREPOS, corepos_importing.model.VendorImporter): class VendorImporter(FromCOREPOS, corepos_importing.model.VendorImporter):
""" """
Importer for vendor data from CORE POS. Importer for vendor data from CORE POS.

View file

@ -122,6 +122,15 @@ class SubdepartmentImporter(importing.model.SubdepartmentImporter):
} }
class TenderImporter(importing.model.TenderImporter):
extensions = {
'_corepos': [
'corepos_id',
],
}
class VendorImporter(importing.model.VendorImporter): class VendorImporter(importing.model.VendorImporter):
extensions = { extensions = {