Esempio n. 1
0
def test_kg_in_oz():
    kg_oz = UnitInterface(display_unit=DisplayUnit(
        internal_unit=get_kilogram_sales_unit(decimals=9),
        ratio=Decimal('0.028349523'),
        decimals=3, symbol='oz'))
    assert kg_oz.comparison_quantity == Decimal('0.028349523')
    assert kg_oz.render_quantity('0.028349523') == '1.000oz'
    assert kg_oz.render_quantity(1) == '35.274oz'
    assert kg_oz.render_quantity(0.001) == '0.035oz'
    assert kg_oz.from_display(Decimal('0.001')) == Decimal('0.000028350')
    assert kg_oz.to_display(Decimal('0.000028350')) == approx('0.001')
Esempio n. 2
0
def test_kg_in_oz():
    kg_oz = UnitInterface(display_unit=DisplayUnit(
        internal_unit=get_kilogram_sales_unit(decimals=9),
        ratio=Decimal('0.028349523'),
        decimals=3, symbol='oz'))
    assert kg_oz.comparison_quantity == Decimal('0.028349523')
    assert kg_oz.render_quantity('0.028349523') == '1.000oz'
    assert kg_oz.render_quantity(1) == '35.274oz'
    assert kg_oz.render_quantity(0.001) == '0.035oz'
    assert kg_oz.from_display(Decimal('0.001')) == Decimal('0.000028350')
    assert kg_oz.to_display(Decimal('0.000028350')) == approx('0.001')
Esempio n. 3
0
def test_kg_in_oz():
    kg_oz = UnitInterface(
        display_unit=DisplayUnit(
            internal_unit=get_kilogram_sales_unit(decimals=9), ratio=Decimal("0.028349523"), decimals=3, symbol="oz"
        )
    )
    assert kg_oz.comparison_quantity == Decimal("0.028349523")
    assert kg_oz.render_quantity("0.028349523") == "1.000oz"
    assert kg_oz.render_quantity(1) == "35.274oz"
    assert kg_oz.render_quantity(0.001) == "0.035oz"
    assert kg_oz.from_display(Decimal("0.001")) == Decimal("0.000028350")
    assert kg_oz.to_display(Decimal("0.000028350")) == approx("0.001")
Esempio n. 4
0
    def get_content(self, instance):
        shipment_products = ShipmentProduct.objects.filter(
            shipment=instance).select_related("product", "product__sales_unit")
        content = []

        for shipment_product in shipment_products:
            unit = UnitInterface(shipment_product.product.sales_unit)
            quantity = unit.render_quantity(shipment_product.quantity)
            content.append(f"{shipment_product.product} ({quantity})")
        return ", ".join(content)
Esempio n. 5
0
def test_unit_interface_render_quantity_pieces():
    pcs = UnitInterface(PiecesSalesUnit())
    with translation.override('en'):
        assert pcs.render_quantity(123) == '123'
        assert pcs.render_quantity(1234567) == '1,234,567'
        assert pcs.render_quantity(0.123) == '0'
        assert pcs.render_quantity('52.1') == '52'
        assert pcs.render_quantity('52.5') == '53'
        assert pcs.render_quantity('53.5') == '54'
        assert pcs.render_quantity(123, force_symbol=True) == '123pc.'
Esempio n. 6
0
def test_unit_interface_render_quantity_pieces():
    pcs = UnitInterface(PiecesSalesUnit())
    with translation.override('en'):
        assert pcs.render_quantity(123) == '123'
        assert pcs.render_quantity(1234567) == '1,234,567'
        assert pcs.render_quantity(0.123) == '0'
        assert pcs.render_quantity('52.1') == '52'
        assert pcs.render_quantity('52.5') == '53'
        assert pcs.render_quantity('53.5') == '54'
        assert pcs.render_quantity(123, force_symbol=True) == '123pc.'
Esempio n. 7
0
def test_unit_interface_render_quantity_pieces():
    pcs = UnitInterface(PiecesSalesUnit())
    with translation.override("en"):
        assert pcs.render_quantity(123) == "123"
        assert pcs.render_quantity(1234567) == "1,234,567"
        assert pcs.render_quantity(0.123) == "0"
        assert pcs.render_quantity("52.1") == "52"
        assert pcs.render_quantity("52.5") == "53"
        assert pcs.render_quantity("53.5") == "54"
        assert pcs.render_quantity(123, force_symbol=True) == "123pc."