def validate_region(self, data, value): root = get_root(data['__parent__']) apply_validation = get_first_revision_date(root, default=get_now()) >= VALIDATE_ADDRESS_FROM if self.doc_type_allowed(root) and self.validation_allowed(root) and apply_validation: if data["countryName"] == "Україна": if value and value not in UA_REGIONS: raise ValidationError("field address:region not exist in ua_regions catalog")
def validate_currency(self, data, value): try: root = get_root(data.get("__parent__", {})) except AttributeError: root = None is_valid_date = get_first_revision_date(root, default=get_now()) >= VALIDATE_CURRENCY_FROM if is_valid_date and value not in CURRENCIES: raise ValidationError(f"Currency must be only {', '.join(CURRENCIES)}.")
def validate_countryName(self, data, value): root = get_root(data['__parent__']) apply_validation = get_first_revision_date( root, default=get_now()) >= VALIDATE_ADDRESS_FROM if self.doc_type_allowed(root) and self.validation_allowed( root) and apply_validation: if value not in COUNTRIES: raise ValidationError( u"field address:countryName not exist in countries catalog" )
def validate_classification_id(items, *args): for item in items: if get_first_revision_date(get_root(item["__parent__"]), default=get_now()) > CPV_336_INN_FROM: schemes = [x.scheme for x in item.additionalClassifications] schemes_inn_count = schemes.count(INN_SCHEME) if item.classification.id == CPV_PHARM_PRODUCTS and schemes_inn_count != 1: raise ValidationError( u"Item with classification.id={} have to contain exactly one additionalClassifications " u"with scheme={}".format(CPV_PHARM_PRODUCTS, INN_SCHEME)) if item.classification.id.startswith( CPV_PHARM_PRODUCTS[:3]) and schemes_inn_count > 1: raise ValidationError( u"Item with classification.id that starts with {} and contains additionalClassification " u"objects have to contain no more than one additionalClassifications " u"with scheme={}".format(CPV_PHARM_PRODUCTS[:3], INN_SCHEME))
def validate_selfEligible(self, data, value): tender = get_root(data["__parent__"]) if get_first_revision_date(tender, default=get_now()) > RELEASE_ECRITERIA_ARTICLE_17: if value is not None: raise ValidationError("Rogue field.")
def validate_code(self, data, value): root = get_root(data['__parent__']) validation_date = get_first_revision_date(root, default=get_now()) if validation_date >= UNIT_PRICE_REQUIRED_FROM: if value not in UNIT_CODES: raise ValidationError(u"Code should be one of valid unit codes.")
def amount_npv(self): """ Calculated energy service contract perfomance indicator """ return calculate_npv(get_root(self).NBUdiscountRate, self.annualCostsReduction, self.yearlyPayments, self.contractDuration)