Add periodic engagements and statutory due dates
This commit is contained in:
@@ -23,7 +23,14 @@ from app.modules.services.models import (
|
||||
ServiceDueDateRule,
|
||||
)
|
||||
from app.modules.services.services import normalize_code, normalize_engagement_type
|
||||
from app.modules.services.client_services import assessment_year_from_financial_year, normalize_financial_year, review_partner_required_for_engagement, ensure_engagement_quality_workflow, enforce_quality_gate_on_subscription
|
||||
from app.modules.services.client_services import (
|
||||
assessment_year_from_financial_year,
|
||||
normalize_financial_year,
|
||||
normalize_period_label,
|
||||
review_partner_required_for_engagement,
|
||||
ensure_engagement_quality_workflow,
|
||||
enforce_quality_gate_on_subscription,
|
||||
)
|
||||
from app.modules.services.due_dates import apply_due_date_rule_to_subscription, create_due_date_extension
|
||||
|
||||
TRUE_VALUES = {"1", "true", "yes", "y", "on"}
|
||||
@@ -33,6 +40,7 @@ CLIENT_ASSIGNMENT_COLUMNS = [
|
||||
"client_code",
|
||||
"service_code",
|
||||
"financial_year",
|
||||
"period_label",
|
||||
"engagement_type",
|
||||
"assigned_partner_email",
|
||||
"assigned_manager_email",
|
||||
@@ -759,6 +767,11 @@ def import_client_service_assignments(
|
||||
if not enabled:
|
||||
raise ValueError("Service is not enabled for this firm.")
|
||||
firm_selection, catalogue = enabled
|
||||
period_label = normalize_period_label(
|
||||
_clean(_cell(row, headers, "period_label")),
|
||||
financial_year=financial_year,
|
||||
recurrence_type=getattr(catalogue, "recurrence_type", None),
|
||||
)
|
||||
|
||||
partner_email = _clean(_cell(row, headers, "assigned_partner_email"))
|
||||
manager_email = _clean(_cell(row, headers, "assigned_manager_email"))
|
||||
@@ -786,6 +799,7 @@ def import_client_service_assignments(
|
||||
ClientServiceSubscription.client_id == client.id,
|
||||
ClientServiceSubscription.service_catalogue_id == catalogue.id,
|
||||
ClientServiceSubscription.financial_year == financial_year,
|
||||
ClientServiceSubscription.period_label == period_label,
|
||||
)
|
||||
).scalar_one_or_none()
|
||||
|
||||
@@ -801,6 +815,7 @@ def import_client_service_assignments(
|
||||
client_id=client.id,
|
||||
service_catalogue_id=catalogue.id,
|
||||
financial_year=financial_year,
|
||||
period_label=period_label,
|
||||
assessment_year=assessment_year_from_financial_year(financial_year),
|
||||
created_by_user_id=current_user.id,
|
||||
)
|
||||
@@ -810,6 +825,7 @@ def import_client_service_assignments(
|
||||
if getattr(sub, "is_locked", False):
|
||||
raise ValueError("Existing engagement for this client/service/year is locked and cannot be updated.")
|
||||
sub.financial_year = financial_year
|
||||
sub.period_label = period_label
|
||||
sub.assessment_year = assessment_year_from_financial_year(financial_year)
|
||||
imported_engagement_type = _clean(_cell(row, headers, "engagement_type"))
|
||||
sub.engagement_type = normalize_engagement_type(imported_engagement_type) if imported_engagement_type else (getattr(catalogue, "engagement_type", "non_assurance") or "non_assurance")
|
||||
@@ -826,7 +842,7 @@ def import_client_service_assignments(
|
||||
sub.is_active = is_active
|
||||
sub.remarks = _clean(_cell(row, headers, "remarks")) or None
|
||||
sub.updated_by_user_id = current_user.id
|
||||
apply_due_date_rule_to_subscription(db, sub)
|
||||
apply_due_date_rule_to_subscription(db, sub, force=True)
|
||||
ensure_engagement_quality_workflow(db, subscription=sub, actor_user_id=current_user.id, create_declarations=False)
|
||||
enforce_quality_gate_on_subscription(sub)
|
||||
except Exception as exc:
|
||||
|
||||
Reference in New Issue
Block a user