Skip to content

Commit 5836a86

Browse files
committed
feat: Add minimum due date validation
1 parent e0321fe commit 5836a86

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

netsgiro/objects.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
TransmissionStart,
3131
)
3232
from netsgiro.records import parse as records_parse
33-
from netsgiro.validators import str_of_length
33+
from netsgiro.validators import str_of_length, validate_minimum_date
3434

3535
if TYPE_CHECKING:
3636
from netsgiro.enums import AvtaleGiroRegistrationType
@@ -365,6 +365,7 @@ def add_payment_request(
365365
reference: Optional[str] = None,
366366
payer_name: Optional[str] = None,
367367
bank_notification: Union[bool, str] = False,
368+
strict: bool = False,
368369
) -> 'PaymentRequest':
369370
"""Add an AvtaleGiro payment request to the assignment.
370371
@@ -379,6 +380,10 @@ def add_payment_request(
379380
self.type == AssignmentType.TRANSACTIONS
380381
), 'Can only add payment requests to transaction assignments'
381382

383+
if strict:
384+
# Make sure we're not passing invalid due dates
385+
validate_minimum_date(due_date)
386+
382387
if bank_notification:
383388
transaction_type = TransactionType.AVTALEGIRO_WITH_BANK_NOTIFICATION
384389
else:

netsgiro/validators.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
"""Custom validators for :mod:`attrs`."""
2-
from typing import Any, Callable
2+
from datetime import datetime
3+
from typing import TYPE_CHECKING, Any, Callable
34

45
from attr import Attribute
56
from attr.validators import instance_of
67

8+
from netsgiro.utils import OSLO_TZ, get_minimum_due_date
9+
10+
if TYPE_CHECKING:
11+
from datetime import date
12+
13+
714
C = Callable[[object, Attribute, Any], None]
815

916

@@ -31,3 +38,13 @@ def validator(instance: object, attribute: Attribute, value: Any) -> None:
3138
)
3239

3340
return validator
41+
42+
43+
def validate_minimum_date(value: 'date') -> None:
44+
"""Make sure payment request dates are gt the minimum allowed date."""
45+
if value < get_minimum_due_date(now=datetime.now(tz=OSLO_TZ)):
46+
raise ValueError(
47+
'The minimum due date of a transaction is today + 4 calendar days.'
48+
' OCR files with due dates earlier than this will be rejected when'
49+
' submitted.'
50+
)

0 commit comments

Comments
 (0)