Esempio n. 1
0
 def update_address(self, instance, field_name, validated_address_data):
     if not validated_address_data:
         return None
     contact_address = getattr(instance, field_name)
     if contact_address:
         MutableAddress.objects.filter(pk=contact_address.pk).update(
             **validated_address_data)
         contact_address.refresh_from_db()
     else:
         address = MutableAddress(**validated_address_data)
         address.save()
         setattr(instance, field_name, address)
         instance.save()
Esempio n. 2
0
def test_stacked_tax_taxful_price():
    shop = get_shop(prices_include_tax=True, currency='EUR')
    source = OrderSource(shop)
    assert source.prices_include_tax
    source.add_line(type=OrderLineType.OTHER,
                    quantity=1,
                    base_unit_price=source.create_price(20))
    with override_provides("tax_module", TAX_MODULE_SPEC):
        with override_settings(WSHOP_TAX_MODULE="irvine"):
            source.shipping_address = MutableAddress(
                street="16215 Alton Pkwy",
                postal_code="92602",
            )
            line = source.get_final_lines(with_taxes=True)[0]
            assert isinstance(line, SourceLine)
            assert line.taxes
            assert line.taxful_price == TaxfulPrice(20, 'EUR')
            assert_almost_equal(line.taxless_price,
                                TaxlessPrice("18.52", 'EUR'))
            source.uncache()

            # Let's move out to a taxless location.
            source.shipping_address.postal_code = "11111"
            line = source.get_final_lines(with_taxes=True)[0]
            assert isinstance(line, SourceLine)
            assert not line.taxes
            assert line.taxful_price == TaxfulPrice(20, source.currency)
            assert line.taxless_price.value == Decimal("20")
Esempio n. 3
0
def test_home_country_in_address():
    with override("fi"):
        finnish_address = MutableAddress(country="FI")
        with override_settings(WSHOP_ADDRESS_HOME_COUNTRY="US"):
            assert "Suomi" in str(
                finnish_address
            ), "When home is not Finland, Finland appears in address string"
        with override_settings(WSHOP_ADDRESS_HOME_COUNTRY="FI"):
            assert "Suomi" not in str(
                finnish_address
            ), "When home is Finland, Finland does not appear in address string"
Esempio n. 4
0
def create_random_address(fake=None, **values):
    if not fake:
        fake = get_faker(["person", "address"])
    empty = str  # i.e. constructor for empty string
    values.setdefault("name", fake.name())
    values.setdefault("street", fake.address().replace('\n', ' '))
    values.setdefault("city", fake.city())
    values.setdefault("region", getattr(fake, "state", empty)())
    values.setdefault("country", random.choice(COUNTRY_CODES))
    values.setdefault("postal_code", getattr(fake, "postalcode", empty)())
    address = MutableAddress.from_data(values)
    address.save()
    return address
Esempio n. 5
0
    def handle_row_address(self, fields, row_session):
        row = row_session.row
        contact = row_session.instance
        data = {}
        for field in fields:
            data[field.replace(" ", "_")] = row.get(field, "")
        data["name"] = contact.name
        data["email"] = contact.email
        data["phone"] = contact.phone
        data["name_ext"] = contact.name_ext

        if hasattr(contact, "tax_number"):
            data["tax_number"] = contact.tax_number

        address = MutableAddress.from_data(data)
        address.save()
        contact.default_shipping_address = address
        contact.default_billing_address = address
        contact.save()
Esempio n. 6
0
 def _get_address(self, address, is_company, save):
     if self.is_empty_address(address):
         return None
     address_form = forms.modelform_factory(MutableAddress, exclude=[])
     address_form_instance = address_form(data=address)
     address_form_instance.full_clean()
     if not address_form_instance.is_valid():
         for field_name, errors in address_form_instance.errors.items():
             field_label = address_form_instance.fields[field_name].label
             for error_msg in errors:
                 self.add_error(
                     ValidationError(
                         "%(field_label)s: %(error_msg)s" % {"field_label": field_label, "error_msg": error_msg},
                         code="invalid_address"
                     )
                 )
         return None
     if is_company and not address_form_instance.cleaned_data["tax_number"]:
         self.add_error(ValidationError(_("Tax number is not set for company."), code="no_tax_number"))
         return None
     if save:
         return address_form_instance.save()
     return MutableAddress.from_data(address_form_instance.cleaned_data)
Esempio n. 7
0
def get_address(**overrides):
    data = dict(DEFAULT_ADDRESS_DATA, **overrides)
    return MutableAddress.from_data(data)
Esempio n. 8
0
def test_partial_address_fails():
    address = MutableAddress(name=u"Dog Hello")
    with pytest.raises(ValidationError):
        address.full_clean()