def test_company_contact_name_ext(): company = CompanyContact(name="TestCompany") assert company.name == "TestCompany" assert company.full_name == "TestCompany" company.name_ext = "California" company.save() assert company.name == "TestCompany" assert company.full_name == "TestCompany / California"
def test_discount_for_logged_in_contacts(rf): default_price = 10 request, product = _init_test_for_product(rf, default_price) assert request.customer == AnonymousContact() product_discount_amount = 2 Discount.objects.create( shop=request.shop, active=True, contact_group=PersonContact.get_default_group(), discount_amount_value=product_discount_amount, ) Discount.objects.create( shop=request.shop, active=True, contact_group=CompanyContact.get_default_group(), discount_amount_value=product_discount_amount, ) assert product.get_price_info(request).price == request.shop.create_price( default_price) # setting customer to request should apply the discount request.customer = factories.create_random_person() assert product.get_price_info(request).price == request.shop.create_price( default_price - product_discount_amount) # Company as customer should work too request.customer = factories.create_random_company() assert product.get_price_info(request).price == request.shop.create_price( default_price - product_discount_amount)
def _create_contact_from_address(self, billing_address, is_company): name = billing_address.get("name", None) phone = billing_address.get("phone", "") email = billing_address.get("email", "") fields = {"name": name, "phone": phone, "email": email} if is_company: tax_number = billing_address.get("tax_number", None) fields.update({"tax_number": tax_number}) customer = CompanyContact(**fields) else: customer = PersonContact(**fields) return customer
def test_company_still_linked_if_customer_contact_edited(regular_user): get_default_shop() person = get_person_contact(regular_user) assert not get_company_contact(regular_user) company = CompanyContact() company.save() company.members.add(person) assert get_company_contact(regular_user) client = SmartClient() client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD) customer_edit_url = reverse("shuup:customer_edit") soup = client.soup(customer_edit_url) data = default_customer_data() data.update(default_address_data("billing")) data.update(default_address_data("shipping")) response, soup = client.response_and_soup(customer_edit_url, data, "post") assert response.status_code == 302 assert get_company_contact(regular_user)
def test_display_queryset(regular_user): shop = get_default_shop() anonymous_group = AnonymousContact().get_default_group() PersonContact().get_default_group() CompanyContact().get_default_group() assert get_groups_for_price_display_create(shop).count() == 3 assert get_price_displays_for_shop(None).count() == 3 assert get_price_displays_for_shop(shop).count() == 3 get_person_contact(regular_user) assert get_price_displays_for_shop(shop).count() == 3 # create new group display (from admin usually) ContactGroupPriceDisplay.objects.create(group=anonymous_group, shop=shop) for_create = get_groups_for_price_display_create(shop) assert for_create.count() == 2 assert anonymous_group not in for_create items = get_price_displays_for_shop(shop) assert items.count() == 3 for item in items: if item.group == anonymous_group: assert item.shop else: assert not item.shop assert item.group.identifier in PROTECTED_CONTACT_GROUP_IDENTIFIERS new_group = ContactGroup.objects.create(identifier="test", shop=shop) items = get_price_displays_for_shop(shop) assert items.count() == 4 for item in items: if item.group in [new_group, anonymous_group]: assert item.shop else: assert not item.shop if item.group != new_group: assert item.group.identifier in PROTECTED_CONTACT_GROUP_IDENTIFIERS else: assert item.group.identifier == "test"
def _create_contact_from_address(self, billing_address, is_company): name = billing_address.get("name", None) if not name: self.add_error( ValidationError(_("Name is required for customer"), code="no_name")) return phone = billing_address.get("phone", "") email = billing_address.get("email", "") fields = {"name": name, "phone": phone, "email": email} if is_company: tax_number = billing_address.get("tax_number", None) if not tax_number: self.add_error( ValidationError(_("Tax number is not set for company."), code="no_tax_number")) return fields.update({"tax_number": tax_number}) customer = CompanyContact(**fields) else: customer = PersonContact(**fields) return customer
def test_discount_for_companies(rf): default_price = 10 request, product = _init_test_for_product(rf, default_price) assert request.customer == AnonymousContact() product_discount_amount = 2 Discount.objects.create( shop=request.shop, active=True, contact_group=CompanyContact.get_default_group(), discount_amount_value=product_discount_amount, ) assert product.get_price_info(request).price == request.shop.create_price( default_price) # Setting customer to request activates the discount request.customer = factories.create_random_company() assert product.get_price_info(request).price == request.shop.create_price( default_price - product_discount_amount) # Using person contact as customer means no discount request.customer = factories.create_random_person() assert product.get_price_info(request).price == request.shop.create_price( default_price)
def test_default_company_contact_group_repr_and_str(): cdg = CompanyContact.get_default_group() assert repr(cdg) == '<ContactGroup:%d-default_company_group>' % cdg.pk assert str(cdg) == 'Company Contacts'
def save(self, commit=True): def populate_address(needle): data = {} delete = [] for k, value in six.iteritems(self.cleaned_data): if k.startswith(needle): key = k.replace(needle, "") data[key] = value delete.append(k) # sweep unneeded keys for k in delete: del self.cleaned_data[k] return data contact_address_data = populate_address("contact_") company_address_data = populate_address("company_") user = super(CompanyRegistrationForm, self).save(commit) website = company_address_data.pop("www") contact_address = MutableAddress.from_data(contact_address_data) contact_address.save() company_address = MutableAddress.from_data(company_address_data) company_address.save() contact = PersonContact() contact.is_active = False contact.user = user contact.email = user.email contact.default_shipping_address = contact_address contact.default_billing_address = contact_address contact.first_name = contact_address_data["first_name"] contact.last_name = contact_address_data["last_name"] contact.phone = contact_address.phone contact.save() company = CompanyContact() company.default_shipping_address = company_address company.default_billing_address = company_address company.is_active = False company.phone = company_address.phone company.www = website company.name = company_address_data["name"] company.name_ext = company_address_data["name_ext"] company.tax_number = company_address_data["tax_number"] company.email = company_address_data["email"] company.save() company.members.add(contact) return user