'Validate if user limit has been reached for System Users
Checked in \'Validate\' event as we don\'t want welcome email sent if max users are exceeded.'

def validate_user_limit(self):

    if (self.user_type == u'Website    User'):
        return
    if (not self.enabled):
        return
    limits = get_limits()
    if (not limits.users):
        return
    total_users = get_total_users()
    if self.is_new():
        total_users += 1
    if (total_users > limits.users):
        frappe.throw(_(u'Sorry.    You    have    reached    the    maximum    user    limit    for    your    subscription.    You    can    either    disable    an    existing    user    or    buy    a    higher    subscription    plan.'), MaxUsersReachedError)
