コード例 #1
0
 def setUp(self):
     # test objects
     self.memberservice = models.MemberService.objects.create(
         name="TestService",
         access_phone_number="+358123",
         cost=321,
         days_per_payment=30,
     )
     self.user = get_user_model().objects.create_customuser(
         first_name="FirstName",
         last_name="LastName",
         email="*****@*****.**",
         birthday=timezone.now(),
         municipality="City",
         nick="user1",
         phone="+358123123",
     )
     # be specific about the language to use for the test user
     self.user.language = 'fi'
     self.user.save()
     self.ss = BusinessLogic.create_servicesubscription(
         self.user, self.memberservice, models.ServiceSubscription.SUSPENDED
     )
コード例 #2
0
 def execute(self):
     qs = BusinessLogic.find_expiring_service_subscriptions()
     BusinessLogic.notify_expiring_service_subscriptions(qs)
コード例 #3
0
def updateuser(request):
    if request.method == "POST":
        user = get_object_or_404(CustomUser, id=request.POST["userid"])
        BusinessLogic.updateuser(user)
        messages.success(request, _(f"Updateuser ran for user {user}"))
    return HttpResponseRedirect(reverse("users"))
コード例 #4
0
 def test_find(self):
     about_to_expire = BusinessLogic.find_expiring_service_subscriptions()
     self.assertEqual(len(about_to_expire), 3)
     self.assertEqual(list(about_to_expire), [self.servicesubscription, self.servicesubscription_user2, self.servicesubscription_user2_another])
コード例 #5
0
    def import_tito(f):
        tito = f.read().decode("utf8")
        lines = tito.split("\n")
        imported = exists = error = 0
        failedrows = []
        for line in lines[1:]:
            logger.debug(f"import_tito - Processing line: {line}")
            try:
                if len(line) == 0 or line[0] != "T":
                    raise ParseError("Empty line or not starting with T")
                data_type = int(line[1:3])
                # Currently handle only type 10 (basic transaction data)
                if data_type == 10:
                    # normalize the line ending before checking the length
                    if int(line[3:6]) != 188 or len(
                            line.rstrip("\r\n")) != 188:
                        raise ParseError("Length should be 188")
                    transaction_id = line[6:12]
                    archival_reference = line[12:30].strip()
                    if len(archival_reference) < 18:
                        raise ParseError(
                            "Archival reference number invalid: " +
                            archival_reference)
                    transaction_date = datetime.datetime.strptime(
                        line[30:36], "%y%m%d")
                    transaction_type = int(line[48])
                    if transaction_type < 1 or transaction_type > 4:
                        raise ParseError(
                            "Transaction type should be between 1 and 4, not "
                            + str(transaction_type))
                    code = line[49:52]
                    message = line[52:87].strip()
                    if message == "Viitemaksu":
                        message = None
                    amount = int(line[87:106]) / 100
                    peer = line[108:143]
                    peer = peer.replace("[", "Ä")
                    peer = peer.replace("]", "Å")
                    peer = peer.replace("\\", "Ö")
                    # tito format has leading zeroes in reference number, strip them
                    reference = line[159:179].strip().lstrip("0")

                    # Done parsing, add the transaction

                    try:
                        # Archival reference should be unique ID
                        BankTransaction.objects.get(
                            archival_reference=archival_reference)
                        exists = exists + 1
                    except BankTransaction.DoesNotExist:
                        transaction = BankTransaction.objects.create(
                            date=transaction_date,
                            amount=amount,
                            reference_number=reference,
                            sender=peer,
                            archival_reference=archival_reference,
                            transaction_id=transaction_id,
                            code=code,
                        )
                        BusinessLogic.new_transaction(transaction)
                        imported = imported + 1
            except ParseError as err:
                logger.error(f"Error parsing data: {err}")
                error = error + 1
                failedrows.append(line + " (" + str(err) + ")")

        results = {
            "imported": imported,
            "exists": exists,
            "error": error,
            "failedrows": failedrows,
        }
        logger.info(f"Data imported: {results} - now updating all users..")

        BusinessLogic.update_all_users()

        return results
コード例 #6
0
 def handle(self, *args, **options):
     BusinessLogic.update_all_users()