Skip to content

Commit

Permalink
Merge pull request #545 from unicef/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
robertavram authored Mar 6, 2017
2 parents a6f4828 + 94329d0 commit 93829ab
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 38 deletions.
5 changes: 2 additions & 3 deletions EquiTrack/EquiTrack/scripts/migrate_trips_to_travel.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,11 @@ def migrate_trips(country):


def migrate_trips_all_countries():
for country in Country.objects.all():
for country in Country.objects.order_by('name').all():
if country.name in ["Global"]:
continue

print("Migrating trips for: '%s'" % country.name)
migrate_trips(country.name)
migrate_trips(country)


def migrate_trips_for(country_name):
Expand Down
26 changes: 7 additions & 19 deletions EquiTrack/partners/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.contrib.auth.models import User, Group
from django.contrib.postgres.fields import JSONField, ArrayField
from django.db import models, connection, transaction
from django.db.models import Q, Sum
from django.db.models import Q, Sum, F
from django.db.models.signals import post_save, pre_delete
from django.utils.translation import ugettext as _
from django.utils.functional import cached_property
Expand Down Expand Up @@ -635,12 +635,11 @@ def programmatic_visits(cls, partner, update_one=False):
if update_one:
pv += 1
else:
travelers = Travel.objects.filter(status__in=[Travel.COMPLETED]).values_list('traveler', flat=True)
pv = TravelActivity.objects.filter(
travel_type=TravelType.PROGRAMME_MONITORING,
travels__traveler=F('primary_traveler'),
travels__status__in=[Travel.COMPLETED],
partner=partner,
primary_traveler__in=travelers
).count() or 0

partner.hact_values['programmatic_visits'] = pv
Expand All @@ -655,30 +654,19 @@ def spot_checks(cls, partner, update_one=False):
if update_one:
sc += 1
else:
travelers = Travel.objects.filter(status__in=[Travel.COMPLETED]).values_list('traveler', flat=True)
sc = TravelActivity.objects.filter(
travel_type=TravelType.SPOT_CHECK,
travels__traveler=F('primary_traveler'),
travels__status__in=[Travel.COMPLETED],
partner=partner,
primary_traveler__in=travelers
).count() or 0

partner.hact_values['spot_checks'] = sc
partner.save()

@classmethod
def follow_up_flags(cls, partner, action_point=None):
follow_ups = len([
action for trip in partner.trips
for action in trip.actionpoint_set.filter(
completed_date__isnull=True
)
if action.follow_up
])
if action_point and action_point.completed_date is None and action_point.follow_up:
follow_ups += 1

partner.hact_values['follow_up_flags'] = follow_ups
def follow_up_flags(cls, partner, update_one=False):
partner.hact_values['follow_up_flags'] = 0
partner.save()

@classmethod
Expand Down Expand Up @@ -1398,7 +1386,7 @@ def __unicode__(self):
def days_from_submission_to_signed(self):
if not self.submission_date:
return u'Not Submitted'
if not self.signed_by_unicef_date or self.signed_by_partner_date:
if not self.signed_by_unicef_date or not self.signed_by_partner_date:
return u'Not fully signed'
signed_date = max([self.signed_by_partner_date, self.signed_by_unicef_date])
return relativedelta(signed_date - self.submission_date).days
Expand All @@ -1407,7 +1395,7 @@ def days_from_submission_to_signed(self):
def days_from_review_to_signed(self):
if not self.review_date_prc:
return u'Not Reviewed'
if not self.signed_by_unicef_date or self.signed_by_partner_date:
if not self.signed_by_unicef_date or not self.signed_by_partner_date:
return u'Not fully signed'
signed_date = max([self.signed_by_partner_date, self.signed_by_unicef_date])
return relativedelta(signed_date - self.review_date_prc).days
Expand Down
6 changes: 5 additions & 1 deletion EquiTrack/partners/views/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ def get(self, request):
"""
Return All dropdown values used for Agreements form
"""
signed_by_unicef = list(models.User.objects.filter(groups__name__in=['Senior Management Team']).values('id', 'first_name', 'last_name', 'email'))
signed_by_unicef = list(models.User.objects.filter(groups__name__in=['Senior Management Team'],
profile__country=request.tenant).values('id',
'first_name',
'last_name',
'email'))
hrps = list(ResultStructure.objects.values())
current_country_programme = CountryProgramme.current()
cp_outputs = list(Result.objects.filter(result_type__name=ResultType.OUTPUT, wbs__isnull=False,
Expand Down
35 changes: 32 additions & 3 deletions EquiTrack/t2f/tests/test_travel_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_list_view(self):
self.assertKeysIn(expected_keys, travel_data)

def test_dashboard_travels_list_view(self):
with self.assertNumQueries(12):
with self.assertNumQueries(10):
response = self.forced_auth_req(
'get',
reverse(
Expand All @@ -70,8 +70,37 @@ def test_dashboard_travels_list_view(self):
self.assertEqual(len(response_json['travels_by_section']), 1)
self.assertEqual(response_json['planned'], 1)

def test_dashboard_travels_list_view_no_section(self):
travel = TravelFactory(reference_number=make_travel_reference_number(),
traveler=self.traveler,
supervisor=self.unicef_staff,
section=None)

with self.assertNumQueries(10):
response = self.forced_auth_req(
'get',
reverse(
't2f:travels:list:dashboard',
kwargs={
"year": travel.start_date.year,
"month": '{month:02d}'.format(month=travel.start_date.month),
}
),
user=self.unicef_staff,
data={"office_id": travel.office.id}
)

response_json = json.loads(response.rendered_content)

self.assertEqual(response.status_code, status.HTTP_200_OK)
expected_keys = ['travels_by_section', 'completed', 'planned', 'approved']
self.assertKeysIn(expected_keys, response_json)
self.assertEqual(response_json['travels_by_section'][0]['section_name'], 'No Section selected')
self.assertEqual(len(response_json['travels_by_section']), 1)
self.assertEqual(response_json['planned'], 1)

def test_dashboard_action_points_list_view(self):
with self.assertNumQueries(8):
with self.assertNumQueries(6):
response = self.forced_auth_req(
'get',
reverse('t2f:action_points:dashboard'),
Expand All @@ -88,7 +117,7 @@ def test_dashboard_action_points_list_view(self):
self.assertEqual(response_json['action_points_by_section'][0]['total_action_points'], 1)

def test_dashboard_action_points_list_view_no_office(self):
with self.assertNumQueries(8):
with self.assertNumQueries(6):
response = self.forced_auth_req(
'get',
reverse('t2f:action_points:dashboard'),
Expand Down
10 changes: 6 additions & 4 deletions EquiTrack/t2f/views/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ def list(self, request, year, month, **kwargs):
planned = travels.filter(status=Travel.PLANNED).count()
approved = travels.filter(status=Travel.APPROVED).count()
completed = travels.filter(status=Travel.COMPLETED).count()
section = travels.first().section
section_trips = {
"section_id": travels.first().section.id,
"section_name": travels.first().section.name,
"section_id": section.id if section else None,
"section_name": section.name if section else "No Section selected",
"planned_travels": planned,
"approved_travels": approved,
"completed_travels": completed,
Expand Down Expand Up @@ -69,9 +70,10 @@ def list(self, request, **kwargs):
action_points = ActionPoint.objects.filter(travel__in=travels)
total = action_points.count()
completed = action_points.filter(status=Travel.COMPLETED).count()
section = travels.first().section
section_action_points = {
"section_id": travels.first().section.id,
"section_name": travels.first().section.name,
"section_id": section.id if section else None,
"section_name": section.name if section else "No Section selected",
"total_action_points": total,
"completed_action_points": completed,
}
Expand Down
8 changes: 4 additions & 4 deletions EquiTrack/templates/partners/pca_pdf.html
Original file line number Diff line number Diff line change
Expand Up @@ -1060,10 +1060,10 @@
supplies and equipment transferred by UNICEF to IP: (a) are not used to provide support to
individuals or entities associated with terrorism; (b) are not transferred by the IP to any
individual or entity on the UN Security Council Committee Consolidated List available at
http://www.un.org/sc/committees/consolidated_list.shtml; and (c) are not used, in the case of money,
for the purpose of any payment to persons or entities, or for any import of goods, if such payment
or import is prohibited by a decision of the United Nations Security Council taken under Chapter VII
of the Charter of the United Nations.
https://www.un.org/sc/suborg/en/sanctions/un-sc-consolidated-list; and (c) are not used, in the case
of money, for the purpose of any payment to persons or entities, or for any import of goods, if such
payment or import is prohibited by a decision of the United Nations Security Council taken under
Chapter VII of the Charter of the United Nations.
</li>

</ol>
Expand Down
4 changes: 2 additions & 2 deletions EquiTrack/vision/adapters/partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
}

cso_type_mapping = {
"International NGO ": u'International',
"National NGO ": u'National',
"International NGO": u'International',
"National NGO": u'National',
"Community based organization": u'Community Based Organization',
"Academic Institution": u'Academic Institution'
}
Expand Down
7 changes: 5 additions & 2 deletions EquiTrack/vision/adapters/publics_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def _convert_records(self, records):

def _save_records(self, records):
records = records['ROWSET']['ROW']
records = self._filter_records(records)
processed = 0

for row in records:
Expand All @@ -101,6 +102,10 @@ def _save_records(self, records):
travel_agent = TravelAgent(code=vendor_code)
log.debug('Travel agent created with code %s', vendor_code)

travel_expense_type, _ = TravelExpenseType.objects.get_or_create(vendor_number=vendor_code,
defaults={'title': name})

travel_agent.expense_type = travel_expense_type
travel_agent.name = name
travel_agent.city = city

Expand All @@ -124,8 +129,6 @@ def _save_records(self, records):
travel_agent.save()
log.info('Travel agent %s saved.', travel_agent.name)

TravelExpenseType.objects.get_or_create(vendor_number=vendor_code, is_travel_agent=True,
defaults={'title': name})

return processed

Expand Down

0 comments on commit 93829ab

Please sign in to comment.