コード例 #1
0
ファイル: test_vatlayer.py プロジェクト: joaqoliva/ecommerce
def test_calculate_order_line_unit(vatlayer, order_line, shipping_zone, site_settings):
    manager = get_extensions_manager(
        plugins=["saleor.extensions.plugins.vatlayer.plugin.VatlayerPlugin"]
    )
    order_line.unit_price = TaxedMoney(
        net=Money("10.00", "USD"), gross=Money("10.00", "USD")
    )
    order_line.save()

    order = order_line.order
    method = shipping_zone.shipping_methods.get()
    order.shipping_address = order.billing_address.get_copy()
    order.shipping_method_name = method.name
    order.shipping_method = method
    order.save()

    product = order_line.variant.product
    manager.assign_tax_code_to_object_meta(product, "standard")
    product.save()

    line_price = manager.calculate_order_line_unit(order_line)
    line_price = quantize_price(line_price, line_price.currency)
    assert line_price == TaxedMoney(
        net=Money("8.13", "USD"), gross=Money("10.00", "USD")
    )
コード例 #2
0
ファイル: test_avatax.py プロジェクト: xyzlat/saleor
def test_calculate_order_line_unit(order_line, shipping_zone, site_settings,
                                   address_usa, settings):
    settings.AVATAX_USERNAME_OR_ACCOUNT = "test"
    settings.AVATAX_PASSWORD_OR_LICENSE = "test"
    settings.PLUGINS = ["saleor.extensions.plugins.avatax.plugin.AvataxPlugin"]

    manager = get_extensions_manager(plugins=settings.PLUGINS)
    order_line.unit_price = TaxedMoney(net=Money("10.00", "USD"),
                                       gross=Money("10.00", "USD"))
    order_line.save()

    order = order_line.order
    method = shipping_zone.shipping_methods.get()
    order.shipping_address = order.billing_address.get_copy()
    order.shipping_method_name = method.name
    order.shipping_method = method
    order.save()

    site_settings.company_address = address_usa
    site_settings.save()

    line_price = manager.calculate_order_line_unit(order_line)
    line_price = quantize_price(line_price, line_price.currency)
    assert line_price == TaxedMoney(net=Money("8.13", "USD"),
                                    gross=Money("10.00", "USD"))
コード例 #3
0
def test_calculate_checkout_line_total(
    with_discount,
    expected_net,
    expected_gross,
    taxes_in_prices,
    discount_info,
    checkout_with_item,
    address,
    address_usa,
    site_settings,
    monkeypatch,
    shipping_zone,
):
    monkeypatch.setattr(
        "saleor.core.taxes.avatax.interface.get_cached_tax_codes_or_fetch",
        lambda: {"PC040156": "desc"},
    )
    checkout_with_item.address = address
    checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()
    checkout_with_item.save()
    site_settings.company_address = address_usa
    site_settings.include_taxes_in_prices = taxes_in_prices
    site_settings.save()
    line = checkout_with_item.lines.first()
    product = line.variant.product
    interface.assign_tax_to_object_meta(product, "PC040156")
    product.save()
    discounts = [discount_info] if with_discount else None
    total = interface.calculate_checkout_line_total(line, discounts)
    total = quantize_price(total, total.currency)
    assert total == TaxedMoney(net=Money(expected_net, "USD"),
                               gross=Money(expected_gross, "USD"))
コード例 #4
0
ファイル: test_avatax.py プロジェクト: xyzlat/saleor
def test_calculate_checkout_shipping(
    checkout_with_item,
    shipping_zone,
    discount_info,
    address,
    address_usa,
    site_settings,
    monkeypatch,
    settings,
):
    settings.AVATAX_USERNAME_OR_ACCOUNT = "test"
    settings.AVATAX_PASSWORD_OR_LICENSE = "test"
    settings.PLUGINS = ["saleor.extensions.plugins.avatax.plugin.AvataxPlugin"]
    monkeypatch.setattr(
        "saleor.extensions.plugins.avatax.plugin.get_cached_tax_codes_or_fetch",
        lambda _: {"PC040156": "desc"},
    )
    manager = get_extensions_manager(plugins=settings.PLUGINS)
    site_settings.company_address = address_usa
    site_settings.save()

    checkout_with_item.shipping_address = address
    checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()
    checkout_with_item.save()
    shipping_price = manager.calculate_checkout_shipping(
        checkout_with_item, [discount_info])
    shipping_price = quantize_price(shipping_price, shipping_price.currency)
    assert shipping_price == TaxedMoney(net=Money("8.13", "USD"),
                                        gross=Money("10.00", "USD"))
コード例 #5
0
def test_calculate_checkout_subtotal(
    site_settings,
    vatlayer,
    checkout_with_item,
    address,
    shipping_zone,
    discount_info,
    with_discount,
    expected_net,
    expected_gross,
    taxes_in_prices,
    variant,
):
    site_settings.include_taxes_in_prices = taxes_in_prices
    site_settings.save()

    checkout_with_item.shipping_address = address
    checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()
    checkout_with_item.save()

    manager = get_extensions_manager(
        plugins=["saleor.extensions.plugins.vatlayer.plugin.VatlayerPlugin"])

    product = variant.product
    manager.assign_tax_code_to_object_meta(product, "standard")
    product.save()

    discounts = [discount_info] if with_discount else None
    add_variant_to_checkout(checkout_with_item, variant, 2)
    total = manager.calculate_checkout_subtotal(checkout_with_item, discounts)
    total = quantize_price(total, total.currency)
    assert total == TaxedMoney(net=Money(expected_net, "USD"),
                               gross=Money(expected_gross, "USD"))
コード例 #6
0
def test_calculate_checkout_shipping(
    checkout_with_item,
    shipping_zone,
    discount_info,
    address,
    address_usa,
    site_settings,
    monkeypatch,
):
    monkeypatch.setattr(
        "saleor.core.taxes.avatax.interface.get_cached_tax_codes_or_fetch",
        lambda: {"PC040156": "desc"},
    )

    site_settings.company_address = address_usa
    site_settings.save()

    checkout_with_item.address = address
    checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()
    checkout_with_item.save()
    shipping_price = interface.calculate_checkout_shipping(
        checkout_with_item, [discount_info])
    shipping_price = quantize_price(shipping_price, shipping_price.currency)
    assert shipping_price == TaxedMoney(net=Money("8.13", "USD"),
                                        gross=Money("10.00", "USD"))
コード例 #7
0
def test_calculate_order_line_unit(
    order_line,
    shipping_zone,
    site_settings,
    address_usa,
    plugin_configuration,
):
    plugin_configuration()
    manager = get_plugins_manager(
        plugins=["saleor.plugins.avatax.plugin.AvataxPlugin"])
    order_line.unit_price = TaxedMoney(net=Money("10.00", "USD"),
                                       gross=Money("10.00", "USD"))
    order_line.save()

    order = order_line.order
    method = shipping_zone.shipping_methods.get()
    order.shipping_address = order.billing_address.get_copy()
    order.shipping_method_name = method.name
    order.shipping_method = method
    order.save()

    site_settings.company_address = address_usa
    site_settings.save()

    line_price = manager.calculate_order_line_unit(order_line)
    line_price = quantize_price(line_price, line_price.currency)

    assert line_price == TaxedMoney(net=Money("8.13", "USD"),
                                    gross=Money("10.00", "USD"))
コード例 #8
0
def test_calculate_checkout_shipping(
    checkout_with_item,
    shipping_zone,
    discount_info,
    address,
    address_usa,
    site_settings,
    monkeypatch,
    plugin_configuration,
):
    plugin_configuration()
    monkeypatch.setattr(
        "saleor.plugins.avatax.plugin.get_cached_tax_codes_or_fetch",
        lambda _: {"PC040156": "desc"},
    )
    manager = get_plugins_manager(
        plugins=["saleor.plugins.avatax.plugin.AvataxPlugin"])
    site_settings.company_address = address_usa
    site_settings.save()

    checkout_with_item.shipping_address = address
    checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()
    checkout_with_item.save()
    shipping_price = manager.calculate_checkout_shipping(
        checkout_with_item, list(checkout_with_item), [discount_info])
    shipping_price = quantize_price(shipping_price, shipping_price.currency)
    assert shipping_price == TaxedMoney(net=Money("8.13", "USD"),
                                        gross=Money("10.00", "USD"))
コード例 #9
0
ファイル: test_vatlayer.py プロジェクト: joaqoliva/ecommerce
def test_calculate_order_shipping(vatlayer, order_line, shipping_zone, site_settings):
    manager = get_extensions_manager(
        plugins=["saleor.extensions.plugins.vatlayer.plugin.VatlayerPlugin"]
    )
    order = order_line.order
    method = shipping_zone.shipping_methods.get()
    order.shipping_address = order.billing_address.get_copy()
    order.shipping_method_name = method.name
    order.shipping_method = method
    order.save()
    price = manager.calculate_order_shipping(order)
    price = quantize_price(price, price.currency)
    assert price == TaxedMoney(net=Money("8.13", "USD"), gross=Money("10.00", "USD"))
コード例 #10
0
def test_calculate_order_shipping(order_line, shipping_zone, site_settings,
                                  address_usa):
    order = order_line.order
    method = shipping_zone.shipping_methods.get()
    order.address = order.address.get_copy()
    order.shipping_method_name = method.name
    order.shipping_method = method
    order.save()

    site_settings.company_address = address_usa
    site_settings.save()

    price = interface.calculate_order_shipping(order)
    price = quantize_price(price, price.currency)
    assert price == TaxedMoney(net=Money("8.13", "USD"),
                               gross=Money("10.00", "USD"))
コード例 #11
0
ファイル: test_avatax.py プロジェクト: paranoiasystem/saleor
def test_calculate_checkout_total(
    with_discount,
    expected_net,
    expected_gross,
    voucher_amount,
    taxes_in_prices,
    checkout_with_item,
    discount_info,
    shipping_zone,
    address,
    address_usa,
    site_settings,
    monkeypatch,
    settings,
):
    settings.AVATAX_USERNAME_OR_ACCOUNT = "test"
    settings.AVATAX_PASSWORD_OR_LICENSE = "test"
    settings.PLUGINS = ["saleor.extensions.plugins.avatax.plugin.AvataxPlugin"]
    monkeypatch.setattr(
        "saleor.extensions.plugins.avatax.plugin.get_cached_tax_codes_or_fetch",
        lambda _: {"PC040156": "desc"},
    )
    manager = get_extensions_manager(plugins=settings.PLUGINS)
    checkout_with_item.shipping_address = address
    checkout_with_item.save()
    site_settings.company_address = address_usa
    site_settings.include_taxes_in_prices = taxes_in_prices

    voucher_amount = Money(voucher_amount, "USD")
    checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()
    checkout_with_item.discount = voucher_amount
    checkout_with_item.save()
    line = checkout_with_item.lines.first()
    product = line.variant.product
    manager.assign_tax_code_to_object_meta(product, "PC040156")
    product.save()

    discounts = [discount_info] if with_discount else None
    total = manager.calculate_checkout_total(checkout_with_item, discounts)
    total = quantize_price(total, total.currency)
    assert total == TaxedMoney(
        net=Money(expected_net, "USD"), gross=Money(expected_gross, "USD")
    )
コード例 #12
0
def test_calculate_checkout_subtotal(
    with_discount,
    expected_net,
    expected_gross,
    taxes_in_prices,
    discount_info,
    checkout_with_item,
    stock,
    monkeypatch,
    site_settings,
    address_usa,
    shipping_zone,
    address,
    plugin_configuration,
):
    plugin_configuration()
    variant = stock.product_variant
    monkeypatch.setattr(
        "saleor.plugins.avatax.plugin.get_cached_tax_codes_or_fetch",
        lambda _: {"PC040156": "desc"},
    )
    manager = get_plugins_manager(
        plugins=["saleor.plugins.avatax.plugin.AvataxPlugin"])
    site_settings.company_address = address_usa
    site_settings.include_taxes_in_prices = taxes_in_prices
    site_settings.save()

    checkout_with_item.shipping_address = address
    checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()
    checkout_with_item.save()

    discounts = [discount_info] if with_discount else None
    add_variant_to_checkout(checkout_with_item, variant, 2)
    total = manager.calculate_checkout_subtotal(checkout_with_item,
                                                list(checkout_with_item),
                                                discounts)
    total = quantize_price(total, total.currency)
    assert total == TaxedMoney(net=Money(expected_net, "USD"),
                               gross=Money(expected_gross, "USD"))
コード例 #13
0
ファイル: test_avatax.py プロジェクト: sbh-woodcutter/saleor
def test_calculate_checkout_line_total(
    with_discount,
    expected_net,
    expected_gross,
    taxes_in_prices,
    discount_info,
    checkout_with_item,
    address,
    address_usa,
    site_settings,
    monkeypatch,
    shipping_zone,
    plugin_configuration,
):
    plugin_configuration()
    monkeypatch.setattr(
        "saleor.extensions.plugins.avatax.plugin.get_cached_tax_codes_or_fetch",
        lambda _: {"PC040156": "desc"},
    )
    manager = get_extensions_manager(
        plugins=["saleor.extensions.plugins.avatax.plugin.AvataxPlugin"])

    checkout_with_item.shipping_address = address
    checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()
    checkout_with_item.save()
    site_settings.company_address = address_usa
    site_settings.include_taxes_in_prices = taxes_in_prices
    site_settings.save()
    line = checkout_with_item.lines.first()
    product = line.variant.product
    manager.assign_tax_code_to_object_meta(product, "PC040156")
    product.save()
    discounts = [discount_info] if with_discount else None
    total = manager.calculate_checkout_line_total(line, discounts)
    total = quantize_price(total, total.currency)
    assert total == TaxedMoney(net=Money(expected_net, "USD"),
                               gross=Money(expected_gross, "USD"))
コード例 #14
0
def test_calculate_checkout_total(
    site_settings,
    vatlayer,
    checkout_with_item,
    address,
    shipping_zone,
    discount_info,
    with_discount,
    expected_net,
    expected_gross,
    voucher_amount,
    taxes_in_prices,
):
    manager = get_plugins_manager(
        plugins=["saleor.plugins.vatlayer.plugin.VatlayerPlugin"])
    checkout_with_item.shipping_address = address
    checkout_with_item.save()
    voucher_amount = Money(voucher_amount, "USD")
    checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()
    checkout_with_item.discount = voucher_amount
    checkout_with_item.save()
    line = checkout_with_item.lines.first()
    product = line.variant.product
    manager.assign_tax_code_to_object_meta(product, "standard")
    product.save()

    site_settings.include_taxes_in_prices = taxes_in_prices
    site_settings.save()

    discounts = [discount_info] if with_discount else None
    total = manager.calculate_checkout_total(checkout_with_item,
                                             list(checkout_with_item),
                                             discounts)
    total = quantize_price(total, total.currency)
    assert total == TaxedMoney(net=Money(expected_net, "USD"),
                               gross=Money(expected_gross, "USD"))
コード例 #15
0
def test_calculate_order_line_unit(order_line):
    assert interface.calculate_order_line_unit(order_line) == quantize_price(
        order_line.unit_price, order_line.unit_price.currency
    )