def test_award_update_assistance_executive_comp(): """Test executive comp is loaded correctly awards from txn contract.""" award = mommy.make("awards.Award", generated_unique_award_id="ASST_ONE") txn = mommy.make("awards.TransactionNormalized", award=award, action_date="2011-10-01", unique_award_key="ASST_ONE") txn2 = mommy.make( "awards.TransactionNormalized", award=award, action_date="2012-10-01", unique_award_key="ASST_ONE" ) mommy.make( "awards.TransactionFABS", transaction=txn, officer_1_name="Professor Plum", officer_1_amount=1, officer_2_name="Mrs. White", officer_2_amount=2, officer_3_name="Mrs. Peacock", officer_3_amount=3, officer_4_name="Mr. Green", officer_4_amount=4, officer_5_name="Colonel Mustard", officer_5_amount=5, unique_award_key="ASST_ONE", ) mommy.make( "awards.TransactionFABS", transaction=txn2, officer_1_name="Jack Mustard", officer_1_amount=100, officer_2_name="Jacob Green", officer_2_amount=200, officer_3_name="Diane White", officer_3_amount=300, officer_4_name="Kasandra Scarlet", officer_4_amount=400, officer_5_name="Victor Plum", officer_5_amount=500, unique_award_key="ASST_ONE", ) update_assistance_awards() award.refresh_from_db() assert award.officer_1_name == "Jack Mustard" assert award.officer_5_amount == 500 # Test that a newer transaction without Executive Comp data doesn't overwrite the award values txn3 = mommy.make( "awards.TransactionNormalized", award=award, action_date="2013-10-01", unique_award_key="ASST_ONE" ) mommy.make("awards.TransactionFABS", transaction=txn3, unique_award_key="ASST_ONE") update_assistance_awards() award.refresh_from_db() assert award.officer_1_name == "Jack Mustard" assert award.officer_5_amount == 500
def handle(self, *args, **options): logger.info("Starting historical data load...") db_cursor = connections["data_broker"].cursor() fiscal_year = options.get("fiscal_year") page = options.get("page") limit = options.get("limit") if fiscal_year: fiscal_year = fiscal_year[0] logger.info("Processing data for Fiscal Year " + str(fiscal_year)) else: fiscal_year = 2017 page = page[0] if page else 1 limit = limit[0] if limit else 500000 if not options["assistance"]: with timer("D1 historical data load", logger.info): self.update_transaction_contract(db_cursor=db_cursor, fiscal_year=fiscal_year, page=page, limit=limit) if not options["contracts"]: with timer("D2 historical data load", logger.info): self.update_transaction_assistance(db_cursor=db_cursor, fiscal_year=fiscal_year, page=page, limit=limit) with timer( "updating awards to reflect their latest associated transaction info", logger.info): update_awards(tuple(award_update_id_list)) with timer( "updating assistance-specific awards to reflect their latest transaction info", logger.info): update_assistance_awards(tuple(award_assistance_update_id_list)) with timer( "updating contract-specific awards to reflect their latest transaction info", logger.info): update_contract_awards(tuple(award_contract_update_id_list)) # Done! logger.info("FINISHED")
def upsert_fabs_transactions(ids_to_upsert, externally_updated_award_ids): if ids_to_upsert or externally_updated_award_ids: update_award_ids = copy(externally_updated_award_ids) if ids_to_upsert: with timer("inserting new FABS data", logger.info): update_award_ids.extend(insert_all_new_fabs(ids_to_upsert)) if update_award_ids: update_award_ids = tuple(set( update_award_ids)) # Convert to tuple and remove duplicates. with timer( "updating awards to reflect their latest associated transaction info", logger.info): award_record_count = update_awards(update_award_ids) logger.info( "{} awards updated from their transactional data".format( award_record_count)) with timer("updating awards with executive compensation data", logger.info): award_record_count = update_assistance_awards(update_award_ids) logger.info( "{} awards updated FABS-specific and exec comp data". format(award_record_count)) with timer("updating C->D linkages", logger.info): update_c_to_d_linkages("assistance") else: logger.info("Nothing to insert...")