From 6a246f07ff96a6369771889120dcbcee33e11af6 Mon Sep 17 00:00:00 2001 From: Matthew McKenzie <97194636+mattjamc@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:05:51 +0100 Subject: [PATCH] Quota order number check --- reference_documents/checks/base.py | 11 +++++++++++ .../checks/preferential_quota_order_numbers.py | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/reference_documents/checks/base.py b/reference_documents/checks/base.py index 058bb427e..dda97f610 100644 --- a/reference_documents/checks/base.py +++ b/reference_documents/checks/base.py @@ -7,6 +7,7 @@ from common.models import Transaction from geo_areas.models import GeographicalArea from geo_areas.models import GeographicalAreaDescription +from quotas.models import QuotaOrderNumber from reference_documents.models import PreferentialQuota from reference_documents.models import PreferentialQuotaOrderNumber from reference_documents.models import PreferentialRate @@ -31,6 +32,16 @@ def __init__(self, preferential_quota_order_number: PreferentialQuotaOrderNumber super().__init__() self.preferential_quota_order_number = preferential_quota_order_number + def order_number(self): + try: + order_number = QuotaOrderNumber.objects.all().get( + order_number=self.preferential_quota_order_number.quota_order_number, + valid_between=self.preferential_quota_order_number.valid_between, + ) + return order_number + except QuotaOrderNumber.DoesNotExist: + return None + class BasePreferentialRateCheck(BaseCheck): def __init__(self, preferential_rate: PreferentialRate): diff --git a/reference_documents/checks/preferential_quota_order_numbers.py b/reference_documents/checks/preferential_quota_order_numbers.py index 8b1378917..26a4f9d0c 100644 --- a/reference_documents/checks/preferential_quota_order_numbers.py +++ b/reference_documents/checks/preferential_quota_order_numbers.py @@ -1 +1,13 @@ +from reference_documents.checks.base import BasePreferentialQuotaOrderNumberCheck +from reference_documents.models import AlignmentReportCheckStatus + +class OrderNumberExists(BasePreferentialQuotaOrderNumberCheck): + def run_check(self): + if not self.order_number(): + message = f"order number not found" + print("FAIL", message) + return AlignmentReportCheckStatus.FAIL, message + else: + print(f"PASS - order number {self.order_number()} found") + return AlignmentReportCheckStatus.PASS, ""