Update usage of short_session()
per upstream changes
This commit is contained in:
parent
7eb7c25172
commit
63a1172408
4 changed files with 15 additions and 14 deletions
|
@ -30,22 +30,23 @@ import sqlalchemy as sa
|
|||
|
||||
from corepos.db.office_op import Session as CoreSession, model as corepos
|
||||
|
||||
from rattail.db.util import short_session
|
||||
from rattail.util import OrderedDict, progress_loop
|
||||
from rattail.util import OrderedDict
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_core_members(api, progress=None):
|
||||
def get_core_members(config, api, progress=None):
|
||||
"""
|
||||
Shared logic for fetching *all* customer accounts from CORE-POS API.
|
||||
"""
|
||||
app = config.get_app()
|
||||
|
||||
# TODO: ideally could do this, but API doesn't let us fetch "all"
|
||||
# return api.get_members()
|
||||
|
||||
# first we fetch all customer records from CORE DB
|
||||
with short_session(Session=CoreSession) as s:
|
||||
with app.short_session(factory=CoreSession) as s:
|
||||
db_customers = s.query(corepos.CustData).all()
|
||||
s.expunge_all()
|
||||
|
||||
|
@ -63,16 +64,17 @@ def get_core_members(api, progress=None):
|
|||
logger("could not fetch member from CORE API: %s",
|
||||
dbcust.card_number)
|
||||
|
||||
progress_loop(fetch, db_customers, progress,
|
||||
message="Fetching Member data from CORE API")
|
||||
app.progress_loop(fetch, db_customers, progress,
|
||||
message="Fetching Member data from CORE API")
|
||||
return list(members.values())
|
||||
|
||||
|
||||
def get_max_existing_vendor_id(session=None):
|
||||
def get_max_existing_vendor_id(config, session=None):
|
||||
"""
|
||||
Returns the "last" (max) existing value for the ``vendors.vendorID``
|
||||
column, for use when creating new records, since it is not auto-increment.
|
||||
"""
|
||||
with short_session(Session=CoreSession, session=session) as s:
|
||||
app = config.get_app()
|
||||
with app.short_session(factory=CoreSession, session=session) as s:
|
||||
return s.query(sa.func.max(corepos.Vendor.id))\
|
||||
.scalar() or 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue