示例#1
0
 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
示例#2
0
 def order2atlist(self, o):
     if not o.paid:
         return None
     at = AbstractTransaction()
     at.holvi_order = o  # nonstandard field, but ought to be helpful
     at.name = "%s, %s" % (o.buyer.lastname, o.buyer.firstname)
     at.email = str(o.buyer.email)
     at.stamp = o.paid_time  # this is already parsed by holviapi
     at.amount = o.net
     at.reference = "holvi:%s" % o.code
     # DO NOT EVER CHANGE THIS, it must always and forever yield same unique_id for same transaction.
     at.unique_id = hashlib.sha1(str(o.code).encode('utf-8') + at.stamp.isoformat().encode('utf-8')).hexdigest()
     return [at]  # We must return a list since invoice might have multiple payments
示例#3
0
 def invoice2atlist(self, i):
     if not i.payments:
         return None
     atlist = []
     for pline in i.payments:
         at = AbstractTransaction()
         at.holvi_invoice = i  # nonstandard field, but ought to be helpful
         at.name = str(i.receiver.name)
         at.email = str(i.receiver.email)
         at.amount = Decimal(pline['amount'])
         at.reference = str(i.rf_reference)
         at.stamp = dateutil.parser.parse(pline['time'])
         # DO NOT EVER CHANGE THIS, it must always and forever yield same unique_id for same transaction.
         at.unique_id = hashlib.sha1(str(i.code).encode('utf-8') + at.stamp.isoformat().encode('utf-8')).hexdigest()
         atlist.append(at)
     return atlist
示例#4
0
文件: importer.py 项目: vranki/asylum
 def order2atlist(self, o):
     if not o.paid:
         return None
     at = AbstractTransaction()
     at.holvi_order = o  # nonstandard field, but ought to be helpful
     at.name = "%s, %s" % (o.buyer.lastname, o.buyer.firstname)
     at.email = str(o.buyer.email)
     at.stamp = o.paid_time  # this is already parsed by holviapi
     at.amount = o.net
     at.reference = "holvi:%s" % o.code
     # DO NOT EVER CHANGE THIS, it must always and forever yield same unique_id for same transaction.
     at.unique_id = hashlib.sha1(
         str(o.code).encode('utf-8') +
         at.stamp.isoformat().encode('utf-8')).hexdigest()
     return [
         at
     ]  # We must return a list since invoice might have multiple payments
示例#5
0
文件: importer.py 项目: vranki/asylum
 def invoice2atlist(self, i):
     if not i.payments:
         return None
     atlist = []
     for pline in i.payments:
         at = AbstractTransaction()
         at.holvi_invoice = i  # nonstandard field, but ought to be helpful
         at.name = str(i.receiver.name)
         at.email = str(i.receiver.email)
         at.amount = Decimal(pline['amount'])
         at.reference = str(i.rf_reference)
         at.stamp = dateutil.parser.parse(pline['time'])
         # DO NOT EVER CHANGE THIS, it must always and forever yield same unique_id for same transaction.
         at.unique_id = hashlib.sha1(
             str(i.code).encode('utf-8') +
             at.stamp.isoformat().encode('utf-8')).hexdigest()
         atlist.append(at)
     return atlist
示例#6
0
    def form_valid(self, form):
        context = self.get_context_data()
        # We have to write out the file in binary mode before we properly parse it by lines
        tmp = tempfile.NamedTemporaryFile(prefix="ndaupload", delete=False)
        with tmp as dest:
            for chunk in self.request.FILES['ndafile'].chunks():
                dest.write(chunk)

        transactions_handler = context['transactions_handler']
        transactions = []
        with open(tmp.name) as f:
            for line in f:
                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 = 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

        # Done with the temp file, get rid of it
        os.unlink(tmp.name)

        context['title'] = _("Transactions uploaded")
        context['transactions'] = transactions
        return self.render_to_response(context)
示例#7
0
 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