From b7512e0b31e2918ff85f0f5f5bb56d80a986b8a4 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 22 Nov 2018 20:38:36 -0600 Subject: [PATCH] Add feature demo for importing Square transactions to CORE-POS also allow delete of CORE-POS transactions, for sake of demo --- .../corepos/transaction-details/index.mako | 11 ++++++++ rattail_demo/web/templates/menu.mako | 5 +++- rattail_demo/web/views/__init__.py | 1 + .../web/views/corepos/transactions.py | 27 +++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 rattail_demo/web/templates/corepos/transaction-details/index.mako diff --git a/rattail_demo/web/templates/corepos/transaction-details/index.mako b/rattail_demo/web/templates/corepos/transaction-details/index.mako new file mode 100644 index 0000000..c4dce82 --- /dev/null +++ b/rattail_demo/web/templates/corepos/transaction-details/index.mako @@ -0,0 +1,11 @@ +## -*- coding: utf-8; -*- +<%inherit file="/master/index.mako" /> + +<%def name="context_menu_items()"> + ${parent.context_menu_items()} + % if request.has_perm('{}.import_file'.format(permission_prefix)): +
  • ${h.link_to("Import {} from Square CSV".format(model_title_plural), url('{}.import_square'.format(route_prefix)))}
  • + % endif + + +${parent.body()} diff --git a/rattail_demo/web/templates/menu.mako b/rattail_demo/web/templates/menu.mako index 0f048b8..16833c4 100644 --- a/rattail_demo/web/templates/menu.mako +++ b/rattail_demo/web/templates/menu.mako @@ -97,7 +97,7 @@ % endif - % if request.has_any_perm('batch.handheld.list', 'batch.inventory.list'): + % if request.has_any_perm('batch.handheld.list', 'batch.inventory.list', 'batch.importer.list'):
  • Batches
  • % endif diff --git a/rattail_demo/web/views/__init__.py b/rattail_demo/web/views/__init__.py index d1dc8c7..f32d45f 100644 --- a/rattail_demo/web/views/__init__.py +++ b/rattail_demo/web/views/__init__.py @@ -41,3 +41,4 @@ def includeme(config): # batch views config.include('tailbone.views.handheld') config.include('tailbone.views.inventory') + config.include('tailbone.views.batch.importer') diff --git a/rattail_demo/web/views/corepos/transactions.py b/rattail_demo/web/views/corepos/transactions.py index 85ad24f..aa169b9 100644 --- a/rattail_demo/web/views/corepos/transactions.py +++ b/rattail_demo/web/views/corepos/transactions.py @@ -10,6 +10,8 @@ from corepos.trans.db import model as coretrans from .master import CoreMasterView from rattail_demo.web.db import CoreTransSession +from rattail_corepos.corepos.importing.square import FromSquareToCoreTrans + class TransactionDetailView(CoreMasterView): """ @@ -20,6 +22,9 @@ class TransactionDetailView(CoreMasterView): model_title = "CORE-POS Transaction Detail" url_prefix = '/corepos/transaction-details' route_prefix = 'corepos.transaction_details' + deletable = True + bulk_deletable = True + supports_import_batch_from_file = True labels = { 'store_row_id': "Store Row ID", @@ -43,6 +48,11 @@ class TransactionDetailView(CoreMasterView): 'total', ] + def get_bulk_delete_session(self): + from corepos.trans.db import Session as CoreTransSession + + return CoreTransSession() + def configure_grid(self, g): super(TransactionDetailView, self).configure_grid(g) @@ -71,6 +81,23 @@ class TransactionDetailView(CoreMasterView): f.set_type('discount', 'currency') f.set_type('total', 'currency') + def import_square(self): + return self.import_batch_from_file(FromSquareToCoreTrans, 'TransactionDetail', + importer_host_title="Square CSV") + + @classmethod + def defaults(cls, config): + route_prefix = cls.get_route_prefix() + url_prefix = cls.get_url_prefix() + permission_prefix = cls.get_permission_prefix() + + # import from square + config.add_route('{}.import_square'.format(route_prefix), '{}/import-square'.format(url_prefix)) + config.add_view(cls, attr='import_square', route_name='{}.import_square'.format(route_prefix), + permission='{}.import_file'.format(permission_prefix)) + + cls._defaults(config) + def includeme(config): TransactionDetailView.defaults(config)