def test_find_entity_version(self): search_date = factory.fuzzy.FuzzyDate(datetime.date(2015, 1, 1), datetime.date(2015, 12, 30)).fuzz() self.assertEqual(entity_version.find("ENTITY_V_0", search_date), self.entity_versions[0]) self.assertEqual(entity_version.find("ENTITY_V_1", search_date), self.entity_versions[1]) self.assertEqual(entity_version.find("NOT_EXISTING_ENTITY", search_date), None) ev = entity_version.find_by_id(self.entity_versions[0].id) self.assertEqual(ev, self.entity_versions[0]) self.assertEqual(str(ev), str(self.entity_versions[0])) self.assertIsNone(entity_version.find_by_id(None))
def save_address_from_entity(off_year, entity_version_id_selected, email): entity_id = entity_version.find_by_id(entity_version_id_selected).entity_id entity_id_mapped_with_type = get_map_entity_with_offer_year_entity_type(off_year) entity_address_choice = entity_id_mapped_with_type.get(entity_id) new_address = score_sheet_address.ScoreSheetAddress(offer_year=off_year, entity_address_choice=entity_address_choice, email=email) address = score_sheet_address.get_from_offer_year(off_year) if address: new_address.id = address.id new_address.save()
def get_entity_address(request, entity_version_id): version = entity_version_mdl.find_by_id(entity_version_id) entity = version.entity response = { 'entity_version_exists_now': version.exists_now(), 'recipient': '{} - {}'.format(version.acronym, version.title), 'address': {} } if entity and entity.has_address(): response['address'] = {'location': entity.location, 'postal_code': entity.postal_code, 'city': entity.city, 'country_id': entity.country_id, 'phone': entity.phone, 'fax': entity.fax, } return JsonResponse(response)