Exemplo n.º 1
0
def test_create_berth_switch_offer_old_lease(api_client, berth_application,
                                             berth):
    berth_lease = BerthLeaseFactory(
        start_date=calculate_season_start_date(),
        end_date=calculate_season_end_date(),
        status=LeaseStatus.PAID,
    )
    BerthLeaseFactory(
        customer=berth_lease.customer,
        start_date=calculate_season_start_date(),
        end_date=calculate_season_end_date(),
        status=LeaseStatus.PAID,
    )
    berth_application.customer = berth_lease.customer
    berth_application.berth_switch = BerthSwitchFactory(
        berth=berth_lease.berth)
    berth_application.save()

    variables = {
        "applicationId": to_global_id(BerthApplicationNode,
                                      berth_application.id),
        "newBerthId": to_global_id(BerthNode, berth.id),
        "oldLeaseId": to_global_id(BerthLeaseNode, berth_lease.id),
    }
    executed = api_client.execute(CREATE_BERTH_SWITCH_OFFER_MUTATION,
                                  input=variables)

    assert executed["data"]["createBerthSwitchOffer"]["berthSwitchOffer"] == {
        "status": OfferStatus.DRAFTED.name,
        "dueDate": None,
        "application": {
            "id": variables["applicationId"],
            "status": "OFFER_GENERATED"
        },
        "customer": {
            "id": to_global_id(ProfileNode, berth_lease.customer.id)
        },
        "lease": {
            "id": to_global_id(BerthLeaseNode, berth_lease.id)
        },
        "berth": {
            "id": variables["newBerthId"]
        },
    }
Exemplo n.º 2
0
 def get_old_lease(application: BerthApplication) -> BerthLease:
     # Based on the information filled by the customer on the switch application,
     # we retrieve the corresponding lease on the current season
     return BerthLease.objects.get(
         customer=application.customer,
         berth=application.berth_switch.berth,
         status=LeaseStatus.PAID,
         start_date=calculate_season_start_date(),
         end_date=calculate_season_end_date(),
     )
Exemplo n.º 3
0
def calculate_lease_start_and_end_dates(start_date: date) -> Tuple[date, date]:
    """
    When importing customers from the old Timmi system, we try to create leases based on the order data we have.
    For that, we use the created_at timestamp of the order. Assuming that the order was generated for the
    upcoming season, we calculate the start and end dates for the lease.
    """
    end_date = calculate_season_end_date(start_date)

    # If the start date is after the calculated end date for the associated season (year),
    # the lease would belong to the next year's season
    if start_date > end_date:
        start_date = calculate_season_start_date(start_date) + relativedelta(
            years=1)
        end_date = calculate_season_end_date(start_date)
    # If the order was created before the start date's year's season start, the start date will
    # be the that year's season
    elif start_date < calculate_season_start_date(start_date):
        start_date = calculate_season_start_date(start_date)
    # Otherwise, if the start date is during the season dates, it should be the same

    return start_date, end_date
Exemplo n.º 4
0
def test_create_berth_switch_offer_refresh_profile(api_client,
                                                   berth_application, berth):
    faker = Faker("fi_FI")
    berth_lease = BerthLeaseFactory(
        start_date=calculate_season_start_date(),
        end_date=calculate_season_end_date(),
        status=LeaseStatus.PAID,
    )
    berth_application.customer = berth_lease.customer
    berth_application.berth_switch = BerthSwitchFactory(
        berth=berth_lease.berth)
    berth_application.save()

    first_name = faker.first_name()
    last_name = faker.last_name()
    email = faker.email()
    phone = faker.phone_number()

    data = {
        "id": to_global_id(ProfileNode, berth_lease.customer.id),
        "first_name": first_name,
        "last_name": last_name,
        "primary_email": {
            "email": email
        },
        "primary_phone": {
            "phone": phone
        },
    }
    variables = {
        "applicationId": to_global_id(BerthApplicationNode,
                                      berth_application.id),
        "newBerthId": to_global_id(BerthNode, berth.id),
        "profileToken": "profile-token",
    }
    with mock.patch(
            "customers.services.profile.requests.post",
            side_effect=mocked_response_profile(count=0,
                                                data=data,
                                                use_edges=False),
    ):
        executed = api_client.execute(
            CREATE_BERTH_SWITCH_OFFER_MUTATION_CUSTOMER_FIELDS,
            input=variables)

    assert executed["data"]["createBerthSwitchOffer"]["berthSwitchOffer"] == {
        "customerFirstName": first_name,
        "customerLastName": last_name,
        "customerEmail": email,
        "customerPhone": phone,
    }
Exemplo n.º 5
0
def calculate_product_partial_season_price(
        base_price: Decimal,
        start_date: date,
        end_date: date,
        summer_season: bool = True) -> Decimal:
    # If it's the "normal" (summer) season, calculate with the normal dates
    season_days = calculate_season_end_date() - calculate_season_start_date()
    # If it's for the opposite season ("winter season"), calculate the inverse
    if not summer_season:
        season_days = (calculate_winter_season_end_date() -
                       calculate_winter_season_start_date())
    delta = (end_date - start_date).days
    price = (delta * base_price) / season_days.days
    return price
Exemplo n.º 6
0
def test_create_berth_switch_offer_missing_application_switch(
        api_client, berth_application, berth):
    berth_lease = BerthLeaseFactory(start_date=calculate_season_start_date(),
                                    end_date=calculate_season_end_date())
    berth_application.customer = berth_lease.customer
    berth_application.berth_switch = None
    berth_application.save()

    berth_lease.status = LeaseStatus.PAID
    berth_lease.save()

    variables = {
        "applicationId": to_global_id(BerthApplicationNode,
                                      berth_application.id),
        "newBerthId": to_global_id(BerthNode, berth.id),
    }
    executed = api_client.execute(CREATE_BERTH_SWITCH_OFFER_MUTATION,
                                  input=variables)
    assert_in_errors("Application must be a switch application", executed)
Exemplo n.º 7
0
def test_create_berth_switch_offer_wrong_berth(api_client, berth_application,
                                               berth):
    berth_lease = BerthLeaseFactory(
        start_date=calculate_season_start_date(),
        end_date=calculate_season_end_date(),
        status=LeaseStatus.PAID,
    )
    berth_application.customer = berth_lease.customer

    berth_application.berth_switch = BerthSwitchFactory(
        berth=BerthFactory(number="9999"), )
    berth_application.save()

    variables = {
        "applicationId": to_global_id(BerthApplicationNode,
                                      berth_application.id),
        "newBerthId": to_global_id(BerthNode, berth.id),
    }
    executed = api_client.execute(CREATE_BERTH_SWITCH_OFFER_MUTATION,
                                  input=variables)

    assert_in_errors("NO_LEASE", executed)
def _order_created_at():
    return fake.date_between_dates(
        datetime.date(template_context["season_year"], 1, 1),
        calculate_season_end_date(
            datetime.date(template_context["season_year"], 1, 1)),
    ).isoformat()
# place for variables that are used while applying a template
template_context = {}

LEASE_TEMPLATE = {
    "harbor_servicemap_id":
    lambda: template_context["berth"]["harbor_servicemap_id"],
    "pier_id":
    lambda: template_context["berth"]["pier_identifier"],
    "berth_number":
    lambda: int(template_context["berth"]["number"]),
    "start_date":
    lambda: calculate_season_start_date(
        datetime.date(template_context["season_year"], 1, 1)).isoformat(),
    "end_date":
    lambda: calculate_season_end_date(
        datetime.date(template_context["season_year"], 1, 1)).isoformat(),
    "boat_index":
    lambda: template_context["boat_index"],
}


def _order_created_at():
    return fake.date_between_dates(
        datetime.date(template_context["season_year"], 1, 1),
        calculate_season_end_date(
            datetime.date(template_context["season_year"], 1, 1)),
    ).isoformat()


ORDER_TEMPLATE = {
    "order_sum": lambda: str(random_price()),