Skip to content

Commit

Permalink
Merge branch 'main' into IA-3579-ou-filters-datasource-version
Browse files Browse the repository at this point in the history
  • Loading branch information
beygorghor committed Dec 6, 2024
2 parents f3551bc + 7d32772 commit 16c3da9
Show file tree
Hide file tree
Showing 23 changed files with 671 additions and 44 deletions.
2 changes: 1 addition & 1 deletion hat/assets/js/apps/Iaso/domains/app/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@
"iaso.pages.create": "Créer un lien intégré",
"iaso.pages.dialog.delete.content": "Cette opération est irréversible",
"iaso.pages.dialog.delete.title": "Etes-vous sur de vouloir effacer ce lien intégré ?",
"iaso.pages.dialog.helper": "Entrer les informations du link intégré",
"iaso.pages.dialog.helper": "Entrer les informations du lien intégré",
"iaso.pages.edit": "Editer un lien intégré",
"iaso.pages.errors.name": "Le nom est un champ requis",
"iaso.pages.errors.slug": "Le slug est un champ requis",
Expand Down
43 changes: 27 additions & 16 deletions hat/assets/js/apps/Iaso/domains/home/components/LangSwitch.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box } from '@mui/material';
import { Box, Button } from '@mui/material';
import { makeStyles } from '@mui/styles';
import classNames from 'classnames';
import React, { FunctionComponent, useCallback } from 'react';
Expand All @@ -17,6 +17,14 @@ const useStyles = makeStyles(theme => ({
languageSwitchActive: {
color: theme.palette.primary.main,
},
languageSwitchButton: {
backgroundColor: theme.palette.success.main,
color: 'white',
borderRadius: 0,
textTransform: 'none',
paddingLeft: theme.spacing(3),
paddingRight: theme.spacing(3),
},
}));

export const LangSwitch: FunctionComponent = () => {
Expand Down Expand Up @@ -56,9 +64,15 @@ export const LangSwitch: FunctionComponent = () => {
</>
);
};

// We don't need to translate as we show "English" in english etc
const localeMap = {
fr: 'Français',
en: 'English',
};

export const OffLineLangSwitch: FunctionComponent = () => {
const classes: Record<string, string> = useStyles();
const { locale: activeLocale } = useLocale();
const { setLocale } = useLocale();
const handleClick = useCallback(
localeCode => {
Expand All @@ -68,21 +82,18 @@ export const OffLineLangSwitch: FunctionComponent = () => {
);
return (
<>
{APP_LOCALES.map((locale, index) => (
<Box key={locale.code}>
<Box
className={classNames(
classes.languageSwitch,
locale.code === activeLocale &&
classes.languageSwitchActive,
)}
onClick={() => handleClick(locale.code)}
>
{locale.code}
{APP_LOCALES.map((locale, index) => {
return (
<Box key={locale.code} ml={index === 1 ? 2 : undefined}>
<Button
onClick={() => handleClick(locale.code)}
className={classes.languageSwitchButton}
>
{localeMap[locale.code]}
</Button>
</Box>
{index + 1 !== APP_LOCALES.length && '-'}
</Box>
))}
);
})}
</>
);
};
15 changes: 13 additions & 2 deletions iaso/management/commands/delete_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from django.db.models.functions import Cast

from hat.audit.models import Modification
from iaso.models import Account, OrgUnitType, CommentIaso, StoragePassword, StorageDevice, StorageLogEntry
from iaso.models import Account, OrgUnitType, CommentIaso, StoragePassword, StorageDevice, StorageLogEntry, TenantUser
from iaso.models import BulkCreateUserCsvFile
from iaso.models import ExportLog, ExportRequest
from iaso.models import ExportLog
from iaso.models.base import DataSource, ExternalCredentials, Instance, Mapping, Profile, InstanceFile, InstanceLock
from iaso.models.base import Task, QUEUED, KILLED
from iaso.models.entity import Entity, EntityType
Expand Down Expand Up @@ -118,6 +118,11 @@ def delete_account(self, account):
)
forms = Form.objects_include_deleted.filter(projects__in=[project])

print(
"OrgUnitChangeRequestConfiguration delete",
project.orgunitchangerequestconfiguration_set.all().delete(),
)

print(
"OrgUnit remove reference_instance",
OrgUnitReferenceInstance.objects.filter(
Expand Down Expand Up @@ -262,6 +267,12 @@ def delete_account(self, account):
)
print("StorageDevice", StorageDevice.objects.filter(account=account).delete())

user_ids = profiles.values_list("user_id")
print(
"TenantUser delete",
TenantUser.objects.filter(Q(main_user_id__in=user_ids) | Q(account_user_id__in=user_ids)).delete(),
)

print("Users", User.objects.filter(iaso_profile__account=account).delete())

print("Profiles", profiles.delete())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.16 on 2024-12-05 10:25

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
("iaso", "0309_alter_potentialpayment_user"),
]

operations = [
migrations.AlterField(
model_name="orgunitchangerequestconfiguration",
name="project",
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="iaso.project"),
),
]
29 changes: 29 additions & 0 deletions iaso/migrations/0311_alter_tenantuser_account_user_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.16 on 2024-12-05 11:32

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("iaso", "0310_alter_orgunitchangerequestconfiguration_project"),
]

operations = [
migrations.AlterField(
model_name="tenantuser",
name="account_user",
field=models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE, related_name="tenant_user", to=settings.AUTH_USER_MODEL
),
),
migrations.AlterField(
model_name="tenantuser",
name="main_user",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, related_name="tenant_users", to=settings.AUTH_USER_MODEL
),
),
]
2 changes: 1 addition & 1 deletion iaso/models/org_unit_change_request_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class OrgUnitChangeRequestConfiguration(SoftDeletableModel):
or restrict the list of possible values for each field.
"""

project = models.ForeignKey("Project", on_delete=models.PROTECT)
project = models.ForeignKey("Project", on_delete=models.CASCADE)
org_unit_type = models.ForeignKey("OrgUnitType", on_delete=models.PROTECT)
org_units_editable = models.BooleanField(default=True) # = is it possible to edit org units of that type
editable_fields = ArrayField(
Expand Down
4 changes: 2 additions & 2 deletions iaso/models/tenant_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


class TenantUser(models.Model):
main_user = models.ForeignKey(User, on_delete=models.PROTECT, related_name="tenant_users")
account_user = models.OneToOneField(User, on_delete=models.PROTECT, related_name="tenant_user")
main_user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="tenant_users")
account_user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="tenant_user")
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

Expand Down
34 changes: 34 additions & 0 deletions plugins/polio/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from iaso.admin import IasoJSONEditorWidget
from plugins.polio.api.vaccines.supply_chain import validate_rounds_and_campaign
from plugins.polio.models.base import VaccineStockHistory

from .budget.models import BudgetProcess, BudgetStep, BudgetStepFile, BudgetStepLink, MailTemplate, WorkflowModel
from .models import (
Expand Down Expand Up @@ -272,6 +273,39 @@ def get_queryset(self, request):
return super().get_queryset(request).select_related("org_unit")


@admin.register(VaccineStockHistory)
class VaccineStockHistoryAdmin(admin.ModelAdmin):
list_display = ("get_campaign_name", "get_round_number", "round", "get_vaccine_name", "get_country")
# list_filter = ("get_country", "get_vaccine_name","get_campaign_name")

@admin.display(description="Campaign name")
def get_campaign_name(self, obj):
if obj.round:
return obj.round.campaign.obr_name
return None

@admin.display(description="Round number")
def get_round_number(self, obj):
if obj.round:
return obj.round.number
return None

@admin.display(description="Vaccine")
def get_vaccine_name(self, obj):
if obj.round:
return obj.vaccine_stock.vaccine
return None

@admin.display(description="Country")
def get_country(self, obj):
if obj.round:
return obj.vaccine_stock.country.name
return None

def get_queryset(self, request):
return super().get_queryset(request).select_related("round", "vaccine_stock", "vaccine_stock__country")


class RoundAdminInline(admin.TabularInline):
model = Round
extra = 0
Expand Down
26 changes: 16 additions & 10 deletions plugins/polio/management/commands/add_stock_history.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from django.core.management.base import BaseCommand
from datetime import timedelta
from iaso.management.commands.command_logger import CommandLogger
from plugins.polio.models import Round, VaccineStock
from logging import getLogger
from django.db.models import Q

from plugins.polio.models.base import VACCINES, VaccineStockHistory
from plugins.polio.tasks.archive_vaccine_stock_for_rounds import archive_stock_for_round

Expand All @@ -15,20 +13,28 @@ class Command(BaseCommand):
help = """Compute stock history and add it when missing"""

def handle(self, *args, **options):
rounds_to_update = Round.objects.filter(
vaccinerequestform__isnull=False, vaccinerequestform__deleted_at__isnull=True
).order_by("ended_at")
rounds_to_update = (
Round.objects.filter(vaccinerequestform__isnull=False, vaccinerequestform__deleted_at__isnull=True)
.select_related("campaign__country")
.order_by("ended_at")
)

vaccines = [v[0] for v in VACCINES]

for vaccine in vaccines:
rounds_for_vaccine = rounds_to_update.filter(
(Q(campaign__separate_scopes_per_round=False) & Q(campaign__scopes__vaccine=vaccine))
| (Q(campaign__separate_scopes_per_round=True) & Q(scopes__vaccine=vaccine))
).exclude(id__in=VaccineStockHistory.objects.filter(vaccine_stock__vaccine=vaccine).values("round_id"))
vaccine_stock = VaccineStock.objects.filter(vaccine=vaccine)
)
for round_to_update in rounds_for_vaccine:
reference_date = round_to_update.ended_at + timedelta(days=14)
archive_stock_for_round(
round=round_to_update, vaccine_stock=vaccine_stock, reference_date=reference_date
vaccine_stock_qs = VaccineStock.objects.filter(
vaccine=vaccine, country=round_to_update.campaign.country
)
vaccine_stock = vaccine_stock_qs.first()
# If vaccine stock is None, archived_round will be empty
archived_round = VaccineStockHistory.objects.filter(vaccine_stock=vaccine_stock, round=round_to_update)
if not archived_round.exists():
reference_date = round_to_update.ended_at + timedelta(days=14)
archive_stock_for_round(
round=round_to_update, vaccine_stock=vaccine_stock_qs, reference_date=reference_date
)
4 changes: 2 additions & 2 deletions plugins/polio/tasks/archive_vaccine_stock_for_rounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

def archive_stock_for_round(round, vaccine_stock, reference_date, country=None):
vaccine_stock_for_vaccine = vaccine_stock
if not country:
vaccine_stock_for_vaccine = vaccine_stock_for_vaccine.filter(country=round.campaign.country.id)

if vaccine_stock_for_vaccine.exists():
if not country:
vaccine_stock_for_vaccine = vaccine_stock_for_vaccine.filter(country=round.campaign.country.id)
vaccine_stock_for_vaccine = vaccine_stock_for_vaccine.first()
calculator = VaccineStockCalculator(vaccine_stock_for_vaccine)
total_usable_vials_in, total_usable_doses_in = calculator.get_total_of_usable_vials(reference_date)
Expand Down
41 changes: 34 additions & 7 deletions plugins/wfp/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
from django.contrib import admin

from .models import (
Beneficiary,
Journey,
Step,
Visit,
)
from .models import Beneficiary, Journey, Step, Visit, MonthlyStatistics


@admin.register(Beneficiary)
Expand Down Expand Up @@ -33,10 +27,12 @@ class JourneyAdmin(admin.ModelAdmin):
"instance_id",
"beneficiary",
)
raw_id_fields = ["beneficiary"]
list_filter = (
"admission_criteria",
"admission_type",
"nutrition_programme",
"beneficiary__gender",
"programme_type",
"start_date",
"end_date",
Expand All @@ -56,3 +52,34 @@ class VisitAdmin(admin.ModelAdmin):
class StepAdmin(admin.ModelAdmin):
list_display = ("id", "assistance_type", "quantity_given", "visit")
list_filter = ("assistance_type", "visit__journey__programme_type", "visit__journey__beneficiary__account")


@admin.register(MonthlyStatistics)
class MonthlyStatisticsAdmin(admin.ModelAdmin):
list_filter = (
"account",
"month",
"gender",
"admission_criteria",
"admission_type",
"nutrition_programme",
"programme_type",
"exit_type",
)
list_display = (
"id",
"org_unit",
"account",
"month",
"year",
"gender",
"admission_criteria",
"admission_type",
"nutrition_programme",
"programme_type",
"exit_type",
"number_visits",
"given_sachet_rusf",
"given_sachet_rutf",
"given_quantity_csb",
)
Loading

0 comments on commit 16c3da9

Please sign in to comment.