Exemple #1
0
    def test_grant(self):
        instance = PublicsGrantFactory.build(name='xyz')
        self.assertEqual(str(instance), u'xyz')

        # Ost (East)
        instance = PublicsGrantFactory.build(name=u'\xd6st')
        self.assertEqual(str(instance), u'\xd6st')
    def test_endpoint(self):
        # This line is duplicated on purpose. Currency will have always 1+N number of queries
        # because of the exchange rate
        factory.build_batch(PublicsCurrencyFactory, 4)

        # Create one of each model to check if all serializers are working fine
        PublicsAirlineCompanyFactory()
        country = PublicsCountryFactory(currency=None)
        PublicsDSARegionFactory(country=country)
        PublicsBusinessAreaFactory()
        PublicsWBSFactory(business_area=None)
        PublicsGrantFactory()
        PublicsFundFactory()
        PublicsTravelExpenseTypeFactory()

        with self.assertNumQueries(11):
            response = self.forced_auth_req('get',
                                            reverse('publics:static'),
                                            user=self.unicef_staff)

        response_json = json.loads(response.rendered_content)
        self.assertKeysIn([
            'currencies', 'travel_types', 'countries', 'airlines',
            'travel_modes', 'expense_types', 'business_areas'
        ],
                          response_json,
                          exact=True)
Exemple #3
0
    def prepare_travel(self):
        # Currencies
        huf = PublicsCurrencyFactory(name='HUF', code='huf')

        # Add wbs/grant/fund
        wbs_1 = PublicsWBSFactory(name='WBS #1')
        grant_1 = PublicsGrantFactory(name='Grant #1')
        wbs_1.grants.add(grant_1)
        fund_1 = PublicsFundFactory(name='Fund #1')
        grant_1.funds.add(fund_1)

        dsa_region = PublicsDSARegionFactory()
        PublicsDSARateFactory(region=dsa_region)

        # Expense types
        et_t_food = PublicsTravelExpenseTypeFactory(
            title='Food',
            vendor_number=TravelExpenseType.USER_VENDOR_NUMBER_PLACEHOLDER
        )

        # Make a travel
        travel = Travel.objects.create(traveler=self.traveler,
                                       supervisor=self.unicef_staff,
                                       currency=huf)

        # Add expenses
        Expense.objects.create(travel=travel,
                               type=et_t_food,
                               currency=huf,
                               amount=35)

        ItineraryItemFactory(travel=travel,
                             departure_date=datetime(2017, 5, 10, tzinfo=UTC),
                             arrival_date=datetime(2017, 5, 11, tzinfo=UTC),
                             dsa_region=dsa_region)
        ItineraryItemFactory(travel=travel,
                             departure_date=datetime(2017, 5, 20, tzinfo=UTC),
                             arrival_date=datetime(2017, 5, 21, tzinfo=UTC),
                             dsa_region=dsa_region)

        # Add cost assignments
        CostAssignment.objects.create(travel=travel,
                                      share=100,
                                      wbs=wbs_1,
                                      grant=grant_1,
                                      fund=fund_1)

        return travel
 def setUp(self):
     self.grant = PublicsGrantFactory()
     self.fund = PublicsFundFactory()
     self.data = {
         "WBS_ELEMENT_EX": "666/987",
         "FUND": {"FUND_ROW": [
             {"GRANT_NBR": "123", "FUND_TYPE_CODE": "321"},
         ]}
     }
     self.expected_data = {
         "wbs": self.data["WBS_ELEMENT_EX"],
         "grants": [
             {"grant_name": "123", "fund_type": "321"}
         ]
     }
     self.adapter = adapter.CostAssignmentSynch(self.country)
Exemple #5
0
    def setUp(self):
        super(InvoiceMaking, self).setUp()
        self.unicef_staff = UserFactory(is_staff=True)
        self.traveler = UserFactory()

        profile = self.traveler.profile
        profile.vendor_number = 'user0001'
        profile.save()

        country = profile.country
        country.business_area_code = '0060'
        country.save()

        dsa_region = PublicsDSARegionFactory()
        PublicsDSARateFactory(region=dsa_region)

        # Currencies
        self.huf = PublicsCurrencyFactory(name='HUF', code='huf')
        self.usd = PublicsCurrencyFactory(name='USD', code='usd')

        # Add wbs/grant/fund
        self.wbs_1 = PublicsWBSFactory(name='WBS #1')
        self.wbs_2 = PublicsWBSFactory(name='WBS #2')

        self.grant_1 = PublicsGrantFactory(name='Grant #1')
        self.grant_2 = PublicsGrantFactory(name='Grant #2')
        self.grant_3 = PublicsGrantFactory(name='Grant #3')

        self.wbs_1.grants.add(self.grant_1)
        self.wbs_2.grants.add(self.grant_2, self.grant_3)

        self.fund_1 = PublicsFundFactory(name='Fund #1')
        self.fund_2 = PublicsFundFactory(name='Fund #4')

        self.grant_1.funds.add(self.fund_1)
        self.grant_3.funds.add(self.fund_2)

        # Expense types
        self.et_t_food = PublicsTravelExpenseTypeFactory(
            title='Food',
            vendor_number=TravelExpenseType.USER_VENDOR_NUMBER_PLACEHOLDER)
        self.et_t_travel = PublicsTravelExpenseTypeFactory(
            title='Travel',
            vendor_number=TravelExpenseType.USER_VENDOR_NUMBER_PLACEHOLDER)
        self.et_t_other = PublicsTravelExpenseTypeFactory(
            title='Other',
            vendor_number=TravelExpenseType.USER_VENDOR_NUMBER_PLACEHOLDER)

        self.et_a_nico = PublicsTravelExpenseTypeFactory(
            title='Nico Travel', vendor_number='a_nico')
        self.et_a_torben = PublicsTravelExpenseTypeFactory(
            title='Torben Travel', vendor_number='a_torben')

        # Make a travel
        self.travel = Travel.objects.create(traveler=self.traveler,
                                            supervisor=self.unicef_staff,
                                            currency=self.huf)

        ItineraryItemFactory(travel=self.travel,
                             departure_date=datetime(2017, 5, 10, tzinfo=UTC),
                             arrival_date=datetime(2017, 5, 11, tzinfo=UTC),
                             dsa_region=dsa_region)
        ItineraryItemFactory(travel=self.travel,
                             departure_date=datetime(2017, 5, 20, tzinfo=UTC),
                             arrival_date=datetime(2017, 5, 21, tzinfo=UTC),
                             dsa_region=dsa_region)
Exemple #6
0
    def test_invoice_export(self):
        # Setting up initial data
        wbs_1 = PublicsWBSFactory(name='2060/A0/12/1222')
        wbs_2 = PublicsWBSFactory(name='2060/A0/12/1214')

        grant_1 = PublicsGrantFactory(name='SM130147')
        grant_2 = PublicsGrantFactory(name='SM130952')

        fund_1 = PublicsFundFactory(name='BMA')
        fund_2 = PublicsFundFactory(name='NON-GRANT')

        wbs_1.grants.add(grant_1)
        wbs_2.grants.add(grant_2)

        grant_1.funds.add(fund_1)
        grant_2.funds.add(fund_2)

        usd = PublicsCurrencyFactory(name='USD', code='usd')

        # Setting up test data
        travel_1 = TravelFactory(traveler=self.traveler, supervisor=self.unicef_staff)
        travel_2 = TravelFactory(traveler=self.traveler, supervisor=self.unicef_staff)

        # Successful invoice
        invoice_1 = InvoiceFactory(travel=travel_1,
                                   currency=usd,
                                   business_area='2060',
                                   status=Invoice.SUCCESS,
                                   vendor_number='100009998',
                                   amount=Decimal('1232.12'),
                                   vision_fi_id='FI12345',
                                   messages=['Payment was made.'])

        InvoiceItemFactory(invoice=invoice_1,
                           wbs=wbs_1,
                           grant=grant_1,
                           fund=fund_1,
                           amount=Decimal('1232.12'))

        # Failed invoice
        invoice_2 = InvoiceFactory(travel=travel_1,
                                   currency=usd,
                                   business_area='2060',
                                   status=Invoice.ERROR,
                                   vendor_number='100009998',
                                   amount=Decimal('123'),
                                   messages=['Payment failed. Not enough money'])

        InvoiceItemFactory(invoice=invoice_2,
                           wbs=wbs_1,
                           grant=grant_1,
                           fund=fund_1,
                           amount=Decimal('123'))

        # 2 item invoice
        invoice_3 = InvoiceFactory(travel=travel_2,
                                   currency=usd,
                                   business_area='2060',
                                   status=Invoice.PROCESSING,
                                   vendor_number='12343424',
                                   amount=Decimal('1919.11'))

        InvoiceItemFactory(invoice=invoice_3,
                           wbs=wbs_1,
                           grant=grant_1,
                           fund=fund_1,
                           amount=Decimal('1000'))

        InvoiceItemFactory(invoice=invoice_3,
                           wbs=wbs_2,
                           grant=grant_2,
                           fund=fund_2,
                           amount=Decimal('919.11'))

        with self.assertNumQueries(1):
            response = self.forced_auth_req('get', reverse('t2f:travels:list:invoice_export'),
                                            user=self.unicef_staff)
        export_csv = csv.reader(StringIO(response.content.decode('utf-8')))
        rows = [r for r in export_csv]

        self.assertEqual(len(rows), 5)

        self.assertEqual(rows[0],
                         ['reference_number',
                          'ta_number',
                          'vendor_number',
                          'currency',
                          'total_amount',
                          'status',
                          'message',
                          'vision_fi_doc',
                          'wbs',
                          'grant',
                          'fund',
                          'amount'])

        self.assertEqual(rows[1],
                         ['2060/{}/1/01'.format(datetime.now().year),
                          '{}/1'.format(datetime.now().year),
                          '100009998',
                          'USD',
                          '1232.1200',
                          'success',
                          'Payment was made.',
                          'FI12345',
                          '2060/A0/12/1222',
                          'SM130147',
                          'BMA',
                          '1232.1200'])

        self.assertEqual(rows[2],
                         ['2060/{}/1/02'.format(datetime.now().year),
                          '{}/1'.format(datetime.now().year),
                          '100009998',
                          'USD',
                          '123.0000',
                          'error',
                          'Payment failed. Not enough money',
                          '',
                          '2060/A0/12/1222',
                          'SM130147',
                          'BMA',
                          '123.0000'])

        self.assertEqual(rows[3],
                         ['2060/{}/2/01'.format(datetime.now().year),
                          '{}/2'.format(datetime.now().year),
                          '12343424',
                          'USD',
                          '1919.1100',
                          'processing',
                          '',
                          '',
                          '2060/A0/12/1222',
                          'SM130147',
                          'BMA',
                          '1000.0000'])

        self.assertEqual(rows[4],
                         ['2060/{}/2/01'.format(datetime.now().year),
                          '{}/2'.format(datetime.now().year),
                          '12343424',
                          'USD',
                          '1919.1100',
                          'processing',
                          '',
                          '',
                          '2060/A0/12/1214',
                          'SM130952',
                          'NON-GRANT',
                          '919.1100'])