Exemple #1
0
def test_sales_ranges_update_after_range_update():
    shop = get_default_shop()
    supplier = get_default_supplier()
    person = create_random_person()
    company = create_random_company()
    create_fully_paid_order(shop, person, supplier, "sku1", 50)
    create_fully_paid_order(shop, company, supplier, "sku2", 100)
    assert get_total_sales(shop, person) == 50
    assert get_total_sales(shop, company) == 100

    sales_range = create_sales_range("gold", shop, 10, 90)
    assert sales_range.group in person.groups.all()
    assert sales_range.group not in company.groups.all()

    sales_range.max_value = None
    sales_range.save()
    assert sales_range.group in person.groups.all()
    assert sales_range.group in company.groups.all()

    # Make sure customers is actually removed when range changes
    sales_range.max_value = 60
    sales_range.save()
    assert sales_range.group in person.groups.all()
    assert sales_range.group not in company.groups.all()

    # Inactive ranges shouldn't update group members
    sales_range.min_value = None
    sales_range.save()
    assert sales_range.group in person.groups.all()
    assert sales_range.group not in company.groups.all()
def test_encode_address():
    contact = create_random_company()
    address = contact.default_billing_address
    address.save()

    assert not address.tax_number

    encoded = encode_address(address)
    for field, value in encoded.items():
        assert getattr(address, field) == value

    # If no tax number, use tax_number argument
    encoded = encode_address(address, tax_number="12345")
    for field, value in encoded.items():
        if field == "tax_number":
            assert value == "12345"
        else:
            assert getattr(address, field) == value

    address.tax_number = "67890"
    address.save()

    # If tax number exists, use existing tax number
    encoded = encode_address(address, tax_number="12345")
    for field, value in encoded.items():
        if field == "tax_number":
            assert value == "67890"
        else:
            assert getattr(address, field) == value
def test_company_contact_creation(rf, admin_user):
    get_initial_order_status()
    contact = create_random_company()
    test_tax_number = "1234567-1"
    contact.tax_number = test_tax_number
    contact.save()
    contact.default_billing_address.tax_number = test_tax_number
    contact.default_billing_address.save()
    state = get_frontend_order_state(contact=contact)
    state["customer"] = {
        "id": None,
        "name": None,
        "billingAddress": encode_address(contact.default_billing_address),
        "shipToBillingAddress": True,
        "saveAddress": True,
        "isCompany": True
    }
    order = get_order_from_state(state, admin_user)
    assert order.lines.count() == 5
    assert order.customer.id != contact.id
    assert order.customer.name == contact.name
    assert order.customer.tax_number == test_tax_number
    assert order.billing_address.tax_number == contact.default_billing_address.tax_number
    assert order.billing_address.street == contact.default_billing_address.street
    assert order.billing_address.street == order.shipping_address.street
def test_order_customer_name_from_customer():
    company = create_random_company()
    person = create_random_person()
    order = create_empty_order()
    order.customer = company
    order.orderer = person
    order.save()
    order.refresh_from_db()
    assert order.shipping_address_id is not None
    assert order.billing_address_id is not None
    assert order.orderer_id is not None
    assert order.get_customer_name() == order.customer.name
Exemple #5
0
def test_customer_company_member(regular_user):
    get_default_shop()  # Create a shop

    mw = E-CommerceFrontMiddleware()
    request = get_unprocessed_request()
    request.user = regular_user
    person = get_person_contact(regular_user)
    company = create_random_company()
    company.members.add(person)

    assert get_company_contact(regular_user) == company

    mw.process_request(request)

    check_request_attribute_basics(request)

    assert isinstance(request.person, PersonContact)
    assert isinstance(request.customer, CompanyContact)

    company = get_company_contact(request.user)
    assert company and (company == request.customer)
def test_address_assigned_for_multiple_contact():
    person1 = create_random_person()
    person2 = create_random_company()
    address = create_random_address()
    person1.default_billing_address = address
    person1.save()
    person2.default_shipping_address = address
    person2.save()

    assert person1.default_billing_address.id == address.id
    assert person2.default_shipping_address.id == address.id

    form = MutableAddressForm(instance=address)
    data = get_form_data(form, prepared=True)
    form = MutableAddressForm(data=data, instance=address)
    form.full_clean()
    assert not form.errors
    assert form.cleaned_data
    form.save()
    address.refresh_from_db()
    assert person1.default_billing_address_id != address.id
    assert person2.default_shipping_address_id != address.id
def test_order_creator_customer_details(rf, admin_user):
    shop = get_default_shop()
    contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
    company = create_random_company()
    group = get_default_customer_group()
    contact.groups.add(group)
    contact.company_memberships.add(company)
    contact.save()
    product = create_product(
        sku=printable_gibberish(),
        supplier=get_default_supplier(),
        shop=shop
    )
    order = create_random_order(contact, products=[product])
    request = apply_request_middleware(rf.get("/", {
        "command": "customer_details",
        "id": contact.id
    }), user=admin_user)
    response = OrderEditView.as_view()(request)
    data = json.loads(response.content.decode("utf8"))

    assert "customer_info" in data
    assert "order_summary" in data
    assert "recent_orders" in data
    assert data["customer_info"]["name"] == contact.full_name
    assert data["customer_info"]["phone_no"] == contact.phone
    assert data["customer_info"]["email"] == contact.email
    assert company.full_name in data["customer_info"]["companies"]
    assert group.name in data["customer_info"]["groups"]
    assert data["customer_info"]["merchant_notes"] == contact.merchant_notes
    assert len(data["order_summary"]) == 1
    assert data["order_summary"][0]["year"] == order.order_date.year
    assert data["order_summary"][0]["total"] == format_money(order.taxful_total_price)
    assert len(data["recent_orders"]) == 1
    assert data["recent_orders"][0]["status"] == order.get_status_display()
    assert data["recent_orders"][0]["total"] == format_money(order.taxful_total_price)
    assert data["recent_orders"][0]["payment_status"] == force_text(order.payment_status.label)
    assert data["recent_orders"][0]["shipment_status"] == force_text(order.shipping_status.label)
Exemple #8
0
def _create_customer_for_day(shop, day):
    company = create_random_company()
    company.created_on = day
    company.save()