Esempio n. 1
0
def test_methods_impossible(admin_user):
    contact = get_person_contact(admin_user)
    source = BasketishOrderSource(get_default_shop())

    default_product = get_default_product()
    default_product.width = 5000
    default_product.depth = 4000
    default_product.heith = 1300
    default_product.save()

    source.add_line(
        type=OrderLineType.PRODUCT,
        product=default_product,
        supplier=get_default_supplier(),
        quantity=1,
        base_unit_price=source.create_price(10),
        weight=Decimal("200"))
    billing_address = get_address()
    shipping_address = get_address(name="My House", country='BR')

    shipping_address.postal_code = "89070210"

    source.billing_address = billing_address
    source.shipping_address = shipping_address
    source.customer = contact

    source.shipping_method = get_correios_carrier_1()
    source.payment_method = get_payment_method(name="neat", price=4)
    assert source.shipping_method_id
    assert source.payment_method_id

    errors = list(source.get_validation_errors())
    assert len(errors) == 1
Esempio n. 2
0
def test_addressbook_has_addresses(regular_user):
    client, contact = initialize_test(regular_user)
    address = get_address()
    address.save()
    billing_name = address.name
    contact.default_billing_address = address
    contact.save()
    addressbook_url = reverse("shuup:address_book")
    soup = client.soup(addressbook_url)

    assert len(soup(text="Name:")) == 1
    elems = [p for p in soup.find_all("p") if p.text == "Name: %s" % billing_name]
    assert len(elems) == 1

    address = get_address(**{"name": "Kek Bur"})
    address.save()
    shipping_name = address.name
    contact.default_shipping_address = address
    contact.save()

    soup = client.soup(addressbook_url)

    elems = [p for p in soup.find_all("p") if p.text == "Name: %s" % billing_name]
    assert len(elems) == 1

    assert len(soup(text="Name:")) == 2
    elems = [p for p in soup.find_all("p") if p.text == "Name: %s" % shipping_name]
    assert len(elems) == 1
Esempio n. 3
0
def create_simple_order(request, creator, customer):
    billing_address = get_address().to_immutable()
    shipping_address = get_address(name="Shippy Doge").to_immutable()
    shipping_address.save()
    shop = request.shop
    order = Order(
        creator=creator,
        customer=customer,
        shop=shop,
        payment_method=get_default_payment_method(),
        shipping_method=get_default_shipping_method(),
        billing_address=billing_address,
        shipping_address=shipping_address,
        order_date=now(),
        status=get_initial_order_status(),
        currency=shop.currency,
        prices_include_tax=shop.prices_include_tax,
    )
    order.full_clean()
    order.save()

    order.cache_prices()
    order.check_all_verified()
    order.save()
    return order
def _seed_source(shop, user):
    source = BasketishOrderSource(shop)
    billing_address = get_address()
    shipping_address = get_address(name="Test street")
    source.status = get_initial_order_status()
    source.billing_address = billing_address
    source.shipping_address = shipping_address
    source.customer = get_person_contact(user)
    return source
Esempio n. 5
0
def seed_source(user):
    source = BasketishOrderSource(get_default_shop())
    billing_address = get_address()
    shipping_address = get_address(name="Shippy Doge")
    source.status = get_initial_order_status()
    source.billing_address = billing_address
    source.shipping_address = shipping_address
    source.customer = get_person_contact(user)
    source.payment_method = get_default_payment_method()
    source.shipping_method = get_default_shipping_method()
    assert source.payment_method_id == get_default_payment_method().id
    assert source.shipping_method_id == get_default_shipping_method().id
    return source
Esempio n. 6
0
def test_correios_delivery_time_2(rf, admin_user):
    with patch.object(CorreiosWS, 'get_preco_prazo', return_value=MOCKED_SUCCESS_RESULT):
        pac_carrier = get_correios_carrier_2()
        contact = get_person_contact(admin_user)
        p1 = create_product(sku='p1',
                            supplier=get_default_supplier(),
                            width=400,
                            depth=400,
                            height=400,
                            gross_weight=1250)

        # P2 é pesado pacas - é empacotado em uma caixa separada
        # só para dar problema na metade da entrega
        p2 = create_product(sku='p2',
                            supplier=get_default_supplier(),
                            width=400,
                            depth=400,
                            height=400,
                            gross_weight=31250)

        source = seed_source(admin_user)
        source.add_line(
            type=OrderLineType.PRODUCT,
            product=p1,
            supplier=get_default_supplier(),
            quantity=2,
            base_unit_price=source.create_price(10))

        source.add_line(
            type=OrderLineType.PRODUCT,
            product=p2,
            supplier=get_default_supplier(),
            quantity=1,
            base_unit_price=source.create_price(20))

        billing_address = get_address()
        shipping_address = get_address(name="My House", country='BR')
        shipping_address.postal_code = "89070210"
        source.billing_address = billing_address
        source.shipping_address = shipping_address
        source.customer = contact

        shipping = ShippingMethod.objects.filter(carrier=pac_carrier).first()

        bc = shipping.behavior_components.first()
        packages = bc._pack_source(source)
        assert len(packages) == 3

        results = bc._get_correios_results(source, packages)
        assert len(results) == 3
def get_source(admin_user, service):
    contact = get_person_contact(admin_user)
    source = BasketishOrderSource(get_default_shop())

    billing_address = get_address()
    shipping_address = get_address(name="My House", country='BR')

    source.billing_address = billing_address
    source.shipping_address = shipping_address
    source.customer = contact

    source.shipping_method = service.carrier
    source.payment_method = get_payment_method(name="neat", price=4)

    return source
Esempio n. 8
0
def test_new_mutable_address():
    address = get_address()
    new_mutable = address.to_mutable()

    # New address should be unsaved
    assert new_mutable.pk == None
    assert isinstance(new_mutable, MutableAddress)
    assert get_data_dict(address).items() == get_data_dict(new_mutable).items()
Esempio n. 9
0
def test_methods(admin_user, country):
    contact = get_person_contact(admin_user)
    source = BasketishOrderSource(get_default_shop())
    source.add_line(
        type=OrderLineType.PRODUCT,
        product=get_default_product(),
        supplier=get_default_supplier(),
        quantity=1,
        base_unit_price=source.create_price(10),
        weight=Decimal("0.2")
    )
    billing_address = get_address()
    shipping_address = get_address(name="Shippy Doge", country=country)
    source.billing_address = billing_address
    source.shipping_address = shipping_address
    source.customer = contact

    source.shipping_method = get_expensive_sweden_shipping_method()
    source.payment_method = get_payment_method(name="neat", price=4)
    assert source.shipping_method_id
    assert source.payment_method_id

    errors = list(source.get_validation_errors())

    if country == "FI":
        # "Expenseefe-a Svedee Sheepping" will not allow shipping to
        # Finland, let's see if that holds true
        assert any([ve.code == "we_no_speak_finnish" for ve in errors])
        assert [x.code for x in errors] == ["we_no_speak_finnish"]
        return  # Shouldn't try the rest if we got an error here
    else:
        assert not errors

    final_lines = list(source.get_final_lines())

    assert any(line.type == OrderLineType.SHIPPING for line in final_lines)

    for line in final_lines:
        if line.type == OrderLineType.SHIPPING:
            if country == "SE":  # We _are_ using Expenseefe-a Svedee Sheepping after all.
                assert line.price == source.create_price("5.00")
            else:
                assert line.price == source.create_price("4.00")
            assert line.text == u"Expenseefe-a Svedee Sheepping"
        if line.type == OrderLineType.PAYMENT:
            assert line.price == source.create_price(4)
Esempio n. 10
0
def test_set_shipping_address(admin_user):
    shop = factories.get_default_shop()
    basket = factories.get_basket()
    factories.get_default_payment_method()
    factories.get_default_shipping_method()
    client = _get_client(admin_user)
    addr1 = factories.get_address()
    addr1.save()

    # use existing address
    payload = {
        'id': addr1.id
    }
    response = client.post('/api/shuup/basket/{}-{}/set_shipping_address/'.format(shop.pk, basket.key), payload)
    assert response.status_code == status.HTTP_200_OK
    response_data = json.loads(response.content.decode("utf-8"))
    shipping_addr = response_data["shipping_address"]
    assert shipping_addr["id"] == addr1.id
    assert shipping_addr["prefix"] == addr1.prefix
    assert shipping_addr["name"] == addr1.name
    assert shipping_addr["postal_code"] == addr1.postal_code
    assert shipping_addr["street"] == addr1.street
    assert shipping_addr["city"] == addr1.city
    assert shipping_addr["country"] == addr1.country

    # create a new address
    address_data = {
        'name': 'name',
        'prefix': 'prefix',
        'postal_code': 'postal_code',
        'street': 'street',
        'city': 'city',
        'country': 'BR'
    }
    response = client.post('/api/shuup/basket/{}-{}/set_shipping_address/'.format(shop.pk, basket.key), address_data)
    assert response.status_code == status.HTTP_200_OK
    response_data = json.loads(response.content.decode("utf-8"))
    shipping_addr = response_data["shipping_address"]
    assert shipping_addr["id"] == addr1.id+1
    assert shipping_addr["prefix"] == address_data["prefix"]
    assert shipping_addr["name"] == address_data["name"]
    assert shipping_addr["postal_code"] == address_data["postal_code"]
    assert shipping_addr["street"] == address_data["street"]
    assert shipping_addr["city"] == address_data["city"]
    assert shipping_addr["country"] == address_data["country"]

    # get the basket and check the address
    response = client.get('/api/shuup/basket/{}-{}/'.format(shop.pk, basket.key))
    assert response.status_code == status.HTTP_200_OK
    response_data = json.loads(response.content.decode("utf-8"))
    shipping_addr = response_data["shipping_address"]
    assert shipping_addr["id"] == addr1.id+1
    assert shipping_addr["prefix"] == address_data["prefix"]
    assert shipping_addr["name"] == address_data["name"]
    assert shipping_addr["postal_code"] == address_data["postal_code"]
    assert shipping_addr["street"] == address_data["street"]
    assert shipping_addr["city"] == address_data["city"]
    assert shipping_addr["country"] == address_data["country"]
Esempio n. 11
0
def seed_source(shipping_method=None, produce_price=10):
    source = BasketishOrderSource(get_default_shop())
    billing_address = get_address()
    shipping_address = get_address(name="Shippy Doge")
    source.status = get_initial_order_status()
    source.billing_address = billing_address
    source.shipping_address = shipping_address
    source.customer = create_random_person()
    source.payment_method = get_default_payment_method()
    source.shipping_method = shipping_method if shipping_method else get_default_shipping_method()
    source.add_line(
        type=OrderLineType.PRODUCT,
        product=get_default_product(),
        supplier=get_default_supplier(),
        quantity=1,
        base_unit_price=source.create_price(produce_price),
    )
    return source
Esempio n. 12
0
def test_methods_possible(admin_user):
    with patch.object(CorreiosWS, 'get_preco_prazo', return_value=MOCKED_SUCCESS_RESULT):

        contact = get_person_contact(admin_user)
        source = BasketishOrderSource(get_default_shop())

        default_product = get_default_product()
        default_product.width = 500
        default_product.depth = 400
        default_product.heith = 130
        default_product.save()

        source.add_line(
            type=OrderLineType.PRODUCT,
            product=default_product,
            supplier=get_default_supplier(),
            quantity=1,
            base_unit_price=source.create_price(10),
            weight=Decimal("0.2"))
        billing_address = get_address()
        shipping_address = get_address(name="My House", country='BR')
        shipping_address.postal_code = "89070210"

        source.billing_address = billing_address
        source.shipping_address = shipping_address
        source.customer = contact

        source.shipping_method = get_correios_carrier_1()
        source.payment_method = get_payment_method(name="neat", price=4)
        assert source.shipping_method_id
        assert source.payment_method_id

        errors = list(source.get_validation_errors())
        # no errors
        assert len(errors) == 0

        final_lines = list(source.get_final_lines())

        assert any(line.type == OrderLineType.SHIPPING for line in final_lines)

        for line in final_lines:
            if line.type == OrderLineType.SHIPPING:
                assert line.text == "Correios - PAC #1"
Esempio n. 13
0
def test_correios_delivery_time_1(rf, admin_user):

    with patch.object(CorreiosWS, 'get_preco_prazo', return_value=MOCKED_SUCCESS_RESULT):
        pac_carrier = get_correios_carrier_2()
        contact = get_person_contact(admin_user)
        p1 = create_product(sku='p1',
                            supplier=get_default_supplier(),
                            width=400,
                            depth=400,
                            height=400,
                            gross_weight=1250)

        source = seed_source(admin_user)
        source.add_line(
            type=OrderLineType.PRODUCT,
            product=p1,
            supplier=get_default_supplier(),
            quantity=1,
            base_unit_price=source.create_price(10))
        billing_address = get_address()
        shipping_address = get_address(name="My House", country='BR')
        shipping_address.postal_code = "89070210"
        source.billing_address = billing_address
        source.shipping_address = shipping_address
        source.customer = contact

        bc = ShippingMethod.objects.filter(carrier=pac_carrier).first().behavior_components.first()
        packages = bc._pack_source(source)
        assert len(packages) == 1

        results = bc._get_correios_results(source, packages)
        assert len(results) == 1
        assert results[0].erro == 0
        assert results[0].valor > Decimal(0)

        delivery_time = bc.get_delivery_time(ShippingMethod.objects.filter(carrier=pac_carrier).first(), source)
        assert delivery_time is not None
        assert delivery_time.max_duration == delivery_time.min_duration
        assert delivery_time.max_duration.days == results[0].prazo_entrega + bc.additional_delivery_time

        costs = list(bc.get_costs(ShippingMethod.objects.filter(carrier=pac_carrier).first(), source))
        assert len(costs) == 1
        assert source.create_price(results[0].valor + bc.additional_price) == costs[0].price
Esempio n. 14
0
def seed_source(user, extra_addr=True):
    source = BasketishOrderSource(get_default_shop())
    billing_address = get_address()
    shipping_address = get_address(name="Shippy Doge")

    if extra_addr:
        billing_address.extra = ExtraMutableAddress.from_data(EXTRA_MUTABLE_ADDRESS_1)
    if extra_addr:
        shipping_address.extra = ExtraMutableAddress.from_data(EXTRA_MUTABLE_ADDRESS_2)

    source.status = get_initial_order_status()
    source.billing_address = billing_address
    source.shipping_address = shipping_address
    source.customer = get_person_contact(user)
    source.payment_method = get_default_payment_method()
    source.shipping_method = get_default_shipping_method()
    assert source.payment_method_id == get_default_payment_method().id
    assert source.shipping_method_id == get_default_shipping_method().id
    return source
Esempio n. 15
0
def delete_address(regular_user):
    client, contact = initialize_test(regular_user)
    address = get_address()
    address.save()

    sa = SavedAddress.objects.create(owner=contact, address=address)
    delete_url = reverse("shuup:address_book_delete", kwargs={"pk":sa.pk})
    response, soup = client.response_and_soup(delete_url)
    assert response.status_code == 302
    assert "Cannot remove address" not in soup

    user = User.objects.create_user('john', '*****@*****.**', 'doepassword')
    contact2 = get_person_contact(user)
    address2 = get_address()
    address2.save()

    sa2 = SavedAddress.objects.create(owner=contact2, address=address2)
    response, soup = client.response_and_soup(delete_url)
    assert response.status_code == 302
    assert "Cannot remove address" in soup
Esempio n. 16
0
def test_address_ownership(admin_user):
    address = get_address()
    address.save()
    saved = SavedAddress(address=address)
    saved.owner = get_person_contact(admin_user)
    assert saved.get_title(), u"get_title does what it should even if there is no explicit title"
    saved.title = u"My favorite address"
    assert saved.get_title() == saved.title, u"get_title does what it should when there is an explicit title"
    assert six.text_type(saved) == saved.get_title(), u"str() is an alias for .get_title()"
    saved.full_clean()
    saved.save()
    assert SavedAddress.objects.for_owner(get_person_contact(admin_user)).filter(address=address).exists(), \
        "contacts can save addresses"
    assert SavedAddress.objects.for_owner(None).count() == 0, "Ownerless saved addresses aren't a real thing"
Esempio n. 17
0
def test_immutable_address():
    address = get_address()
    new_immutable = address.to_immutable()

    # New address should be saved
    assert new_immutable.pk != None
    assert isinstance(new_immutable, ImmutableAddress)
    assert get_data_dict(address).items() == get_data_dict(new_immutable).items()

    # Taking immutable for same address should return same object
    assert new_immutable == address.to_immutable()

    # Taking immutable from new_immutable should return same item
    assert new_immutable == new_immutable.to_immutable()
Esempio n. 18
0
def test_order_address_immutability_unsaved_address(save):
    billing_address = get_address()
    if save:
        billing_address.save()
    order = Order(
        shop=get_default_shop(),
        billing_address=billing_address.to_immutable(),
        order_date=now(),
        status=get_initial_order_status()
    )
    order.save()
    order.billing_address.name = "Mute Doge"
    with pytest.raises(ValidationError):
        order.billing_address.save()
Esempio n. 19
0
def test_basic_address():
    address = get_address()
    address.full_clean()
    string_repr = str(address)
    for field, value in get_data_dict(address).items():
        if field == "country":  # We can't test this right now, it's formatted in the repr
            continue
        if not value:
            continue
        assert value in string_repr, "Field %s is not represented in %r" % (field, string_repr)

    assert address.is_european_union, "Dog Fort, UK is in the EU"
    assert list(address.split_name) == ["Dog", "Hello"], "Names split correctly"
    assert address.first_name == "Dog", "Names split correctly"
    assert address.last_name == "Hello", "Names split correctly"
    assert address.full_name == "Sir Dog Hello , Esq.", "Names join correctly"
Esempio n. 20
0
def test_addressbook_has_saved_addresses(regular_user):
    client, contact = initialize_test(regular_user)
    address = get_address()
    address.save()
    address_title = "TestAddress"
    sa = SavedAddress.objects.create(owner=contact, address=address, title=address_title)
    addressbook_url = reverse("shuup:address_book")

    soup = client.soup(addressbook_url)
    elems = [h for h in soup.find_all("h2") if h.text.strip() == address_title]
    assert len(elems) == 1
    assert len(soup(text="Name:")) == 1

    second_address_title = "TestAddress2"
    sa = SavedAddress.objects.create(owner=contact, address=address, title=second_address_title)
    soup = client.soup(addressbook_url)
    elems = [h for h in soup.find_all("h2") if h.text.strip() == second_address_title]
    assert len(elems) == 1
    assert len(soup(text="Name:")) == 2
Esempio n. 21
0
def test_address_saving_retrieving_and_immutability():
    # We can save an address...
    address = get_address()
    address.save()
    # mutate it...
    address.name = u"Dog Hi"
    # Then set it as immutable...
    immutable_address = address.to_immutable()
    immutable_address.save()

    # And when we try to save it again, it fails...
    immutable_address.name = u"Dog Yo"
    with pytest.raises(ValidationError):
        immutable_address.save()

    # But to mutate the address, we can copy it...
    address_copy = address.to_mutable()
    assert not address_copy.pk
    address_copy.save()
    assert address_copy.pk != address.pk, "new address was saved as another entity"
Esempio n. 22
0
def fill_address_inputs(soup, with_company=False):
    inputs = {}
    test_address = get_address()
    for key, value in extract_form_fields(soup.find('form', id='addresses')).items():
        if not value:
            if key in ("order-tax_number", "order-company_name"):
                continue
            if key.startswith("shipping-") or key.startswith("billing-"):
                bit = key.split("-")[1]
                value = getattr(test_address, bit, None)
            if not value and "email" in key:
                value = "*****@*****.**" % random.random()
            if not value:
                value = "test"
        inputs[key] = value

    if with_company:
        inputs["company-tax_number"] = "FI1234567-1"
        inputs["company-company_name"] = "Example Oy"
    else:
        inputs = dict((k, v) for (k, v) in inputs.items() if not k.startswith("company-"))

    return inputs
Esempio n. 23
0
def test_broken_order(admin_user):
    """
    """
    quantities = [44, 23, 65]
    expected = sum(quantities) * 50
    expected_based_on = expected / 1.5

    # Shuup is calculating taxes per line so there will be some "errors"
    expected_based_on = ensure_decimal_places(Decimal("%s" % (expected_based_on + 0.01)))

    shop = get_default_shop()

    supplier = get_default_supplier()
    product1 = create_product("simple-test-product1", shop, supplier, 50)
    product2 = create_product("simple-test-product2", shop, supplier, 50)
    product3 = create_product("simple-test-product3", shop, supplier, 50)

    tax = get_default_tax()

    source = BasketishOrderSource(get_default_shop())
    billing_address = get_address(country="US")
    shipping_address = get_address(name="Test street", country="US")
    source.status = get_initial_order_status()
    source.billing_address = billing_address
    source.shipping_address = shipping_address
    source.customer = create_random_person()
    source.payment_method = get_default_payment_method()
    source.shipping_method = get_default_shipping_method()

    source.add_line(
        type=OrderLineType.PRODUCT,
        product=product1,
        supplier=get_default_supplier(),
        quantity=quantities[0],
        base_unit_price=source.create_price(50),
    )

    source.add_line(
        type=OrderLineType.PRODUCT,
        product=product2,
        supplier=get_default_supplier(),
        quantity=quantities[1],
        base_unit_price=source.create_price(50),
    )

    source.add_line(
        type=OrderLineType.PRODUCT,
        product=product3,
        supplier=get_default_supplier(),
        quantity=quantities[2],
        base_unit_price=source.create_price(50),
    )

    currency = "EUR"
    summary = source.get_tax_summary()


    assert len(summary) == 1
    summary = summary[0]

    assert summary.taxful == Money(expected, "EUR")
    assert summary.based_on == Money(expected_based_on, "EUR")

    # originally non-rounded value
    assert bankers_round(source.get_total_tax_amount()) == summary.tax_amount

    assert source.taxless_total_price.value == expected_based_on
    assert summary.taxful.value == source.taxful_total_price.value

    assert summary.tax_amount == Money(bankers_round(source.taxful_total_price.value - source.taxless_total_price.value), currency)
    assert summary.taxful == summary.raw_based_on + summary.tax_amount

    assert summary.tax_rate == tax.rate
    assert summary.taxful.value == (summary.based_on + summary.tax_amount).value - Decimal("%s" % 0.01)

    # create order from basket
    creator = OrderCreator()
    order = creator.create_order(source)
    assert order.taxless_total_price.value == expected_based_on

    # originally non-rounded value
    assert bankers_round(order.get_total_tax_amount()) == summary.tax_amount
Esempio n. 24
0
def create_order(request, creator, customer, product):
    billing_address = get_address().to_immutable()
    shipping_address = get_address(name="Shippy Doge").to_immutable()
    shipping_address.save()
    default_pm = get_default_payment_method()
    default_sm = get_default_shipping_method()
    shop = request.shop
    order = Order(
        creator=creator,
        customer=customer,
        shop=shop,
        payment_method=default_pm,
        shipping_method=default_sm,
        billing_address=billing_address,
        shipping_address=shipping_address,
        order_date=now(),
        status=get_initial_order_status(),
        currency=shop.currency,
        prices_include_tax=shop.prices_include_tax,
    )
    order.full_clean()
    order.save()
    supplier = get_default_supplier()
    product_order_line = OrderLine(order=order)
    update_order_line_from_product(
        pricing_context=request,
        order_line=product_order_line,
        product=product,
        quantity=5,
        supplier=supplier)

    assert product_order_line.text == product.safe_translation_getter("name")
    product_order_line.base_unit_price = shop.create_price(100)
    assert product_order_line.price.value > 0
    product_order_line.save()

    line_tax = get_line_taxes_for(product_order_line)[0]

    order_line_tax = OrderLineTax.from_tax(
        tax=line_tax.tax,
        base_amount=line_tax.base_amount,
        order_line=product_order_line,
    )
    order_line_tax.save()  # Save order_line_tax before linking to order_line.tax
    product_order_line.taxes.add(order_line_tax)

    discount_order_line = OrderLine(order=order, quantity=1, type=OrderLineType.OTHER)
    discount_order_line.discount_amount = shop.create_price(30)
    assert discount_order_line.discount_amount.value == 30
    assert discount_order_line.price.value == -30
    assert discount_order_line.base_unit_price.value == 0
    discount_order_line.save()

    order.cache_prices()
    order.check_all_verified()
    order.save()

    assert not order.can_set_complete()

    base = 5 * shop.create_price(100).amount
    discount = shop.create_price(30).amount
    tax_value = line_tax.amount
    if not order.prices_include_tax:
        assert order.taxless_total_price.amount == base - discount
        assert order.taxful_total_price.amount == base + tax_value - discount
    else:
        assert_almost_equal(order.taxless_total_price.amount, base - tax_value - discount)
        assert_almost_equal(order.taxful_total_price.amount, base - discount)

    assert not order.is_fully_shipped()
    shipment = order.create_shipment_of_all_products(supplier=supplier)
    assert order.is_fully_shipped()

    assert shipment.total_products == 5, "All products were shipped"
    assert shipment.weight == product.gross_weight * 5 / 1000, "Gravity works"
    assert not order.get_unshipped_products(), "Nothing was left in the warehouse"

    assert order.can_set_complete()

    order.create_payment(order.taxful_total_price)
    assert order.is_paid()
    assert Order.objects.paid().filter(pk=order.pk).exists(), "It was paid! Honestly!"
    assert order.has_products()

    assert order.get_available_shipping_methods()
    assert order.get_available_payment_methods()

    assert default_sm in order.get_available_shipping_methods()
    assert default_pm in order.get_available_payment_methods()
Esempio n. 25
0
def test_uk_not_in_eu():
    address = get_address(country="GB")
    assert not address.is_european_union
Esempio n. 26
0
def test_broken_order(admin_user):
    """
    """
    quantities = [44, 23, 65]
    expected = sum(quantities) * 50
    expected_based_on = expected / 1.5

    # Shuup is calculating taxes per line so there will be some "errors"
    expected_based_on = ensure_decimal_places(
        Decimal("%s" % (expected_based_on + 0.01)))

    shop = get_default_shop()

    supplier = get_default_supplier()
    product1 = create_product("simple-test-product1", shop, supplier, 50)
    product2 = create_product("simple-test-product2", shop, supplier, 50)
    product3 = create_product("simple-test-product3", shop, supplier, 50)

    tax = get_default_tax()

    source = BasketishOrderSource(get_default_shop())
    billing_address = get_address(country="US")
    shipping_address = get_address(name="Test street", country="US")
    source.status = get_initial_order_status()
    source.billing_address = billing_address
    source.shipping_address = shipping_address
    source.customer = create_random_person()
    source.payment_method = get_default_payment_method()
    source.shipping_method = get_default_shipping_method()

    source.add_line(
        type=OrderLineType.PRODUCT,
        product=product1,
        supplier=get_default_supplier(),
        quantity=quantities[0],
        base_unit_price=source.create_price(50),
    )

    source.add_line(
        type=OrderLineType.PRODUCT,
        product=product2,
        supplier=get_default_supplier(),
        quantity=quantities[1],
        base_unit_price=source.create_price(50),
    )

    source.add_line(
        type=OrderLineType.PRODUCT,
        product=product3,
        supplier=get_default_supplier(),
        quantity=quantities[2],
        base_unit_price=source.create_price(50),
    )

    currency = "EUR"
    summary = source.get_tax_summary()

    assert len(summary) == 1
    summary = summary[0]

    assert summary.taxful == Money(expected, "EUR")
    assert summary.based_on == Money(expected_based_on, "EUR")

    # originally non-rounded value
    assert bankers_round(source.get_total_tax_amount()) == summary.tax_amount

    assert source.taxless_total_price.value == expected_based_on
    assert summary.taxful.value == source.taxful_total_price.value

    assert summary.tax_amount == Money(
        bankers_round(source.taxful_total_price.value -
                      source.taxless_total_price.value), currency)
    assert summary.taxful == summary.raw_based_on + summary.tax_amount

    assert summary.tax_rate == tax.rate
    assert summary.taxful.value == (
        summary.based_on + summary.tax_amount).value - Decimal("%s" % 0.01)

    # create order from basket
    creator = OrderCreator()
    order = creator.create_order(source)
    assert order.taxless_total_price.value == expected_based_on

    # originally non-rounded value
    assert bankers_round(order.get_total_tax_amount()) == summary.tax_amount
Esempio n. 27
0
def test_set_shipping_address(admin_user):
    shop = factories.get_default_shop()
    basket = factories.get_basket()
    factories.get_default_payment_method()
    factories.get_default_shipping_method()
    client = _get_client(admin_user)
    addr1 = factories.get_address()
    addr1.save()

    # use existing address
    payload = {'id': addr1.id}
    response = client.post(
        '/api/shuup/basket/{}-{}/set_shipping_address/'.format(
            shop.pk, basket.key), payload)
    assert response.status_code == status.HTTP_200_OK
    response_data = json.loads(response.content.decode("utf-8"))
    shipping_addr = response_data["shipping_address"]
    assert shipping_addr["id"] == addr1.id
    assert shipping_addr["prefix"] == addr1.prefix
    assert shipping_addr["name"] == addr1.name
    assert shipping_addr["postal_code"] == addr1.postal_code
    assert shipping_addr["street"] == addr1.street
    assert shipping_addr["city"] == addr1.city
    assert shipping_addr["country"] == addr1.country

    # create a new address
    address_data = {
        'name': 'name',
        'prefix': 'prefix',
        'postal_code': 'postal_code',
        'street': 'street',
        'city': 'city',
        'country': 'BR'
    }
    response = client.post(
        '/api/shuup/basket/{}-{}/set_shipping_address/'.format(
            shop.pk, basket.key), address_data)
    assert response.status_code == status.HTTP_200_OK
    response_data = json.loads(response.content.decode("utf-8"))
    shipping_addr = response_data["shipping_address"]
    assert shipping_addr["id"] == addr1.id + 1
    assert shipping_addr["prefix"] == address_data["prefix"]
    assert shipping_addr["name"] == address_data["name"]
    assert shipping_addr["postal_code"] == address_data["postal_code"]
    assert shipping_addr["street"] == address_data["street"]
    assert shipping_addr["city"] == address_data["city"]
    assert shipping_addr["country"] == address_data["country"]

    # get the basket and check the address
    response = client.get('/api/shuup/basket/{}-{}/'.format(
        shop.pk, basket.key))
    assert response.status_code == status.HTTP_200_OK
    response_data = json.loads(response.content.decode("utf-8"))
    shipping_addr = response_data["shipping_address"]
    assert shipping_addr["id"] == addr1.id + 1
    assert shipping_addr["prefix"] == address_data["prefix"]
    assert shipping_addr["name"] == address_data["name"]
    assert shipping_addr["postal_code"] == address_data["postal_code"]
    assert shipping_addr["street"] == address_data["street"]
    assert shipping_addr["city"] == address_data["city"]
    assert shipping_addr["country"] == address_data["country"]
Esempio n. 28
0
def create_order(request, creator, customer, product):
    billing_address = get_address().to_immutable()
    shipping_address = get_address(name="Shippy Doge").to_immutable()
    shipping_address.save()
    default_pm = get_default_payment_method()
    default_sm = get_default_shipping_method()
    shop = request.shop
    order = Order(
        creator=creator,
        customer=customer,
        shop=shop,
        payment_method=default_pm,
        shipping_method=default_sm,
        billing_address=billing_address,
        shipping_address=shipping_address,
        order_date=now(),
        status=get_initial_order_status(),
        currency=shop.currency,
        prices_include_tax=shop.prices_include_tax,
    )
    order.full_clean()
    order.save()
    supplier = get_default_supplier()
    product_order_line = OrderLine(order=order)
    update_order_line_from_product(pricing_context=request,
                                   order_line=product_order_line,
                                   product=product,
                                   quantity=5,
                                   supplier=supplier)

    assert product_order_line.text == product.safe_translation_getter("name")
    product_order_line.base_unit_price = shop.create_price(100)
    assert product_order_line.price.value > 0
    product_order_line.save()

    line_tax = get_line_taxes_for(product_order_line)[0]

    order_line_tax = OrderLineTax.from_tax(
        tax=line_tax.tax,
        base_amount=line_tax.base_amount,
        order_line=product_order_line,
    )
    order_line_tax.save(
    )  # Save order_line_tax before linking to order_line.tax
    product_order_line.taxes.add(order_line_tax)

    discount_order_line = OrderLine(order=order,
                                    quantity=1,
                                    type=OrderLineType.OTHER)
    discount_order_line.discount_amount = shop.create_price(30)
    assert discount_order_line.discount_amount.value == 30
    assert discount_order_line.price.value == -30
    assert discount_order_line.base_unit_price.value == 0
    discount_order_line.save()

    order.cache_prices()
    order.check_all_verified()
    order.save()

    assert not order.can_set_complete()

    base = 5 * shop.create_price(100).amount
    discount = shop.create_price(30).amount
    tax_value = line_tax.amount
    if not order.prices_include_tax:
        assert order.taxless_total_price.amount == base - discount
        assert order.taxful_total_price.amount == base + tax_value - discount
    else:
        assert_almost_equal(order.taxless_total_price.amount,
                            base - tax_value - discount)
        assert_almost_equal(order.taxful_total_price.amount, base - discount)

    assert not order.is_fully_shipped()
    shipment = order.create_shipment_of_all_products(supplier=supplier)
    assert order.is_fully_shipped()

    assert shipment.total_products == 5, "All products were shipped"
    assert shipment.weight == product.gross_weight * 5, "Gravity works"
    assert not order.get_unshipped_products(
    ), "Nothing was left in the warehouse"

    assert order.can_set_complete()

    order.create_payment(order.taxful_total_price)
    assert order.is_paid()
    assert Order.objects.paid().filter(
        pk=order.pk).exists(), "It was paid! Honestly!"
    assert order.has_products()

    assert order.get_available_shipping_methods()
    assert order.get_available_payment_methods()

    assert default_sm in order.get_available_shipping_methods()
    assert default_pm in order.get_available_payment_methods()