def add(a, b, allow_overflow=False):
    """Adds two instances of `Money`.

    Args:
      a (:class:`endpoints_management.gen.servicecontrol_v1_messages.Money`): one money
        value
      b (:class:`endpoints_management.gen.servicecontrol_v1_messages.Money`): another
        money value
      allow_overflow: determines if the addition is allowed to overflow

    Return:
      `Money`: an instance of Money

    Raises:
      ValueError: if the inputs do not have the same currency code
      OverflowError: if the sum overflows and allow_overflow is not `True`
    """
    for m in (a, b):
        if not isinstance(m, sc_messages.Money):
            raise ValueError(u'Inputs should be of type %s' % (sc_messages.Money,))
    if a.currencyCode != b.currencyCode:
        raise ValueError(u'Money values need the same currency to be summed')
    nano_carry, nanos_sum = _sum_nanos(a, b)
    units_sum_no_carry = a.units + b.units
    units_sum = units_sum_no_carry + nano_carry

    # Adjust when units_sum and nanos_sum have different signs
    if units_sum > 0 and nanos_sum < 0:
        units_sum -= 1
        nanos_sum += _BILLION
    elif units_sum < 0 and nanos_sum > 0:
        units_sum += 1
        nanos_sum -= _BILLION

    # Return the result, detecting overflow if it occurs
    sign_a = _sign_of(a)
    sign_b = _sign_of(b)
    if sign_a > 0 and sign_b > 0 and units_sum >= _INT64_MAX:
        if not allow_overflow:
            raise OverflowError(u'Money addition positive overflow')
        else:
            return sc_messages.Money(units=_INT64_MAX,
                                     nanos=MAX_NANOS,
                                     currencyCode=a.currencyCode)
    elif (sign_a < 0 and sign_b < 0 and
          (units_sum_no_carry <= -_INT64_MAX or units_sum <= -_INT64_MAX)):
        if not allow_overflow:
            raise OverflowError(u'Money addition negative overflow')
        else:
            return sc_messages.Money(units=_INT64_MIN,
                                     nanos=-MAX_NANOS,
                                     currencyCode=a.currencyCode)
    else:
        return sc_messages.Money(units=units_sum,
                                 nanos=nanos_sum,
                                 currencyCode=a.currencyCode)
Adds two instances of `Money`.

    Args:
      a (:class:`endpoints_management.gen.servicecontrol_v1_messages.Money`): one money
        value
      b (:class:`endpoints_management.gen.servicecontrol_v1_messages.Money`): another
        money value
      allow_overflow: determines if the addition is allowed to overflow

    Return:
      `Money`: an instance of Money

    Raises:
      ValueError: if the inputs do not have the same currency code
      OverflowError: if the sum overflows and allow_overflow is not `True`