def equal_fields(field, obj_field, record_field): if field in [ 'commitment_amount', 'commitment_amount_dc', 'amount_changed' ]: return comp_decimals(obj_field, record_field) if field == 'line_item': return str(obj_field) == record_field return obj_field == record_field
def equal_fields(field, obj_field, record_field): if field in ['overall_amount', 'overall_amount_dc', 'intervention_amt', 'total_amt', 'actual_amt', 'actual_amt_local', 'outstanding_amt', 'outstanding_amt_local']: return comp_decimals(obj_field, record_field) if field == 'line_item': return str(obj_field) == record_field return obj_field == record_field
def equal_fields(field, obj_field, record_field): if field in [ 'overall_amount', 'overall_amount_dc', 'intervention_amt', 'total_amt', 'actual_amt', 'actual_amt_local', 'outstanding_amt', 'outstanding_amt_local' ]: return comp_decimals(obj_field, record_field) if field == 'line_item': return str(obj_field) == record_field return obj_field == record_field
def update_fr_totals(): totals_updated = 0 qs = FundsReservationHeader.objects qs = qs.annotate(my_li_total_sum=Sum('fr_items__overall_amount_dc')) for fr in qs: # Note that Sum() returns None, not 0, if there's nothing to sum. total_li_sum = fr.my_li_total_sum or Decimal('0.00') if not comp_decimals(total_li_sum, fr.total_amt_local): fr.total_amt_local = total_li_sum fr.save() totals_updated += 1 return totals_updated
def equal_fields(field, obj_field, record_field): if field in ['commitment_amount', 'commitment_amount_dc', 'amount_changed']: return comp_decimals(obj_field, record_field) if field == 'line_item': return str(obj_field) == record_field return obj_field == record_field
def test_equal(self): self.assertTrue(utils.comp_decimals(0.2, 0.2))
def test_not_equal(self): self.assertFalse(utils.comp_decimals(0.2, 0.3))
def _partner_save(self, partner, full_sync=True): processed = 0 saving = False notify_block = False try: partner_org, new = PartnerOrganization.objects.get_or_create( vendor_number=partner['VENDOR_CODE']) if not self.get_partner_type(partner): logger.info( 'Partner {} skipped, because PartnerType is {}'.format( partner['VENDOR_NAME'], partner['PARTNER_TYPE_DESC'])) if partner_org.id: partner_org.deleted_flag = True if partner.get( 'MARKED_FOR_DELETION', None) else False partner_org.blocked = True if partner.get( 'POSTING_BLOCK', None) else False partner_org.hidden = True partner_org.save() return processed if new or self._changed_fields(partner_org, partner): partner_org.name = partner['VENDOR_NAME'] partner_org.cso_type = self.get_cso_type(partner) partner_org.rating = self.get_partner_rating(partner) partner_org.type_of_assessment = self.get_type_of_assessment( partner) partner_org.address = partner.get('STREET', '') partner_org.city = partner.get('CITY', '') partner_org.postal_code = partner.get('POSTAL_CODE', '') partner_org.country = partner['COUNTRY'] partner_org.phone_number = partner.get('PHONE_NUMBER', '') partner_org.email = partner.get('EMAIL', '') partner_org.core_values_assessment_date = datetime.strptime( partner['CORE_VALUE_ASSESSMENT_DT'], '%d-%b-%y' ) if 'CORE_VALUE_ASSESSMENT_DT' in partner else None partner_org.last_assessment_date = datetime.strptime( partner['DATE_OF_ASSESSMENT'], '%d-%b-%y') if 'DATE_OF_ASSESSMENT' in partner else None partner_org.partner_type = self.get_partner_type(partner) partner_org.deleted_flag = True if 'MARKED_FOR_DELETION' in partner else False posting_block = True if 'POSTING_BLOCK' in partner else False if posting_block and not partner_org.blocked: # i'm blocking the partner now notify_block = True partner_org.blocked = posting_block partner_org.hidden = partner_org.deleted_flag or partner_org.blocked or partner_org.manually_blocked partner_org.vision_synced = True saving = True if full_sync and ( partner_org.total_ct_cp is None or partner_org.total_ct_cy is None or partner_org.net_ct_cy is None or partner_org.total_ct_ytd is None or partner_org.reported_cy is None or not comp_decimals( partner_org.total_ct_cp, Decimal(partner['TOTAL_CASH_TRANSFERRED_CP'])) or not comp_decimals( partner_org.total_ct_cy, Decimal(partner['TOTAL_CASH_TRANSFERRED_CY'])) or not comp_decimals( partner_org.net_ct_cy, Decimal(partner['NET_CASH_TRANSFERRED_CY'])) or not comp_decimals( partner_org.total_ct_ytd, Decimal(partner['TOTAL_CASH_TRANSFERRED_YTD'])) or not comp_decimals(partner_org.reported_cy, Decimal(partner['REPORTED_CY']))): partner_org.total_ct_cy = partner['TOTAL_CASH_TRANSFERRED_CY'] partner_org.total_ct_cp = partner['TOTAL_CASH_TRANSFERRED_CP'] partner_org.net_ct_cy = partner['NET_CASH_TRANSFERRED_CY'] partner_org.total_ct_ytd = partner[ 'TOTAL_CASH_TRANSFERRED_YTD'] partner_org.reported_cy = partner['REPORTED_CY'] saving = True logger.debug('sums changed', partner_org) if saving: logger.debug('Updating Partner', partner_org) # clear basis_for_risk_rating in certain cases if partner_org.basis_for_risk_rating and ( partner_org.type_of_assessment.upper() in [ PartnerOrganization.HIGH_RISK_ASSUMED, PartnerOrganization.LOW_RISK_ASSUMED ] or (partner_org.rating == PartnerOrganization.RATING_NON_ASSESSED and partner_org.type_of_assessment == PartnerOrganization.MICRO_ASSESSMENT)): partner_org.basis_for_risk_rating = '' partner_org.save() if notify_block: notify_partner_hidden.delay(partner_org.pk, connection.schema_name) if new: PlannedEngagement.objects.get_or_create(partner=partner_org) else: # if date has changed, archive old and create a new one not archived core_value_date = partner_org.core_values_assessment_date if not partner_org.core_values_assessments.filter( date=core_value_date).exists(): partner_org.core_values_assessments.update(archived=True) partner_org.core_values_assessments.create( date=core_value_date, archived=False) processed = 1 except Exception: logger.exception(u'Exception occurred during Partner Sync') return processed
def _partner_save(self, partner, full_sync=True): processed = 0 saving = False notify_block = False try: partner_org, new = PartnerOrganization.objects.get_or_create(vendor_number=partner['VENDOR_CODE']) if not self.get_partner_type(partner): logger.info('Partner {} skipped, because PartnerType is {}'.format( partner['VENDOR_NAME'], partner['PARTNER_TYPE_DESC'] )) if partner_org.id: partner_org.deleted_flag = True if partner.get('MARKED_FOR_DELETION', None) else False partner_org.blocked = True if partner.get('POSTING_BLOCK', None) else False partner_org.hidden = True partner_org.save() return processed if new or self._changed_fields(partner_org, partner): partner_org.name = partner['VENDOR_NAME'] partner_org.cso_type = self.get_cso_type(partner) partner_org.rating = self.get_partner_rating(partner) partner_org.type_of_assessment = self.get_type_of_assessment(partner) partner_org.address = partner.get('STREET', '') partner_org.city = partner.get('CITY', '') partner_org.postal_code = partner.get('POSTAL_CODE', '') partner_org.country = partner['COUNTRY'] partner_org.phone_number = partner.get('PHONE_NUMBER', '') partner_org.email = partner.get('EMAIL', '') partner_org.core_values_assessment_date = datetime.strptime( partner['CORE_VALUE_ASSESSMENT_DT'], '%d-%b-%y') if 'CORE_VALUE_ASSESSMENT_DT' in partner else None partner_org.last_assessment_date = datetime.strptime( partner['DATE_OF_ASSESSMENT'], '%d-%b-%y') if 'DATE_OF_ASSESSMENT' in partner else None partner_org.partner_type = self.get_partner_type(partner) partner_org.deleted_flag = True if 'MARKED_FOR_DELETION' in partner else False posting_block = True if 'POSTING_BLOCK' in partner else False if posting_block and not partner_org.blocked: # i'm blocking the partner now notify_block = True partner_org.blocked = posting_block partner_org.hidden = partner_org.deleted_flag or partner_org.blocked or partner_org.manually_blocked partner_org.vision_synced = True saving = True if full_sync and ( partner_org.total_ct_cp is None or partner_org.total_ct_cy is None or partner_org.net_ct_cy is None or partner_org.total_ct_ytd is None or partner_org.reported_cy is None or not comp_decimals(partner_org.total_ct_cp, Decimal(partner['TOTAL_CASH_TRANSFERRED_CP'])) or not comp_decimals(partner_org.total_ct_cy, Decimal(partner['TOTAL_CASH_TRANSFERRED_CY'])) or not comp_decimals(partner_org.net_ct_cy, Decimal(partner['NET_CASH_TRANSFERRED_CY'])) or not comp_decimals(partner_org.total_ct_ytd, Decimal(partner['TOTAL_CASH_TRANSFERRED_YTD'])) or not comp_decimals(partner_org.reported_cy, Decimal(partner['REPORTED_CY']))): partner_org.total_ct_cy = partner['TOTAL_CASH_TRANSFERRED_CY'] partner_org.total_ct_cp = partner['TOTAL_CASH_TRANSFERRED_CP'] partner_org.net_ct_cy = partner['NET_CASH_TRANSFERRED_CY'] partner_org.total_ct_ytd = partner['TOTAL_CASH_TRANSFERRED_YTD'] partner_org.reported_cy = partner['REPORTED_CY'] saving = True logger.debug('sums changed', partner_org) if saving: logger.debug('Updating Partner', partner_org) # clear basis_for_risk_rating in certain cases if partner_org.basis_for_risk_rating and ( partner_org.type_of_assessment.upper() in [PartnerOrganization.HIGH_RISK_ASSUMED, PartnerOrganization.LOW_RISK_ASSUMED] or ( partner_org.rating == PartnerOrganization.RATING_NOT_REQUIRED and partner_org.type_of_assessment == PartnerOrganization.MICRO_ASSESSMENT) ): partner_org.basis_for_risk_rating = '' partner_org.save() if notify_block: notify_partner_hidden.delay(partner_org.pk, connection.schema_name) if new: PlannedEngagement.objects.get_or_create(partner=partner_org) # if date has changed, archive old and create a new one not archived core_value_date = partner_org.core_values_assessment_date if not partner_org.core_values_assessments.filter(date=core_value_date).exists(): partner_org.core_values_assessments.update(archived=True) partner_org.core_values_assessments.create(date=core_value_date, archived=False) processed = 1 except Exception: logger.exception('Exception occurred during Partner Sync') return processed