def upload_view(self, request, extra_context=None): """Displays a form that can upload transactions form a Nordea "NDA" transaction file.""" # The revisionform view will check for change permission (via changeform_view), # but we also need to check for add permissions here. if not self.has_add_permission(request): # pragma: no cover raise PermissionDenied model = self.model opts = model._meta try: each_context = self.admin_site.each_context(request) except TypeError: # Django <= 1.7 pragma: no cover each_context = self.admin_site.each_context() # Get the rest of the context. context = dict( each_context, opts=opts, app_label=opts.app_label, module_name=capfirst(opts.verbose_name), title=_("Upload Nordea transactions"), transactions_handler=get_handler_instance('TRANSACTION_CALLBACKS_HANDLER') ) context.update(extra_context or {}) view = self.view_class.as_view() return view(request, context=context)
def import_transactions(self, transactions_handler=None): if transactions_handler is None: transactions_handler = get_handler_instance( 'TRANSACTION_CALLBACKS_HANDLER') transactions = [] for line in self.stream: nt = parseLine(line) if nt is not None: if transactions_handler: at = AbstractTransaction() at.name = str(nt.name) at.reference = str(nt.referenceNumber) at.amount = nt.amount # We know this is Decimal instance at.stamp = HELSINKI.fromutc( datetime.datetime.combine( nt.timestamp, datetime.datetime.min.time())) # DO NOT EVER CHANGE THIS, it must always and forever yield same unique_id for same transaction. at.unique_id = hashlib.sha1( str(nt.archiveID).encode('utf-8') + nt.timestamp.isoformat().encode('utf-8') + str(nt.referenceNumber).encode('utf-8')).hexdigest() ret = transactions_handler.import_transaction(at) if ret is not None: transactions.append(ret) else: transactions.append(nt) else: # Raise error ? AFAIK there should be no unparseable lines pass return transactions
def decorator(f): instance = get_handler_instance(setting) if not instance: return f @functools.wraps(f) def wrapper(*args, **kwargs): with transaction.atomic(): instance.on_saving(*args, **kwargs) r = f(*args, **kwargs) instance.on_saved(*args, **kwargs) return r return wrapper
def conditional_add_transaction(self, timescope=None): if not self.in_timescope(timescope): return False if self.transaction_exists(timescope): return False t = Transaction() if timescope: t.stamp = timescope h = get_handler_instance('RECURRINGTRANSACTIONS_CALLBACKS_HANDLER') t.tag = self.tag t.owner = self.owner uid_source = self.make_uid_source(timescope) t.unique_id = hashlib.sha1(uid_source.encode('UTF-8')).hexdigest() t.reference = uid_source t.amount = self.amount if h: if not h.on_creating(self, t): return False t.save() if h: h.on_created(self, t) return t
def conditional_add_transaction(self, timescope=None): if not self.in_timescope(timescope): return False if self.transaction_exists(timescope): return False t = Transaction() if timescope: t.stamp = timescope h = get_handler_instance('RECURRINGTRANSACTIONS_CALLBACKS_HANDLER') t.tag = self.tag t.owner = self.owner uid_source = self.make_uid_source(timescope) t.unique_id = hashlib.sha1(uid_source.encode('UTF-8')).hexdigest() t.reference = uid_source t.amount = self.amount if h: if not h.on_creating(self, t): return False t.save() if h: h.on_created(self, t) return t
def import_transactions(self, transactions_handler=None): if transactions_handler is None: transactions_handler = get_handler_instance('TRANSACTION_CALLBACKS_HANDLER') transactions = [] for obj in self.stream: atlist = None #print("DEBUG: processing %s with code %s" % (obj.__class__.__name__, obj.code)) if type(obj) is holviapi.Invoice: atlist = self.invoice2atlist(obj) if type(obj) is holviapi.Order: atlist = self.order2atlist(obj) if atlist is None: continue if transactions_handler: for at in atlist: ret = transactions_handler.import_transaction(at) if ret is not None: transactions.append(ret) else: transactions += atlist return transactions
def import_transactions(self, transactions_handler=None): if transactions_handler is None: transactions_handler = get_handler_instance('TRANSACTION_CALLBACKS_HANDLER') transactions = [] for line in self.stream: nt = parseLine(line) if nt is not None: if transactions_handler: at = AbstractTransaction() at.name = str(nt.name) at.reference = str(nt.referenceNumber) at.amount = nt.amount # We know this is Decimal instance at.stamp = HELSINKI.fromutc(datetime.datetime.combine(nt.timestamp, datetime.datetime.min.time())) # DO NOT EVER CHANGE THIS, it must always and forever yield same unique_id for same transaction. at.unique_id = hashlib.sha1(str(nt.archiveID).encode('utf-8') + nt.timestamp.isoformat().encode('utf-8') + str(nt.referenceNumber).encode('utf-8')).hexdigest() ret = transactions_handler.import_transaction(at) if ret is not None: transactions.append(ret) else: transactions.append(nt) else: # Raise error ? AFAIK there should be no unparseable lines pass return transactions
def import_transactions(self, transactions_handler=None): if transactions_handler is None: transactions_handler = get_handler_instance( 'TRANSACTION_CALLBACKS_HANDLER') transactions = [] for obj in self.stream: atlist = None #print("DEBUG: processing %s with code %s" % (obj.__class__.__name__, obj.code)) if type(obj) is holviapi.Invoice: atlist = self.invoice2atlist(obj) if type(obj) is holviapi.Order: atlist = self.order2atlist(obj) if atlist is None: continue if transactions_handler: for at in atlist: ret = transactions_handler.import_transaction(at) if ret is not None: transactions.append(ret) else: transactions += atlist return transactions