<commit_before># -*- coding: utf-8 -*-
from decimal import Decimal

from django.conf import settings
from django.core.mail import EmailMessage
from django.template import Context
from django.template.loader import get_template
from django.utils import timezone
from holviapi.utils import barcode as bank_barcode
from members.models import Member
from ndaparser.models import UploadedTransaction

from .models import NotificationSent


class NordeaOverdueInvoicesHandler(object):
    def list_overdue(self):
        raise NotImplemented()
        # TODO: Heuristics to determine which transactions are not paid...

    def process_overdue(self, send=False):
        barcode_iban = settings.NORDEA_BARCODE_IBAN
        body_template = get_template('velkoja/nordea_notification_email_body.jinja')
        subject_template = get_template('velkoja/nordea_notification_email_subject.jinja')
        overdue = self.list_overdue()
        ret = []
        for transaction in overdue:
            # If we have already sent notification recently, do not sent one just yet
            if NotificationSent.objects.filter(transaction_unique_id=transaction.unique_id).count():
                notified = NotificationSent.objects.get(transaction_unique_id=transaction.unique_id)
                if (timezone.now() - notified.stamp).days < settings.HOLVI_NOTIFICATION_INTERVAL_DAYS:
                    continue

            barcode = None
            if barcode_iban:
                barcode = bank_barcode(barcode_iban, transaction.reference, -transaction.amount)

            mail = EmailMessage()
            mail.subject = subject_template.render(Context({"transaction": transaction, "barcode": barcode})).strip()
            mail.body = body_template.render(Context({"transaction": transaction, "barcode": barcode}))
            mail.to = [transaction.owner.email]
            if send:
                mail.send()

            try:
                notified = NotificationSent.objects.get(transaction_unique_id=transaction.unique_id)
                notified.notification_no += 1
            except NotificationSent.DoesNotExist:
                notified = NotificationSent()
                notified.transaction_unique_id = transaction.unique_id
            notified.stamp = timezone.now()
            notified.email = transaction.owner.email
            if send:
                notified.save()
            ret.append((notified, transaction))
        return ret
<commit_msg>Add the same email from/cc handling as in Holvi<commit_after># -*- coding: utf-8 -*-
from decimal import Decimal

from django.conf import settings
from django.core.mail import EmailMessage
from django.template import Context
from django.template.loader import get_template
from django.utils import timezone
from holviapi.utils import barcode as bank_barcode
from members.models import Member
from ndaparser.models import UploadedTransaction

from .models import NotificationSent


class NordeaOverdueInvoicesHandler(object):
    def list_overdue(self):
        raise NotImplemented()
        # TODO: Heuristics to determine which transactions are not paid...

    def process_overdue(self, send=False):
        barcode_iban = settings.NORDEA_BARCODE_IBAN
        body_template = get_template('velkoja/nordea_notification_email_body.jinja')
        subject_template = get_template('velkoja/nordea_notification_email_subject.jinja')
        overdue = self.list_overdue()
        ret = []
        for transaction in overdue:
            # If we have already sent notification recently, do not sent one just yet
            if NotificationSent.objects.filter(transaction_unique_id=transaction.unique_id).count():
                notified = NotificationSent.objects.get(transaction_unique_id=transaction.unique_id)
                if (timezone.now() - notified.stamp).days < settings.HOLVI_NOTIFICATION_INTERVAL_DAYS:
                    continue

            barcode = None
            if barcode_iban:
                barcode = bank_barcode(barcode_iban, transaction.reference, -transaction.amount)

            mail = EmailMessage()
            mail.from_email = settings.VELKOJA_FROM_EMAIL
            mail.to = [transaction.owner.email]
            if settings.VELKOJA_CC_EMAIL:
                mail.cc = [settings.VELKOJA_CC_EMAIL]
            mail.subject = subject_template.render(Context({"transaction": transaction, "barcode": barcode})).strip()
            mail.body = body_template.render(Context({"transaction": transaction, "barcode": barcode}))
            if send:
                mail.send()

            try:
                notified = NotificationSent.objects.get(transaction_unique_id=transaction.unique_id)
                notified.notification_no += 1
            except NotificationSent.DoesNotExist:
                notified = NotificationSent()
                notified.transaction_unique_id = transaction.unique_id
            notified.stamp = timezone.now()
            notified.email = transaction.owner.email
            if send:
                notified.save()
            ret.append((notified, transaction))
        return ret

{'fraction_non_alphanumeric': 0.07678780773739742, 'fraction_numerical': 0.0007815552950371239, 'mean_word_length': 2.674802584350323, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5607312', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1300, 'n_words': 304}