Skip to content

Commit

Permalink
Merge pull request #3221 from unicef/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
ntrncic authored Mar 9, 2022
2 parents 5347f93 + 34e3aac commit 70a63c1
Show file tree
Hide file tree
Showing 110 changed files with 1,750 additions and 1,192 deletions.
6 changes: 3 additions & 3 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ Pillow = "==8.1.0"
psycopg2-binary = "==2.9.1"
sentry-sdk = "*"
requests = "==2.26"
social-auth-app-django = "==4.0"
social-auth-app-django = "==5.0"
social-auth-core = {extras = ["azuread"],version = "==4.1"}
tenant-schemas-celery = "==1.0.1"
unicef-attachments = "==0.9.0"
unicef-attachments = "==0.10.1"
unicef-djangolib = "==0.5.4"
unicef-locations = "==3.0"
unicef-locations = "==3.2.3"
unicef-notification = "==1.1"
unicef-restlib = "==0.7"
unicef-snapshot = "==1.1"
Expand Down
1,274 changes: 764 additions & 510 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/etools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION = __version__ = '9.10.0'
VERSION = __version__ = '9.11.0'
NAME = 'eTools'
1 change: 0 additions & 1 deletion src/etools/applications/action_points/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
default_app_config = __name__ + '.apps.AppConfig'
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
default_app_config = __name__ + '.apps.AppConfig'
4 changes: 2 additions & 2 deletions src/etools/applications/action_points/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import include, url
from django.urls import include, re_path

from rest_framework_nested import routers

Expand All @@ -12,5 +12,5 @@


urlpatterns = [
url(r'^', include(action_points_api.urls)),
re_path(r'^', include(action_points_api.urls)),
]
21 changes: 21 additions & 0 deletions src/etools/applications/attachments/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.contrib import admin

from etools.applications.attachments.models import AttachmentFlat


@admin.register(AttachmentFlat)
class AttachmentAdmin(admin.ModelAdmin):
list_display = [
'partner',
'partner_type',
'vendor_number',
'pd_ssfa',
'pd_ssfa_number',
'agreement_reference_number',
'file_type',
'file_link',
'filename',
'uploaded_by',
'ip_address',
]
list_filter = ['file_type', 'partner', ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.6 on 2021-11-24 00:02

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('attachments', '0018_remove_attachmentflat_created'),
]

operations = [
migrations.AddField(
model_name='attachmentflat',
name='ip_address',
field=models.GenericIPAddressField(default='0.0.0.0'),
),
]
1 change: 1 addition & 0 deletions src/etools/applications/attachments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class AttachmentFlat(models.Model):
verbose_name=_('Created'),
null=True,
)
ip_address = models.GenericIPAddressField(default='0.0.0.0')

objects = AttachmentFlatManager()

Expand Down
1 change: 1 addition & 0 deletions src/etools/applications/attachments/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def assert_keys(self, response):
"created",
"attachment",
"source",
"ip_address"
]
for row in response.data:
self.assertCountEqual(list(row.keys()), expected_keys)
Expand Down
1 change: 1 addition & 0 deletions src/etools/applications/attachments/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def denormalize_attachment(attachment):
"file_link": attachment.file_link,
"filename": attachment.filename,
"uploaded_by": uploaded_by,
"ip_address": attachment.ip_address,
"source": source,
"created": attachment.created,
}
Expand Down
1 change: 0 additions & 1 deletion src/etools/applications/audit/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
default_app_config = __name__ + '.apps.AppConfig'
9 changes: 4 additions & 5 deletions src/etools/applications/audit/exports.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import itertools
from collections import OrderedDict

Expand Down Expand Up @@ -28,7 +27,7 @@ class EngagementCSVRenderer(BaseCSVRenderer):

class SpotCheckDetailCSVRenderer(BaseCSVRenderer):
labels = OrderedDict((
('unique_id', 'Unique ID'),
('reference_number', 'Unique ID'),
('link', 'Hyperlink'),
('auditor', 'Auditor or Staff Assigned'),
('partner', 'IP'),
Expand All @@ -49,7 +48,7 @@ class AuditDetailCSVRenderer(BaseCSVRenderer):
@property
def labels(self):
labels = OrderedDict((
('unique_id', 'Unique ID'),
('reference_number', 'Unique ID'),
('link', 'Hyperlink'),
('auditor', 'Auditor or Staff Assigned'),
('partner', 'IP'),
Expand Down Expand Up @@ -83,7 +82,7 @@ class MicroAssessmentDetailCSVRenderer(BaseCSVRenderer):
@property
def labels(self):
labels = OrderedDict((
('unique_id', 'Unique ID'),
('reference_number', 'Unique ID'),
('link', 'Hyperlink'),
('auditor', 'Auditor or Staff Assigned'),
('partner', 'IP'),
Expand Down Expand Up @@ -115,7 +114,7 @@ def header(self):

class SpecialAuditDetailCSVRenderer(BaseCSVRenderer):
labels = OrderedDict((
('unique_id', 'Unique ID'),
('reference_number', 'Unique ID'),
('link', 'Hyperlink'),
('auditor', 'Auditor or Staff Assigned'),
('partner', 'IP'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Command(BaseCommand):
action_points_editors = [focal_point, action_point_author, action_point_assignee, action_point_assigned_by]

engagement_overview_read_block = [
'audit.engagement.unique_id',
'audit.engagement.reference_number',

'audit.engagement.status',
'audit.engagement.status_date',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('users', '0012_auto_20190513_1804'),
('audit', '0018_auto_20191008_2235'),
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 2.2.3 on 2019-08-14 12:17

from django.db import connection, migrations, models


def set_reference_number(apps, schema_editor):
Country = apps.get_model("users", "country")
Engagement = apps.get_model("audit", "engagement")
country = Country.objects.get(
schema_name=connection.tenant.schema_name,
)
for engagement in Engagement.objects.all():
if engagement.engagement_type == 'audit':
engagement_code = 'a'
else:
engagement_code = engagement.engagement_type
engagement.reference_number = '{}/{}/{}/{}/{}'.format(
country.country_short_code,
engagement.partner.name[:5],
engagement_code.upper(),
engagement.created.year,
engagement.pk
)
engagement.save()


class Migration(migrations.Migration):

dependencies = [
('audit', '0021_auto_20200729_2123'),
]

operations = [
migrations.AddField(
model_name='engagement',
name='reference_number',
field=models.CharField(max_length=100, null=True, verbose_name='Reference Number'),
),
migrations.RunPython(set_reference_number, migrations.RunPython.noop),
]
35 changes: 23 additions & 12 deletions src/etools/applications/audit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ class Engagement(InheritedModelMixin, TimeStampedModel, models.Model):
blank=True,
related_name='engagements',
)
reference_number = models.CharField(
verbose_name=_("Reference Number"),
max_length=100,
null=True,
)

objects = InheritanceManager()

Expand Down Expand Up @@ -222,8 +227,7 @@ def displayed_status_date(self):
def get_shared_ip_with_display(self):
return list(map(lambda po: dict(PartnerOrganization.AGENCY_CHOICES).get(po, 'Unknown'), self.shared_ip_with))

@property
def unique_id(self):
def get_reference_number(self):
engagement_code = 'a' if self.engagement_type == self.TYPES.audit else self.engagement_type
return '{}/{}/{}/{}/{}'.format(
connection.tenant.country_short_code or '',
Expand All @@ -233,15 +237,11 @@ def unique_id(self):
self.id
)

@property
def reference_number(self):
return self.unique_id

def get_mail_context(self, **kwargs):
object_url = self.get_object_url(**kwargs)

return {
'unique_id': self.unique_id,
'unique_id': self.reference_number,
'engagement_type': self.get_engagement_type_display(),
'object_url': object_url,
'partner': force_text(self.partner),
Expand Down Expand Up @@ -293,6 +293,12 @@ def finalize(self):
def get_object_url(self, **kwargs):
return build_frontend_url('ap', 'engagements', self.id, 'overview', **kwargs)

def save(self, *args, **kwargs):
super().save(*args, **kwargs)
if not self.reference_number:
self.reference_number = self.get_reference_number()
self.save()


class RiskCategory(OrderedModel, models.Model):
"""Group of questions"""
Expand Down Expand Up @@ -450,7 +456,6 @@ def submit(self, *args, **kwargs):
@transition('status', source=Engagement.STATUSES.report_submitted, target=Engagement.STATUSES.final,
permission=has_action_permission(action='finalize'))
def finalize(self, *args, **kwargs):
self.partner.update_spot_checks(update_one=True, event_date=self.date_of_draft_report_to_ip)
return super().finalize(*args, **kwargs)

def get_object_url(self, **kwargs):
Expand Down Expand Up @@ -733,7 +738,10 @@ class Meta:
ordering = ('id', )

def __str__(self):
return '{}: {}'.format(self.audit.unique_id, self.get_title_display())
return '{}: {}'.format(
self.audit.reference_number,
self.get_title_display(),
)


class KeyInternalControl(models.Model):
Expand All @@ -751,7 +759,10 @@ class Meta:
ordering = ('id', )

def __str__(self):
return '{}: {}'.format(self.audit.unique_id, self.audit_observation)
return '{}: {}'.format(
self.audit.reference_number,
self.audit_observation,
)


class SpecialAudit(Engagement):
Expand Down Expand Up @@ -823,7 +834,7 @@ class Meta:
verbose_name_plural = _('Specific Procedures')

def __str__(self):
return '{}: {}'.format(self.audit.unique_id, self.description)
return '{}: {}'.format(self.audit.reference_number, self.description)


class SpecialAuditRecommendation(models.Model):
Expand All @@ -840,7 +851,7 @@ class Meta:
verbose_name_plural = _('Special Audit Recommendations')

def __str__(self):
return '{}: {}'.format(self.audit.unique_id, self.description)
return '{}: {}'.format(self.audit.reference_number, self.description)


class EngagementActionPointManager(models.Manager):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{{ action_point.assigned_by }} has assigned you an action point.
Engagement ID: {{ action_point.engagement.unique_id }}
Engagement ID: {{ action_point.engagement.reference_number }}
Due Date: {{ action_point.due_date }}
Link: {{ action_point.engagement.object_url }}
Expand All @@ -25,7 +25,7 @@
{{ action_point.assigned_by }} has assigned you an action point. <br/><br/>
Engagement ID: {{ action_point.engagement.unique_id }}<br/>
Engagement ID: {{ action_point.engagement.reference_number }}<br/>
Due Date: {{ action_point.due_date }}<br/>
Link: <a href="{{ action_point.engagement.object_url }}">click here</a><br/><br/>
Expand Down
1 change: 0 additions & 1 deletion src/etools/applications/audit/purchase_order/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
default_app_config = __name__ + '.apps.AppConfig'
9 changes: 6 additions & 3 deletions src/etools/applications/audit/serializers/engagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class EngagementExportSerializer(serializers.ModelSerializer):
read_only=True
)
status_date = serializers.ReadOnlyField(source='displayed_status_date')
unique_id = serializers.ReadOnlyField()
reference_number = serializers.ReadOnlyField()

class Meta:
model = Engagement
Expand All @@ -187,7 +187,7 @@ class Meta:
'auditor_firm_name',
'status',
'status_date',
'unique_id',
'reference_number',
)


Expand All @@ -209,7 +209,10 @@ class EngagementLightSerializer(serializers.ModelSerializer):
read_only=True
)
status_date = serializers.ReadOnlyField(source='displayed_status_date', label=_('Date of Status'))
unique_id = serializers.ReadOnlyField(label=_('Unique ID'))
unique_id = serializers.ReadOnlyField(
source="reference_number",
label=_('Unique ID'),
)

offices = OfficeLightSerializer(many=True)
sections = SectionSerializer(many=True)
Expand Down
6 changes: 3 additions & 3 deletions src/etools/applications/audit/serializers/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class EngagementPDFSerializer(serializers.ModelSerializer):
partner = PartnerPDFSerializer()
engagement_type_display = serializers.ReadOnlyField(source='get_engagement_type_display')
status_display = serializers.SerializerMethodField()
unique_id = serializers.ReadOnlyField()
reference_number = serializers.ReadOnlyField()
authorized_officers = serializers.SerializerMethodField()
active_pd = serializers.SerializerMethodField()
staff_members = StaffMemberPDFSerializer(many=True)
Expand All @@ -123,7 +123,7 @@ class Meta:
model = Engagement
fields = [
'id', 'agreement', 'partner', 'engagement_type_display', 'engagement_type', 'status_display', 'status',
'unique_id', 'authorized_officers', 'active_pd', 'staff_members', 'po_item',
'reference_number', 'authorized_officers', 'active_pd', 'staff_members', 'po_item',
'date_of_field_visit', 'date_of_draft_report_to_ip', 'date_of_comments_by_ip',
'date_of_draft_report_to_unicef', 'date_of_comments_by_unicef', 'partner_contacted_at',
'action_points', 'engagement_attachments', 'report_attachments',
Expand Down Expand Up @@ -240,7 +240,7 @@ class Meta(EngagementPDFSerializer.Meta):


class EngagementBaseDetailCSVSerializer(serializers.Serializer):
unique_id = serializers.ReadOnlyField()
reference_number = serializers.ReadOnlyField()
link = serializers.ReadOnlyField(source='get_object_url')
auditor = serializers.ReadOnlyField(source='agreement.auditor_firm')
partner = serializers.ReadOnlyField()
Expand Down
2 changes: 1 addition & 1 deletion src/etools/applications/audit/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ def action_point_updated_receiver(instance, created, **kwargs):
if created:
instance.send_email(instance.assigned_to, 'audit/engagement/action_point_assigned',
cc=[instance.assigned_by.email])
else:
elif not instance.tracker.has_changed('reference_number'):
if instance.tracker.has_changed('assigned_to'):
instance.send_email(instance.assigned_to, 'audit/engagement/action_point_assigned')
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
{% else %}
<div id="content">
<div class="view-container">
<div class="main_title">{{ engagement.unique_id }}</div>
<div class="main_title">{{ engagement.reference_number }}</div>
<div class="content-section">
<div class="content-section__header">
<div class="content-section__header__title">Engagement Overview</div>
Expand Down
Loading

0 comments on commit 70a63c1

Please sign in to comment.