コード例 #1
0
    def validate(self, measure):
        """
        Get all current QuotaOrderNumberOrigin objects associated with a
        measure's QuotaOrderNumber.

        Loop over these and raise a violation if the measure validity period is
        not contained by any of the origins
        """
        if not measure.order_number:
            return

        with override_current_transaction(self.transaction):
            contained_measure = measure.get_versions().current().get()

            origins = QuotaOrderNumberOrigin.objects.current().filter(
                order_number__order_number=measure.order_number.order_number, )

            for origin in origins:
                valid_between = origin.valid_between
                if validity_range_contains_range(
                        valid_between,
                        contained_measure.valid_between,
                ):
                    return

            raise self.violation(measure)
コード例 #2
0
ファイル: business_rules.py プロジェクト: kintisheff/tamato
    def validate(self, indent):
        goods_validity = indent.indented_goods_nomenclature.valid_between

        for node in indent.nodes.all():
            parent = node.get_parent()

            if not parent:
                continue

            parent_validity = parent.indent.indented_goods_nomenclature.valid_between

            if not validity_range_contains_range(parent_validity,
                                                 goods_validity):
                raise self.violation(indent)
コード例 #3
0
    def clean(self):
        cleaned_data = super().clean()

        if "measure_type" in cleaned_data and "valid_between" in cleaned_data:
            measure_type = cleaned_data["measure_type"]
            if not validity_range_contains_range(
                measure_type.valid_between,
                cleaned_data["valid_between"],
            ):
                raise ValidationError(
                    f"The date range of the measure can't be outside that of the measure type: "
                    f"{measure_type.valid_between} does not contain {cleaned_data['valid_between']}",
                )

        return cleaned_data
コード例 #4
0
    def validate(self, measure):
        if (not measure.effective_valid_between.upper_inf
                and measure.effective_valid_between.upper < date(2008, 1, 1)):
            # Exclude measure ending before 2008 - ME87 only counts from 2008 onwards.
            return

        regulation_validity = measure.generating_regulation.valid_between
        effective_end_date = measure.generating_regulation.effective_end_date

        if effective_end_date:
            regulation_validity = TaricDateRange(
                regulation_validity.lower,
                date(
                    year=effective_end_date.year,
                    month=effective_end_date.month,
                    day=effective_end_date.day,
                ),
            )

        if not validity_range_contains_range(
                regulation_validity,
                measure.effective_valid_between,
        ):
            raise self.violation(measure)
コード例 #5
0
ファイル: business_rules.py プロジェクト: uktrade/tamato
 def parent_spans_child(self, parent, child) -> bool:
     parent_validity = parent.indented_goods_nomenclature.version_at(
         self.transaction, ).valid_between
     child_validity = child.indented_goods_nomenclature.version_at(
         self.transaction, ).valid_between
     return validity_range_contains_range(parent_validity, child_validity)
コード例 #6
0
ファイル: test_util.py プロジェクト: kintisheff/tamato
def test_validity_range_contains_range(overall, contained, expected):
    dates = Dates()
    overall = getattr(dates, overall)
    contained = getattr(dates, contained)
    assert util.validity_range_contains_range(overall, contained) == expected