- Improvement of Entitlements Domain
- Introduction of LicensePeriod - Introduction of Payments - Introduction of Invoices - Services definitions for Entitlements Domain
This commit is contained in:
@@ -151,6 +151,8 @@ def register_cache_handlers(app):
|
||||
register_config_cache_handlers(cache_manager)
|
||||
from common.utils.cache.crewai_processed_config_cache import register_specialist_cache_handlers
|
||||
register_specialist_cache_handlers(cache_manager)
|
||||
from common.utils.cache.license_cache import register_license_cache_handlers
|
||||
register_license_cache_handlers(cache_manager)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
{{ form.hidden_tag() }}
|
||||
{% set main_fields = ['start_date', 'end_date', 'currency', 'yearly_payment', 'basic_fee'] %}
|
||||
{% set main_fields = ['start_date', 'nr_of_periods', 'currency', 'yearly_payment', 'basic_fee'] %}
|
||||
{% for field in form %}
|
||||
{{ render_included_field(field, readonly_fields=ext_readonly_fields + ['currency'], include_fields=main_fields) }}
|
||||
{% endfor %}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
{{ form.hidden_tag() }}
|
||||
{% set main_fields = ['start_date', 'end_date', 'currency', 'yearly_payment', 'basic_fee'] %}
|
||||
{% set main_fields = ['start_date', 'nr_of_periods', 'currency', 'yearly_payment', 'basic_fee'] %}
|
||||
{% for field in form %}
|
||||
{{ render_included_field(field, readonly_fields=ext_readonly_fields + ['currency'], include_fields=main_fields) }}
|
||||
{% endfor %}
|
||||
|
||||
398
eveai_app/templates/entitlements/license_periods.html
Normal file
398
eveai_app/templates/entitlements/license_periods.html
Normal file
@@ -0,0 +1,398 @@
|
||||
{% extends 'base.html' %}
|
||||
{% from "macros.html" import render_selectable_table %}
|
||||
|
||||
{% block title %}License Periods - {{ license.id }}{% endblock %}
|
||||
|
||||
{% block content_title %}License Periods{% endblock %}
|
||||
{% block content_description %}License: {{ license.id }} | Tier: {{ license.license_tier.name }} | Periods: {{ periods|length }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container-fluid">
|
||||
<!-- License Summary Card -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<strong>License ID:</strong> {{ license.id }}
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<strong>Start Date:</strong> {{ license.start_date }}
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<strong>Total Periods:</strong> {{ license.nr_of_periods }}
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<strong>Currency:</strong> {{ license.currency }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Periods Table -->
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5>License Periods</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Period</th>
|
||||
<th>Start Date</th>
|
||||
<th>End Date</th>
|
||||
<th>Status</th>
|
||||
<th>Usage</th>
|
||||
<th>Payments</th>
|
||||
<th>Invoices</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for period in periods %}
|
||||
<tr class="period-row" data-period-id="{{ period.id }}">
|
||||
<td>{{ period.period_number }}</td>
|
||||
<td>{{ period.period_start }}</td>
|
||||
<td>{{ period.period_end }}</td>
|
||||
<td>
|
||||
<span class="badge badge-{{ period.status.name|status_color }}">
|
||||
{{ period.status.name }}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
{% set usage = usage_by_period.get(period.id) %}
|
||||
{% if usage %}
|
||||
<small>
|
||||
S: {{ "%.1f"|format(usage.storage_mb_used or 0) }}MB<br>
|
||||
E: {{ "%.1f"|format(usage.embedding_mb_used or 0) }}MB<br>
|
||||
I: {{ "{:,}"|format(usage.interaction_total_tokens_used or 0) }}
|
||||
</small>
|
||||
{% else %}
|
||||
<span class="text-muted">No usage</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% set payments = payments_by_period.get(period.id, []) %}
|
||||
<small>{{ payments|length }} payment(s)</small>
|
||||
</td>
|
||||
<td>
|
||||
{% set invoices = invoices_by_period.get(period.id, []) %}
|
||||
<small>{{ invoices|length }} invoice(s)</small>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-info" onclick="showPeriodDetails({{ period.id }})">
|
||||
Details
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Period Details Modal -->
|
||||
<div class="modal fade" id="periodDetailsModal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog modal-lg" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="periodModalTitle">Period Details</h5>
|
||||
<button type="button" class="close" data-dismiss="modal">
|
||||
<span>×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<!-- Nav Tabs -->
|
||||
<ul class="nav nav-tabs" id="periodTabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" id="status-tab" data-toggle="tab" href="#status" role="tab">
|
||||
Status & Timeline
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="usage-tab" data-toggle="tab" href="#usage" role="tab">
|
||||
Usage
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="financial-tab" data-toggle="tab" href="#financial" role="tab">
|
||||
Financial
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- Tab Content -->
|
||||
<div class="tab-content mt-3">
|
||||
<!-- Status Tab -->
|
||||
<div class="tab-pane fade show active" id="status" role="tabpanel">
|
||||
<div id="statusContent"></div>
|
||||
</div>
|
||||
|
||||
<!-- Usage Tab -->
|
||||
<div class="tab-pane fade" id="usage" role="tabpanel">
|
||||
<div id="usageContent"></div>
|
||||
</div>
|
||||
|
||||
<!-- Financial Tab -->
|
||||
<div class="tab-pane fade" id="financial" role="tabpanel">
|
||||
<div id="financialContent"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
// Period data for JavaScript access
|
||||
const periodsData = {
|
||||
{% for period in periods %}
|
||||
{{ period.id }}: {
|
||||
period_number: {{ period.period_number }},
|
||||
period_start: "{{ period.period_start }}",
|
||||
period_end: "{{ period.period_end }}",
|
||||
status: "{{ period.status.name }}",
|
||||
upcoming_at: "{{ period.upcoming_at or '' }}",
|
||||
pending_at: "{{ period.pending_at or '' }}",
|
||||
active_at: "{{ period.active_at or '' }}",
|
||||
completed_at: "{{ period.completed_at or '' }}",
|
||||
invoiced_at: "{{ period.invoiced_at or '' }}",
|
||||
closed_at: "{{ period.closed_at or '' }}",
|
||||
usage: {{ usage_by_period.get(period.id).to_dict() if usage_by_period.get(period.id) else 'null' }},
|
||||
payments: [
|
||||
{% for payment in payments_by_period.get(period.id, []) %}
|
||||
{
|
||||
id: {{ payment.id }},
|
||||
type: "{{ payment.payment_type.name }}",
|
||||
amount: {{ payment.amount }},
|
||||
currency: "{{ payment.currency }}",
|
||||
status: "{{ payment.status.name }}",
|
||||
paid_at: "{{ payment.paid_at or '' }}"
|
||||
}{% if not loop.last %},{% endif %}
|
||||
{% endfor %}
|
||||
],
|
||||
invoices: [
|
||||
{% for invoice in invoices_by_period.get(period.id, []) %}
|
||||
{
|
||||
id: {{ invoice.id }},
|
||||
type: "{{ invoice.invoice_type.name }}",
|
||||
number: "{{ invoice.invoice_number }}",
|
||||
amount: {{ invoice.amount }},
|
||||
currency: "{{ invoice.currency }}",
|
||||
status: "{{ invoice.status.name }}",
|
||||
due_date: "{{ invoice.due_date }}"
|
||||
}{% if not loop.last %},{% endif %}
|
||||
{% endfor %}
|
||||
]
|
||||
}{% if not loop.last %},{% endif %}
|
||||
{% endfor %}
|
||||
};
|
||||
|
||||
function showPeriodDetails(periodId) {
|
||||
const period = periodsData[periodId];
|
||||
if (!period) return;
|
||||
|
||||
// Update modal title
|
||||
document.getElementById('periodModalTitle').textContent = `Period ${period.period_number} Details`;
|
||||
|
||||
// Update status content
|
||||
updateStatusContent(period);
|
||||
updateUsageContent(period);
|
||||
updateFinancialContent(period);
|
||||
|
||||
// Show modal
|
||||
$('#periodDetailsModal').modal('show');
|
||||
}
|
||||
|
||||
function updateStatusContent(period) {
|
||||
const statusContent = document.getElementById('statusContent');
|
||||
const statusDates = [
|
||||
{ label: 'Upcoming', date: period.upcoming_at },
|
||||
{ label: 'Pending', date: period.pending_at },
|
||||
{ label: 'Active', date: period.active_at },
|
||||
{ label: 'Completed', date: period.completed_at },
|
||||
{ label: 'Invoiced', date: period.invoiced_at },
|
||||
{ label: 'Closed', date: period.closed_at }
|
||||
];
|
||||
|
||||
let html = `
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<h6>Current Status</h6>
|
||||
<span class="badge badge-${getStatusColor(period.status)} badge-lg">${period.status}</span>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<h6>Period Dates</h6>
|
||||
<p><strong>Start:</strong> ${period.period_start}<br>
|
||||
<strong>End:</strong> ${period.period_end}</p>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<h6>Status Timeline</h6>
|
||||
<div class="timeline">
|
||||
`;
|
||||
|
||||
statusDates.forEach(item => {
|
||||
if (item.date) {
|
||||
html += `
|
||||
<div class="timeline-item">
|
||||
<strong>${item.label}:</strong> ${item.date}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
});
|
||||
|
||||
html += '</div>';
|
||||
statusContent.innerHTML = html;
|
||||
}
|
||||
|
||||
function updateUsageContent(period) {
|
||||
const usageContent = document.getElementById('usageContent');
|
||||
|
||||
if (!period.usage) {
|
||||
usageContent.innerHTML = '<p class="text-muted">No usage data available</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
const usage = period.usage;
|
||||
usageContent.innerHTML = `
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body text-center">
|
||||
<h5>Storage</h5>
|
||||
<h3>${(usage.storage_mb_used || 0).toFixed(1)} MB</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body text-center">
|
||||
<h5>Embedding</h5>
|
||||
<h3>${(usage.embedding_mb_used || 0).toFixed(1)} MB</h3>
|
||||
<small>Tokens: ${(usage.embedding_total_tokens_used || 0).toLocaleString()}</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body text-center">
|
||||
<h5>Interaction</h5>
|
||||
<h3>${(usage.interaction_total_tokens_used || 0).toLocaleString()}</h3>
|
||||
<small>Prompt: ${(usage.interaction_prompt_tokens_used || 0).toLocaleString()}<br>
|
||||
Completion: ${(usage.interaction_completion_tokens_used || 0).toLocaleString()}</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function updateFinancialContent(period) {
|
||||
const financialContent = document.getElementById('financialContent');
|
||||
|
||||
let html = '<div class="row">';
|
||||
|
||||
// Payments section
|
||||
html += '<div class="col-md-6"><h6>Payments</h6>';
|
||||
if (period.payments.length === 0) {
|
||||
html += '<p class="text-muted">No payments</p>';
|
||||
} else {
|
||||
html += '<div class="table-responsive"><table class="table table-sm">';
|
||||
html += '<thead><tr><th>Type</th><th>Amount</th><th>Status</th><th>Date</th></tr></thead><tbody>';
|
||||
period.payments.forEach(payment => {
|
||||
html += `
|
||||
<tr>
|
||||
<td>${payment.type}</td>
|
||||
<td>${payment.amount} ${payment.currency}</td>
|
||||
<td><span class="badge badge-${getPaymentStatusColor(payment.status)}">${payment.status}</span></td>
|
||||
<td>${payment.paid_at || '-'}</td>
|
||||
</tr>
|
||||
`;
|
||||
});
|
||||
html += '</tbody></table></div>';
|
||||
}
|
||||
html += '</div>';
|
||||
|
||||
// Invoices section
|
||||
html += '<div class="col-md-6"><h6>Invoices</h6>';
|
||||
if (period.invoices.length === 0) {
|
||||
html += '<p class="text-muted">No invoices</p>';
|
||||
} else {
|
||||
html += '<div class="table-responsive"><table class="table table-sm">';
|
||||
html += '<thead><tr><th>Type</th><th>Number</th><th>Amount</th><th>Status</th><th>Due</th></tr></thead><tbody>';
|
||||
period.invoices.forEach(invoice => {
|
||||
html += `
|
||||
<tr>
|
||||
<td>${invoice.type}</td>
|
||||
<td>${invoice.number}</td>
|
||||
<td>${invoice.amount} ${invoice.currency}</td>
|
||||
<td><span class="badge badge-${getInvoiceStatusColor(invoice.status)}">${invoice.status}</span></td>
|
||||
<td>${invoice.due_date}</td>
|
||||
</tr>
|
||||
`;
|
||||
});
|
||||
html += '</tbody></table></div>';
|
||||
}
|
||||
html += '</div></div>';
|
||||
|
||||
financialContent.innerHTML = html;
|
||||
}
|
||||
|
||||
function getStatusColor(status) {
|
||||
const colors = {
|
||||
'UPCOMING': 'secondary',
|
||||
'PENDING': 'warning',
|
||||
'ACTIVE': 'success',
|
||||
'COMPLETED': 'info',
|
||||
'INVOICED': 'primary',
|
||||
'CLOSED': 'dark'
|
||||
};
|
||||
return colors[status] || 'secondary';
|
||||
}
|
||||
|
||||
function getPaymentStatusColor(status) {
|
||||
const colors = {
|
||||
'PENDING': 'warning',
|
||||
'PAID': 'success',
|
||||
'FAILED': 'danger',
|
||||
'CANCELLED': 'secondary'
|
||||
};
|
||||
return colors[status] || 'secondary';
|
||||
}
|
||||
|
||||
function getInvoiceStatusColor(status) {
|
||||
const colors = {
|
||||
'DRAFT': 'secondary',
|
||||
'SENT': 'info',
|
||||
'PAID': 'success',
|
||||
'OVERDUE': 'danger',
|
||||
'CANCELLED': 'secondary'
|
||||
};
|
||||
return colors[status] || 'secondary';
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.timeline-item {
|
||||
padding: 5px 0;
|
||||
border-left: 2px solid #e9ecef;
|
||||
padding-left: 15px;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.period-row:hover {
|
||||
background-color: #f8f9fa;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.badge-lg {
|
||||
font-size: 0.9em;
|
||||
padding: 0.5em 0.75em;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
@@ -8,10 +8,11 @@
|
||||
|
||||
{% block content %}
|
||||
<form action="{{ url_for('entitlements_bp.handle_license_selection') }}" method="POST" id="licensesForm">
|
||||
{{ render_selectable_table(headers=["License ID", "Name", "Start Date", "End Date", "Active"], rows=rows, selectable=True, id="licensesTable") }}
|
||||
{{ render_selectable_table(headers=["License ID", "Name", "Start Date", "Nr of Periods", "Active"], rows=rows, selectable=True, id="licensesTable") }}
|
||||
<div class="form-group mt-3 d-flex justify-content-between">
|
||||
<div>
|
||||
<button type="submit" name="action" value="edit_license" class="btn btn-primary" onclick="return validateTableSelection('licensesForm')">Edit License</button>
|
||||
<button type="submit" name="action" value="view_periods" class="btn btn-info" onclick="return validateTableSelection('licensesForm')">View Periods</button>
|
||||
</div>
|
||||
<!-- Additional buttons can be added here for other actions -->
|
||||
</div>
|
||||
|
||||
@@ -37,16 +37,15 @@ class LicenseTierForm(FlaskForm):
|
||||
additional_interaction_bucket = IntegerField('Additional Interaction Bucket Size (M Tokens)',
|
||||
validators=[DataRequired(), NumberRange(min=1)])
|
||||
standard_overage_embedding = FloatField('Standard Overage Embedding (%)',
|
||||
validators=[DataRequired(), NumberRange(min=0)],
|
||||
default=0)
|
||||
validators=[DataRequired(), NumberRange(min=0)], default=0)
|
||||
standard_overage_interaction = FloatField('Standard Overage Interaction (%)',
|
||||
validators=[DataRequired(), NumberRange(min=0)],
|
||||
default=0)
|
||||
validators=[DataRequired(), NumberRange(min=0)], default=0)
|
||||
|
||||
|
||||
class LicenseForm(FlaskForm):
|
||||
start_date = DateField('Start Date', id='form-control datepicker', validators=[DataRequired()])
|
||||
end_date = DateField('End Date', id='form-control datepicker', validators=[DataRequired()])
|
||||
nr_of_periods = IntegerField('Number of Periods',
|
||||
validators=[DataRequired(), NumberRange(min=1, max=12)], default=12)
|
||||
currency = StringField('Currency', validators=[Optional(), Length(max=20)])
|
||||
yearly_payment = BooleanField('Yearly Payment', default=False)
|
||||
basic_fee = FloatField('Basic Fee', validators=[InputRequired(), NumberRange(min=0)])
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
import uuid
|
||||
from datetime import datetime as dt, timezone as tz
|
||||
from flask import request, redirect, flash, render_template, Blueprint, session, current_app, jsonify
|
||||
from flask_security import hash_password, roles_required, roles_accepted, current_user
|
||||
from flask import request, redirect, flash, render_template, Blueprint, session, current_app
|
||||
from flask_security import roles_accepted, current_user
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy import or_, desc
|
||||
import ast
|
||||
|
||||
from common.models.entitlements import License, LicenseTier, LicenseUsage, BusinessEventLog
|
||||
from common.extensions import db, security, minio_client, simple_encryption
|
||||
from common.models.entitlements import License, LicenseTier, LicenseUsage, LicensePeriod, PeriodStatus
|
||||
from common.extensions import db, cache_manager
|
||||
|
||||
from common.services.entitlement_services import EntitlementServices
|
||||
from common.services.partner_services import PartnerServices
|
||||
from common.services.tenant_services import TenantServices
|
||||
from common.services.user_services import UserServices
|
||||
from common.services.entitlements.license_tier_services import LicenseTierServices
|
||||
from common.services.user.partner_services import PartnerServices
|
||||
from common.services.user.user_services import UserServices
|
||||
from common.utils.eveai_exceptions import EveAIException
|
||||
from common.utils.security_utils import current_user_has_role
|
||||
from .entitlements_forms import LicenseTierForm, LicenseForm
|
||||
@@ -109,7 +107,7 @@ def handle_license_tier_selection():
|
||||
return redirect(prefixed_url_for('entitlements_bp.create_license',
|
||||
license_tier_id=license_tier_id))
|
||||
case 'associate_license_tier_to_partner':
|
||||
EntitlementServices.associate_license_tier_with_partner(license_tier_id)
|
||||
LicenseTierServices.associate_license_tier_with_partner(license_tier_id)
|
||||
|
||||
# Add more conditions for other actions
|
||||
return redirect(prefixed_url_for('entitlements_bp.view_license_tiers'))
|
||||
@@ -153,8 +151,8 @@ def create_license(license_tier_id):
|
||||
currency = session.get('tenant').get('currency')
|
||||
|
||||
if current_user_has_role("Partner Admin"): # The Partner Admin can only set start & end dates, and allowed fields
|
||||
readonly_fields = [field.name for field in form if (field.name != 'end_date' and field.name != 'start_date' and
|
||||
not field.name.endswith('allowed'))]
|
||||
readonly_fields = [field.name for field in form if (field.name != 'nr_of_periods' and field.name != 'start_date'
|
||||
and not field.name.endswith('allowed'))]
|
||||
|
||||
if request.method == 'GET':
|
||||
# Fetch the LicenseTier
|
||||
@@ -221,11 +219,14 @@ def edit_license(license_id):
|
||||
license = License.query.get_or_404(license_id) # This will return a 404 if no license tier is found
|
||||
form = LicenseForm(obj=license)
|
||||
readonly_fields = []
|
||||
if len(license.usages) > 0: # There already are usage records linked to this license
|
||||
if len(license.periods) > 0: # There already are usage records linked to this license
|
||||
# Define which fields should be disabled
|
||||
readonly_fields = [field.name for field in form if field.name != 'end_date']
|
||||
if current_user_has_role("Partner Admin"): # The Partner Admin can only set the end date
|
||||
readonly_fields = [field.name for field in form if field.name != 'end_date']
|
||||
readonly_fields = [field.name for field in form if field.name != 'nr_of_periods']
|
||||
if current_user_has_role("Partner Admin"): # The Partner Admin can only set the nr_of_periods and allowed fields
|
||||
readonly_fields = [field.name for field in form if (field.name != 'nr_of_periods'
|
||||
and not field.name.endswith('allowed'))]
|
||||
|
||||
cache_manager.license_cache.invalidate_tenant_license(license.tenant_id)
|
||||
|
||||
if form.validate_on_submit():
|
||||
# Populate the license with form data
|
||||
@@ -296,6 +297,7 @@ def view_licenses():
|
||||
current_date = dt.now(tz=tz.utc).date()
|
||||
|
||||
# Query licenses for the tenant, with ordering and active status
|
||||
# TODO - Check validity
|
||||
query = (
|
||||
License.query
|
||||
.join(LicenseTier) # Join with LicenseTier
|
||||
@@ -303,10 +305,9 @@ def view_licenses():
|
||||
.add_columns(
|
||||
License.id,
|
||||
License.start_date,
|
||||
License.end_date,
|
||||
License.nr_of_periods,
|
||||
LicenseTier.name.label('license_tier_name'), # Access name through LicenseTier
|
||||
((License.start_date <= current_date) &
|
||||
(or_(License.end_date.is_(None), License.end_date >= current_date))).label('active')
|
||||
(License.start_date <= current_date).label('active')
|
||||
)
|
||||
.order_by(License.start_date.desc())
|
||||
)
|
||||
@@ -315,8 +316,8 @@ def view_licenses():
|
||||
lics = pagination.items
|
||||
|
||||
# prepare table data
|
||||
rows = prepare_table_for_macro(lics, [('id', ''), ('license_tier_name', ''), ('start_date', ''), ('end_date', ''),
|
||||
('active', '')])
|
||||
rows = prepare_table_for_macro(lics, [('id', ''), ('license_tier_name', ''), ('start_date', ''),
|
||||
('nr_of_periods', ''), ('active', '')])
|
||||
|
||||
# Render the licenses in a template
|
||||
return render_template('entitlements/view_licenses.html', rows=rows, pagination=pagination)
|
||||
@@ -333,4 +334,62 @@ def handle_license_selection():
|
||||
|
||||
match action:
|
||||
case 'edit_license':
|
||||
return redirect(prefixed_url_for('entitlements_bp.edit_license', license_id=license_id))
|
||||
return redirect(prefixed_url_for('entitlements_bp.edit_license', license_id=license_id))
|
||||
case 'view_periods':
|
||||
return redirect(prefixed_url_for('entitlements_bp.view_license_periods', license_id=license_id))
|
||||
|
||||
|
||||
@entitlements_bp.route('/license/<int:license_id>/periods')
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def view_license_periods(license_id):
|
||||
license = License.query.get_or_404(license_id)
|
||||
|
||||
# Verify user can access this license
|
||||
if not current_user.has_role('Super User'):
|
||||
tenant_id = session.get('tenant').get('id')
|
||||
if license.tenant_id != tenant_id:
|
||||
flash('Access denied to this license', 'danger')
|
||||
return redirect(prefixed_url_for('entitlements_bp.view_licenses'))
|
||||
|
||||
# Get all periods for this license
|
||||
periods = (LicensePeriod.query
|
||||
.filter_by(license_id=license_id)
|
||||
.order_by(LicensePeriod.period_number)
|
||||
.all())
|
||||
|
||||
# Group related data for easy template access
|
||||
usage_by_period = {}
|
||||
payments_by_period = {}
|
||||
invoices_by_period = {}
|
||||
|
||||
for period in periods:
|
||||
usage_by_period[period.id] = period.license_usage
|
||||
payments_by_period[period.id] = list(period.payments)
|
||||
invoices_by_period[period.id] = list(period.invoices)
|
||||
|
||||
return render_template('entitlements/license_periods.html',
|
||||
license=license,
|
||||
periods=periods,
|
||||
usage_by_period=usage_by_period,
|
||||
payments_by_period=payments_by_period,
|
||||
invoices_by_period=invoices_by_period)
|
||||
|
||||
|
||||
@entitlements_bp.route('/license/<int:license_id>/periods/<int:period_id>/transition', methods=['POST'])
|
||||
@roles_accepted('Super User', 'Partner Admin')
|
||||
def transition_period_status(license_id, period_id):
|
||||
"""Handle status transitions for license periods"""
|
||||
period = LicensePeriod.query.get_or_404(period_id)
|
||||
new_status = request.form.get('new_status')
|
||||
|
||||
try:
|
||||
period.transition_status(PeriodStatus[new_status], current_user.id)
|
||||
db.session.commit()
|
||||
flash(f'Period {period.period_number} status updated to {new_status}', 'success')
|
||||
except ValueError as e:
|
||||
flash(f'Invalid status transition: {str(e)}', 'danger')
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
flash(f'Error updating status: {str(e)}', 'danger')
|
||||
|
||||
return redirect(prefixed_url_for('entitlements_bp.view_license_periods', license_id=license_id))
|
||||
@@ -1,13 +1,12 @@
|
||||
from flask import current_app, session
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import (StringField, PasswordField, BooleanField, SubmitField, EmailField, IntegerField, DateField,
|
||||
SelectField, SelectMultipleField, FieldList, FormField, FloatField, TextAreaField)
|
||||
from wtforms.validators import DataRequired, Length, Email, NumberRange, Optional, ValidationError
|
||||
from wtforms import (StringField, BooleanField, SubmitField, EmailField, IntegerField, DateField,
|
||||
SelectField, SelectMultipleField, FieldList, FormField, TextAreaField)
|
||||
from wtforms.validators import DataRequired, Length, Email, NumberRange, Optional
|
||||
import pytz
|
||||
from flask_security import current_user
|
||||
|
||||
from common.models.user import Role
|
||||
from common.services.user_services import UserServices
|
||||
from common.services.user.user_services import UserServices
|
||||
from config.type_defs.service_types import SERVICE_TYPES
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import ast
|
||||
|
||||
from common.models.user import User, Tenant, Role, TenantDomain, TenantProject, PartnerTenant
|
||||
from common.extensions import db, security, minio_client, simple_encryption
|
||||
from common.services.user_services import UserServices
|
||||
from common.utils.security_utils import send_confirmation_email, send_reset_email
|
||||
from config.type_defs.service_types import SERVICE_TYPES
|
||||
from .user_forms import TenantForm, CreateUserForm, EditUserForm, TenantDomainForm, TenantSelectionForm, \
|
||||
@@ -18,8 +17,8 @@ from common.utils.simple_encryption import generate_api_key
|
||||
from common.utils.nginx_utils import prefixed_url_for
|
||||
from common.utils.eveai_exceptions import EveAIException
|
||||
from common.utils.document_utils import set_logging_information, update_logging_information
|
||||
from common.services.tenant_services import TenantServices
|
||||
from common.services.user_services import UserServices
|
||||
from common.services.user.tenant_services import TenantServices
|
||||
from common.services.user.user_services import UserServices
|
||||
from common.utils.mail_utils import send_email
|
||||
|
||||
user_bp = Blueprint('user_bp', __name__, url_prefix='/user')
|
||||
|
||||
Reference in New Issue
Block a user