コード例 #1
0
def agreement_transition_to_signed_valid(agreement):
    '''Returns True if it's valid for the agreement to transition to signed, otherwise raises a TransitionError.

    TransitionErrors are raised under 3 circumstances --
      - If the agreement is of type PCA and matches certain criteria (see code)
      - If the start date is empty or in the future
      - If the end date is empty
    '''
    today = date.today()
    if agreement.agreement_type == agreement.PCA and \
            agreement.__class__.objects.filter(partner=agreement.partner,
                                               status=agreement.SIGNED,
                                               agreement_type=agreement.PCA,
                                               country_programme=agreement.country_programme,
                                               start__gt=date(2015, 7, 1)).exists():

        raise TransitionError(['agreement_transition_to_active_invalid_PCA'])

    if not agreement.start or agreement.start > today:
        raise TransitionError([
            'Agreement cannot transition to signed until '
            'the start date is less than or equal to today'
        ])
    if not agreement.end:
        raise TransitionError([
            'Agreement cannot transition to signed unless the end date is defined'
        ])

    return True
コード例 #2
0
ファイル: interventions.py プロジェクト: nixworks/etools
def transition_to_closed(i):
    # unicef/etools-issues:820
    # TODO: this is required to go around the caching of intervention.total_frs where self.frs.all() is called
    # TODO: find a sol for invalidating the cache on related .all() -has to do with prefetch_related in the validator
    r = {
        'total_frs_amt': 0,
        'total_frs_amt_usd': 0,
        'total_outstanding_amt': 0,
        'total_outstanding_amt_usd': 0,
        'total_intervention_amt': 0,
        'total_actual_amt': 0,
        'total_actual_amt_usd': 0,
        'earliest_start_date': None,
        'latest_end_date': None
    }
    for fr in i.frs.filter():
        r['total_frs_amt'] += fr.total_amt_local
        r['total_frs_amt_usd'] += fr.total_amt
        r['total_outstanding_amt'] += fr.outstanding_amt_local
        r['total_outstanding_amt_usd'] += fr.outstanding_amt
        r['total_intervention_amt'] += fr.intervention_amt
        r['total_actual_amt'] += fr.actual_amt_local
        r['total_actual_amt_usd'] += fr.actual_amt
        if r['earliest_start_date'] is None:
            r['earliest_start_date'] = fr.start_date
        elif r['earliest_start_date'] > fr.start_date:
            r['earliest_start_date'] = fr.start_date
        if r['latest_end_date'] is None:
            r['latest_end_date'] = fr.end_date
        elif r['latest_end_date'] < fr.end_date:
            r['latest_end_date'] = fr.end_date
    # hack
    i.total_frs = r

    # Make sure that is past the end date
    today = date.today()
    if i.end > today:
        raise TransitionError([_('End date is in the future')])

    if i.total_frs['total_frs_amt'] != i.total_frs['total_actual_amt'] or \
            i.total_frs['total_outstanding_amt'] != 0:
        raise TransitionError([_('Total FR amount needs to equal total actual amount, and '
                                 'Total Outstanding DCTs need to equal to 0')])

    # If total_actual_amt_usd >100,000 then attachments has to include
    # at least 1 record with type: "Final Partnership Review"
    if i.total_frs['total_actual_amt_usd'] >= 100000:
        if i.attachments.filter(type__name='Final Partnership Review').count() < 1:
            raise TransitionError([_('Total amount transferred greater than 100,000 and no Final Partnership Review '
                                     'was attached')])

    # TODO: figure out Action Point Validation once the spec is completed

    if i.in_amendment is True:
        raise TransitionError([_('Cannot Transition status while adding an amendment')])
    return True
コード例 #3
0
ファイル: interventions.py プロジェクト: nixworks/etools
def transition_to_signed(i):
    from partners.models import Agreement
    if i.in_amendment is True:
        raise TransitionError([_('Cannot Transition status while adding an amendment')])
    if i.document_type in [i.PD, i.SHPD] and i.agreement.status in [Agreement.SUSPENDED, Agreement.TERMINATED]:
        raise TransitionError([_('The PCA related to this record is Suspended or Terminated. '
                                 'This Programme Document will not change status until the related PCA '
                                 'is in Signed status')])

    if i.in_amendment is True:
        raise TransitionError([_('Cannot Transition status while adding an amendment')])

    return True
コード例 #4
0
ファイル: interventions.py プロジェクト: nixworks/etools
def transition_to_active(i):
    # Only transitional validation

    # Validation id 1 -> if intervention is PD make sure the agreement is in active status
    if i.document_type in [i.PD, i.SHPD] and i.agreement.status != i.agreement.SIGNED:
        raise TransitionError([
            _('PD cannot be activated if the associated Agreement is not active')
        ])
    return True
コード例 #5
0
def agreement_transition_to_ended_valid(agreement):
    today = date.today()
    logging.debug('I GOT CALLED to ended')
    if agreement.status == agreement.SIGNED and agreement.end and agreement.end < today:
        return True
    raise TransitionError(['agreement_transition_to_ended_invalid'])
コード例 #6
0
 def test_transition_valid_error(self):
     '''Ensure TransitionError inherits from _BaseStateError'''
     self.assertIsInstance(TransitionError(), _BaseStateError)
コード例 #7
0
ファイル: interventions.py プロジェクト: nixworks/etools
def transition_to_ended(i):
    if i.in_amendment is True:
        raise TransitionError([_('Cannot Transition status while adding an amendment')])

    return True
コード例 #8
0
ファイル: interventions.py プロジェクト: nixworks/etools
def partnership_manager_only(i, user):
    # Transition cannot happen by a user that's not a Partnership Manager
    if not user.groups.filter(name__in=['Partnership Manager']).count():
        raise TransitionError(['Only Partnership Managers can execute this transition'])
    return True