def validate(self, attrs): cf = ClientCustomFieldDefinition() try: cfs = cf.validate(new_fields=attrs, instance=self.instance) except Exception as e: raise serializers.ValidationError({'custom_fields': e}) attrs['custom_fields'] = [{ 'name': k, 'value': v } for k, v in iter(cfs.items())] vat_id = attrs.get('vat_id') country_code = attrs.get('country', None) if vat_id and country_code: valid_vat, message = validate_vat_id(vat_id=vat_id, country_code=country_code) if not valid_vat: raise serializers.ValidationError({'vat_id': message}) if not validate_client_limit(): raise serializers.ValidationError({ 'non_field_errors': _('License client limit reached. Please check your license'), }) return super(StaffCreateClientSerializer, self).validate(attrs)
def validate(self, attrs): vat_id = attrs.get('vat_id') country_code = attrs.get('country', None) if vat_id and country_code: valid_vat, message = validate_vat_id(vat_id=vat_id, country_code=country_code) if not valid_vat: raise serializers.ValidationError({'vat_id': message}) return super().validate(attrs)
def validate(self, attrs): attrs = super(StaffClientUpdateSerializer, self).validate(attrs) cf = ClientCustomFieldDefinition() try: cfs = cf.validate(new_fields=attrs, instance=self.instance) except Exception as e: raise serializers.ValidationError({'custom_fields': e}) attrs['custom_fields'] = [{ 'name': k, 'value': v } for k, v in iter(cfs.items())] # Validate VAT ID vat_id = attrs.get('vat_id') country_code = attrs.get('country', None) if vat_id and country_code: valid_vat, message = validate_vat_id(vat_id=vat_id, country_code=country_code) if not valid_vat: raise serializers.ValidationError({'vat_id': message}) return attrs
def is_valid_fiscal_code(code: str) -> bool: """validates the ro fiscal code""" if ' ' in code: code = code.replace(' ', '') result, message = validate_vat_id(vat_id=code, country_code=code[:2]) return result