def test_unsaved_contact(admin_user):
    payment_method = get_default_payment_method()
    _assign_component_for_service(payment_method, [PersonContact.get_default_group()])
    person = PersonContact(name="Kalle")
    source = _get_source_for_contact(admin_user, payment_method)
    source.customer = person
    assert not person.pk and not source.customer.pk
    _test_service_availability(source, payment_method, False)
Example #2
0
 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
Example #3
0
    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
Example #4
0
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"
Example #5
0
    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
Example #6
0
def test_person_name_init_by_first_and_last_name():
    john = PersonContact(first_name="John", last_name="Smith")
    assert john.name == "John Smith"
    assert john.first_name == "John"
    assert john.last_name == "Smith"
Example #7
0
 def filter(self):
     return json.dumps({"groups": [PersonContact().default_group.pk]})