Skip to content

Commit

Permalink
Merge branch '33354-unicef-cash-unfunded' of github.com:unicef/etools…
Browse files Browse the repository at this point in the history
… into ch33354-UNICEF-cash-unfunded

# Conflicts:
#	src/etools/applications/partners/locale/ar/LC_MESSAGES/django.po
#	src/etools/applications/partners/locale/es/LC_MESSAGES/django.mo
#	src/etools/applications/partners/locale/es/LC_MESSAGES/django.po
#	src/etools/applications/partners/locale/fr/LC_MESSAGES/django.mo
#	src/etools/applications/partners/locale/fr/LC_MESSAGES/django.po
#	src/etools/applications/partners/locale/pt/LC_MESSAGES/django.mo
#	src/etools/applications/partners/locale/pt/LC_MESSAGES/django.po
#	src/etools/applications/partners/locale/ru/LC_MESSAGES/django.mo
#	src/etools/applications/partners/locale/ru/LC_MESSAGES/django.po
#	src/etools/applications/partners/models.py
#	src/etools/applications/reports/models.py
  • Loading branch information
emaciupe committed Jun 7, 2023
2 parents ab4ef1b + 2950de3 commit 6685a33
Show file tree
Hide file tree
Showing 127 changed files with 4,539 additions and 1,230 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ unicef-djangolib = "==0.5.4"
unicef-locations = "==4.0.1"
unicef-notification = "==1.1"
unicef-restlib = "==0.7"
unicef-snapshot = "==1.1"
unicef-snapshot = "==1.3"
unicef-rest-export = "==0.5.3"
xhtml2pdf = "==0.2.5"
unicef-vision = "==0.6"
Expand Down
6 changes: 3 additions & 3 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.12.1'
VERSION = __version__ = '10.1.1'
NAME = 'eTools'
2 changes: 1 addition & 1 deletion src/etools/applications/audit/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class EngagementAdmin(admin.ModelAdmin):
list_display = [
'__str__', 'status', 'partner', 'date_of_field_visit',
'engagement_type', 'start_date', 'end_date',
'engagement_type', 'start_date', 'end_date', 'year_of_audit',
]
list_filter = [
'status', 'start_date', 'end_date', 'status', 'engagement_type',
Expand Down
6 changes: 3 additions & 3 deletions src/etools/applications/audit/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def is_satisfied(self):
return self.user in self.engagement.staff_members.all()


class IsStaffMemberCondition(SimpleCondition):
predicate = 'user.is_staff'
class IsUnicefUserCondition(SimpleCondition):
predicate = 'user.is_unicef_user'

def __init__(self, user):
self.user = user

def is_satisfied(self):
return self.user.is_staff
return self.user.is_unicef_user()
11 changes: 10 additions & 1 deletion src/etools/applications/audit/exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,16 @@ def labels(self):
),
RiskCategory.objects.get(code='ma_questionnaire', parent__isnull=True).children.all()
)):
labels['questionnaire.{}'.format(blueprint.id)] = blueprint.header
labels['questionnaire.{}'.format(blueprint.id)] = "Questionnaire v1 - {}".format(blueprint.header)

for blueprint in itertools.chain(*map(
lambda c: itertools.chain(
itertools.chain(*map(lambda sc: sc.blueprints.all(), c.children.all())),
c.blueprints.all()
),
RiskCategory.objects.get(code='ma_questionnaire_v2', parent__isnull=True).children.all()
)):
labels['questionnaire_v2.{}'.format(blueprint.id)] = "Questionnaire v2 - {}".format(blueprint.header)

return labels

Expand Down
1 change: 1 addition & 0 deletions src/etools/applications/audit/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Meta:
'date_of_draft_report_to_ip': ['lte', 'gte', 'gt', 'lt'],
'offices': ['exact', 'in'],
'sections': ['exact', 'in'],
'year_of_audit': ['exact', 'in'],
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
AuditModuleCondition,
AuditStaffMemberCondition,
EngagementStaffMemberCondition,
IsStaffMemberCondition,
IsUnicefUserCondition,
)
from etools.applications.audit.models import (
Auditor,
Expand Down Expand Up @@ -77,6 +77,7 @@ class Command(BaseCommand):
'audit.engagement.end_date',
'audit.engagement.total_value',
'audit.engagement.joint_audit',
'audit.engagement.year_of_audit',
'audit.engagement.shared_ip_with',
'audit.engagement.related_agreement',
'audit.engagement.sections',
Expand Down Expand Up @@ -289,10 +290,7 @@ def assign_permissions(self):
self.report_editable_block
)

self.add_permissions([self.focal_point, self.auditor], 'edit', [
'purchase_order.auditorfirm.staff_members',
'purchase_order.auditorstaffmember.*',
] + self.engagement_attachments_block)
self.add_permissions([self.focal_point, self.auditor], 'edit', self.engagement_attachments_block)

self.add_permissions(self.focal_point, 'edit', [
'purchase_order.purchaseorder.contract_end_date',
Expand Down Expand Up @@ -321,11 +319,11 @@ def assign_permissions(self):
self.report_readonly_block,
condition=partner_contacted_condition
)
is_staff_condition = [IsStaffMemberCondition.predicate]
is_unicef_user = [IsUnicefUserCondition.predicate]
self.add_permissions(
self.engagement_staff_auditor, 'edit',
self.users_notified_block,
condition=partner_contacted_condition + is_staff_condition
condition=partner_contacted_condition + is_unicef_user
)
self.add_permissions(
self.engagement_staff_auditor, 'edit',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Generated by Django 3.2.6 on 2023-04-14 07:53

from django.db import migrations, models
from django.db.models import F, Subquery, OuterRef
from django.db.models.functions import Extract
from django.utils import timezone

import etools.applications.audit.models


def fill_year_of_audit(apps, schema_editor):
Engagement = apps.get_model('audit', 'Engagement')
Engagement.objects.filter(
engagement_type='audit',
date_of_draft_report_to_ip__isnull=False,
).update(
year_of_audit=Subquery(
Engagement.objects.filter(
pk=OuterRef('pk')
).annotate(
end_year=Extract("date_of_draft_report_to_ip", "year")
).values('end_year')[:1]
)
)
Engagement.objects.filter(
engagement_type='audit',
date_of_draft_report_to_ip__isnull=True,
).update(
year_of_audit=timezone.now().year,
)


class Migration(migrations.Migration):

dependencies = [
('audit', '0023_auto_20220415_1130'),
]

operations = [
migrations.AddField(
model_name='engagement',
name='year_of_audit',
field=models.PositiveSmallIntegerField(default=1, null=True),
),
migrations.RunPython(fill_year_of_audit, migrations.RunPython.noop),
migrations.AlterField(
model_name='engagement',
name='year_of_audit',
field=models.PositiveSmallIntegerField(default=etools.applications.audit.models.get_current_year, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.2.6 on 2023-04-17 09:36

from django.db import migrations, models
import etools.applications.audit.models


class Migration(migrations.Migration):

dependencies = [
('audit', '0024_audit_year_of_audit'),
]

operations = [
migrations.AlterField(
model_name='engagement',
name='year_of_audit',
field=models.PositiveSmallIntegerField(db_index=True, default=etools.applications.audit.models.get_current_year, null=True),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('audit', '0023_auto_20220415_1130'),
('audit', '0025_alter_engagement_year_of_audit'),
]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Migration(migrations.Migration):
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('users', '0021_migrate_to_realms'),
('purchase_order', '0012_alter_auditorstaffmember_auditor_firm'),
('audit', '0024_alter_engagement_staff_members'),
('audit', '0026_alter_engagement_staff_members'),
]

operations = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 3.2.6 on 2023-04-14 07:53

from django.db import migrations, models
from django.db.models import F, Subquery, OuterRef
from django.db.models.functions import Extract
from django.utils import timezone

import etools.applications.audit.models


def fill_year_of_audit_for_special_audit(apps, schema_editor):
Engagement = apps.get_model('audit', 'Engagement')
Engagement.objects.filter(
engagement_type='sa',
date_of_draft_report_to_ip__isnull=False,
).update(
year_of_audit=Subquery(
Engagement.objects.filter(
pk=OuterRef('pk')
).annotate(
end_year=Extract("date_of_draft_report_to_ip", "year")
).values('end_year')[:1]
)
)
Engagement.objects.filter(
engagement_type='sa',
date_of_draft_report_to_ip__isnull=True,
).update(
year_of_audit=timezone.now().year,
)


class Migration(migrations.Migration):

dependencies = [
('audit', '0027_engagement_staff_members'),
]

operations = [
migrations.RunPython(fill_year_of_audit_for_special_audit, migrations.RunPython.noop),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.6 on 2023-05-15 05:51

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('audit', '0027_engagement_staff_members'),
]

operations = [
migrations.AddField(
model_name='microassessment',
name='questionnaire_version',
field=models.PositiveSmallIntegerField(default=1),
),
migrations.AlterField(
model_name='microassessment',
name='questionnaire_version',
field=models.PositiveSmallIntegerField(default=2),
),
migrations.AlterField(
model_name='riskcategory',
name='header',
field=models.CharField(max_length=500, verbose_name='Header'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 3.2.6 on 2023-05-23 10:49

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('audit', '0028_audit_year_of_audit_recalculate'),
('audit', '0028_auto_20230515_0551'),
]

operations = [
]
15 changes: 14 additions & 1 deletion src/etools/applications/audit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
from etools.libraries.fsm.views import has_action_permission


def get_current_year():
return timezone.now().year


class Engagement(InheritedModelMixin, TimeStampedModel, models.Model):
TYPE_AUDIT = 'audit'
TYPE_MICRO_ASSESSMENT = 'ma'
Expand Down Expand Up @@ -160,6 +164,7 @@ class Engagement(InheritedModelMixin, TimeStampedModel, models.Model):
)

joint_audit = models.BooleanField(verbose_name=_('Joint Audit'), default=False, blank=True)
year_of_audit = models.PositiveSmallIntegerField(null=True, default=get_current_year, db_index=True)
shared_ip_with = ArrayField(models.CharField(
max_length=20, choices=PartnerOrganization.AGENCY_CHOICES
), blank=True, default=list, verbose_name=_('Shared Audit with'))
Expand Down Expand Up @@ -307,7 +312,7 @@ class RiskCategory(OrderedModel, models.Model):
('primary', _('Primary')),
)

header = models.CharField(verbose_name=_('Header'), max_length=255)
header = models.CharField(verbose_name=_('Header'), max_length=500)
parent = models.ForeignKey(
'self', verbose_name=_('Parent'), null=True, blank=True, related_name='children', db_index=True,
on_delete=models.CASCADE,
Expand Down Expand Up @@ -549,6 +554,7 @@ class MicroAssessment(Engagement):
code='micro_assessment_final_report',
blank=True,
)
questionnaire_version = models.PositiveSmallIntegerField(default=2)

objects = models.Manager()

Expand All @@ -561,6 +567,13 @@ def save(self, *args, **kwargs):
self.engagement_type = Engagement.TYPES.ma
return super().save(*args, **kwargs)

@staticmethod
def get_questionnaire_code(version: int):
return {
1: 'ma_questionnaire',
2: 'ma_questionnaire_v2'
}[version]

@transition(
'status',
source=Engagement.STATUSES.partner_contacted, target=Engagement.STATUSES.report_submitted,
Expand Down
7 changes: 7 additions & 0 deletions src/etools/applications/audit/serializers/auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ class Meta(UserSerializer.Meta):
fields = ['id', 'user', 'hidden']


class AuditorStaffMemberRealmSerializer(AuditorStaffMemberSerializer):
has_active_realm = serializers.BooleanField(read_only=True)

class Meta(AuditorStaffMemberSerializer.Meta):
fields = AuditorStaffMemberSerializer.Meta.fields + ['has_active_realm']


class AuditorFirmLightSerializer(PermissionsBasedSerializerMixin, serializers.ModelSerializer):
organization_id = serializers.IntegerField(read_only=True, source='organization.id')

Expand Down
Loading

0 comments on commit 6685a33

Please sign in to comment.