Add datasync watcher for trigger-populated "changes" table in CORE
This commit is contained in:
parent
caef131d7c
commit
6f03461114
|
@ -24,16 +24,46 @@
|
||||||
DataSync for CORE POS
|
DataSync for CORE POS
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals, absolute_import
|
from corepos.db.office_op import Session as CoreSession, model as corepos
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from corepos.db import Session as CoreSession, model as corepos
|
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
from rattail.datasync import DataSyncWatcher
|
from rattail.datasync import DataSyncWatcher
|
||||||
|
|
||||||
|
|
||||||
|
class CoreOfficeOpWatcher(DataSyncWatcher):
|
||||||
|
"""
|
||||||
|
DataSync watcher for the CORE ``office_op`` database.
|
||||||
|
"""
|
||||||
|
prunes_changes = True
|
||||||
|
|
||||||
|
def get_changes(self, lastrun):
|
||||||
|
session = CoreSession()
|
||||||
|
changes = session.query(corepos.Change).all()
|
||||||
|
session.expunge_all()
|
||||||
|
session.close()
|
||||||
|
if changes:
|
||||||
|
return [
|
||||||
|
(c.id,
|
||||||
|
model.DataSyncChange(
|
||||||
|
payload_type=c.object_type,
|
||||||
|
payload_key=c.object_key,
|
||||||
|
deletion=c.deleted))
|
||||||
|
for c in changes]
|
||||||
|
|
||||||
|
def prune_changes(self, keys):
|
||||||
|
deleted = 0
|
||||||
|
session = CoreSession()
|
||||||
|
for key in keys:
|
||||||
|
change = session.query(corepos.Change).get(key)
|
||||||
|
if change:
|
||||||
|
session.delete(change)
|
||||||
|
session.flush()
|
||||||
|
deleted += 1
|
||||||
|
session.commit()
|
||||||
|
session.close()
|
||||||
|
return deleted
|
||||||
|
|
||||||
|
|
||||||
class COREPOSProductWatcher(DataSyncWatcher):
|
class COREPOSProductWatcher(DataSyncWatcher):
|
||||||
"""
|
"""
|
||||||
DataSync watcher for the CORE POS database.
|
DataSync watcher for the CORE POS database.
|
||||||
|
@ -56,7 +86,7 @@ class COREPOSProductWatcher(DataSyncWatcher):
|
||||||
(None,
|
(None,
|
||||||
model.DataSyncChange(
|
model.DataSyncChange(
|
||||||
payload_type='Department',
|
payload_type='Department',
|
||||||
payload_key=six.text_type(dept.number)))
|
payload_key=str(dept.number)))
|
||||||
for dept in departments])
|
for dept in departments])
|
||||||
|
|
||||||
# TODO: subdepartment table doesn't have a modified flag?
|
# TODO: subdepartment table doesn't have a modified flag?
|
||||||
|
|
Loading…
Reference in a new issue