Esempio n. 1
0
def allocate(line: OrderLine, space: Space):
    if line.total_volume > space.available_vol:
        raise CantBeAllocated(f'el volumen del sku {line.sku} excede el volumen disponible en el espacio')
    elif line.total_weight > space.available_weight:
        raise CantBeAllocated(f'el peso del sku {line.sku} excede el peso disponible en el espacio')
    else:
        space.allocate(line)
Esempio n. 2
0
def deallocate(line: OrderLine, space: Space):
    for product in space.list_prod():
        if product.sku == line.sku:
            if product.qty == line.qty:
                space.remove_product(product)
            elif product.qty < line.qty:
                raise ValueError(
                    f'El producto {line.sku} excede la cantidad disponible en el espacio'
                )
            product.qty = product.qty - line.qty
Esempio n. 3
0
def test_only_empty_space_can_be_unassigned_from_a_warehouse():
    warehouse = Warehouse("Bodega 1")
    rnd_space_sku1 = random_space('o1')
    rnd_space_sku2 = random_space('o2')
    espacio1 = Space(reference=rnd_space_sku1, max_weigth=50, max_vol=1)
    espacio2 = Space(reference=rnd_space_sku2, max_weigth=50, max_vol=1)

    warehouse.add_space(espacio1)
    warehouse.add_space(espacio2)
    assert warehouse.list_allocated_spaces() == list([espacio1, espacio2])
    warehouse.delete_space(espacio2)
    assert warehouse.list_allocated_spaces() == list([espacio1])
Esempio n. 4
0
def allocate_space(cmd: commands.AllocateSpace,
                   uow: unit_of_work.AbstractUnitOfWork):
    space = Space(cmd.space_reference, cmd.max_weight, cmd.max_vol)
    with uow:
        wh = uow.warehouses.get(cmd.warehouse_ref)
        wh.add_space(space)
        uow.logger.add(events.SpaceAllocated(space_ref=cmd.space_reference))
Esempio n. 5
0
def test_space_can_be_assigned_to_a_warehouse():
    warehouse = Warehouse("Bodega 1")
    rnd_space_sku = random_space('o1')
    espacio = Space(reference=rnd_space_sku, max_weigth=50, max_vol=0.5)

    warehouse.add_space(espacio)
    assert warehouse.get_space(rnd_space_sku) == espacio
Esempio n. 6
0
def test_product_can_not_be_allocated_if_line_exceed_space_weight():
    line = OrderLine('001-LENTES-002 ', 'LENTES TAQUILLEITOR', 10, 50.1, 0.499,
                     'LINEA ABSTRACTA')
    space = Space(reference="A-25-2", max_weigth=50, max_vol=0.5)

    with pytest.raises(CantBeAllocated, match=line.sku):
        allocate(line, space)
Esempio n. 7
0
def test_get_warehouse_master():
    data = {
        "wh_ref":
        "Bodega-1",
        "allocated_spaces": [{
            "reference":
            "espacio-1",
            "max_volume":
            100,
            "max_weight":
            100,
            "productos": [{
                "sku": "sku-001",
                "description": "articulo de prueba",
                "volume_unit": 1,
                "weight_unit": 0.1,
                "qty": 5
            }, {
                "sku": "sku-002",
                "description": "articulo de prueba 2",
                "volume_unit": 0.5,
                "weight_unit": 0.05,
                "qty": 10
            }]
        }]
    }
    wh = Warehouse("Bodega-1")
    space = Space("espacio-1", 100, 100)
    orderline = OrderLine("sku-001", "articulo de prueba", 1, 0.1, 5, "o-l-1")
    orderline2 = OrderLine("sku-002", "articulo de prueba 2", 0.5, 0.05, 10,
                           "o-l-2")
    wh.add_space(space)
    allocate(orderline, wh.get_space('espacio-1'))
    allocate(orderline2, wh.get_space('espacio-1'))
    assert wh.to_dict() == data
Esempio n. 8
0
def test_product_can_not_be_allocated_if_line_exceed_space_volume():
    line = OrderLine(sku='001-LENTES-002 ',
                     description='LENTES TAQUILLEITOR',
                     qty=10,
                     weight_unit=48,
                     volume_unit=0.501,
                     reference='LINEA ABSTRACTA')
    space = Space(reference="A-25-2", max_weigth=50, max_vol=0.5)
    with pytest.raises(CantBeAllocated, match=line.sku):
        allocate(line, space)
Esempio n. 9
0
def test_product_can_be_allocated_only_in_a_space_assigned_to_warehouse():
    wh = Warehouse("Bodega1")
    line = OrderLine(sku='001-LENTES-002',
                     description='LENTES TAQUILLEITOR',
                     qty=10,
                     volume_unit=0.499,
                     weight_unit=49.9,
                     reference='LINEA ABSTRACTA')
    space1 = Space(reference="A-25-2", max_vol=80000, max_weigth=5000000)
    wh.add_space(space1)
    allocate(line, wh.get_space("A-25-2"))
    assert wh.get_space("A-25-2").get_product('001-LENTES-002').sku == line.sku
    assert wh.get_space("A-25-2").get_product(
        '001-LENTES-002').description == line.description
    assert wh.get_space("A-25-2").get_product(
        '001-LENTES-002').weight_unit == line.weight_unit
    assert wh.get_space("A-25-2").get_product(
        '001-LENTES-002').volume_unit == line.volume_unit

    space2 = Space(reference="A-25-3", max_vol=9900, max_weigth=5000)
    with pytest.raises(NotAssignedSpaceException, match=space2.ref):
        allocate(line, space2)
Esempio n. 10
0
def test_product_can_deallocate():
    warehouse = Warehouse("Bodega 1")
    rnd_space_sku1 = random_space('space')
    espacio1 = Space(reference=rnd_space_sku1, max_weigth=500, max_vol=50)
    warehouse.add_space(espacio1)
    line1 = OrderLine(sku=random_sku("lentes"),
                      description='LENTES TAQUILLEITOR',
                      qty=4,
                      volume_unit=.499,
                      weight_unit=49.9,
                      reference='LINEA ABSTRACTA 1')
    line2 = OrderLine(sku=random_sku("zapatos"),
                      description='ZAPATOS TAQUILLEITOR',
                      qty=5,
                      volume_unit=.499,
                      weight_unit=49.9,
                      reference='LINEA ABSTRACTA 2')
    line3 = OrderLine(sku=random_sku("Ollas"),
                      description='OLLAS TAQUILLEITOR',
                      qty=1,
                      volume_unit=.499,
                      weight_unit=49.9,
                      reference='LINEA ABSTRACTA 3')

    allocate(line1, warehouse.get_space(rnd_space_sku1))
    allocate(line2, warehouse.get_space(rnd_space_sku1))
    allocate(line3, warehouse.get_space(rnd_space_sku1))
    assert warehouse.get_space(
        rnd_space_sku1).prods_qty == line1.qty + line2.qty + line3.qty
    assert warehouse.get_space(rnd_space_sku1).available_weight == round(
        espacio1.max_weight - (line1.qty * line1.weight_unit) - \
        (line2.qty * line2.weight_unit) - (
                line3.qty * line3.weight_unit))
    assert warehouse.get_space(rnd_space_sku1).available_vol == espacio1.max_vol - (line1.qty * line1.volume_unit) - \
           (line2.qty * line2.volume_unit) - (line3.qty * line3.volume_unit)
    deallocate(line1, warehouse.get_space(rnd_space_sku1))
    assert warehouse.get_space(
        rnd_space_sku1).prods_qty == line2.qty + line3.qty

    deall_line = (OrderLine(line2.sku, line2.description, line2.volume_unit,
                            line2.weight_unit, 2, "deall_line"))
    deallocate(deall_line, warehouse.get_space(rnd_space_sku1))
    assert warehouse.get_space(rnd_space_sku1).prods_qty == 4

    deall_line2 = (OrderLine(line2.sku, line2.description, line2.volume_unit,
                             line2.weight_unit, 20, "deall_line"))
    with pytest.raises(ValueError, match=deall_line2.sku):
        deallocate(deall_line2, warehouse.get_space(rnd_space_sku1))
    assert warehouse.get_space(rnd_space_sku1).prods_qty == 4
Esempio n. 11
0
def test_only_empty_space_could_be_unassigned():
    warehouse = Warehouse("Bodega 1")
    rnd_space_sku1 = random_space('o1')
    rnd_prod_sku = random_product('TP')
    espacio1 = Space(reference=rnd_space_sku1, max_vol=0.5, max_weigth=50)
    warehouse.add_space(espacio1)
    allocate(
        OrderLine(sku=rnd_prod_sku,
                  description="TERRIBLE PROD",
                  qty=13,
                  volume_unit=0.01,
                  weight_unit=0.5,
                  reference="OL-2"), warehouse.get_space(espacio1.ref))

    with pytest.raises(NotEmpty, match=espacio1.ref):
        warehouse.delete_space(espacio1)
Esempio n. 12
0
def test_update_warehouse_name_in_repository():
    # Given
    fakeWhRep = FakeWarehouseRepository()
    warehouse1 = Warehouse('Bodega-1')
    space1 = Space("space-1", 5, 10)
    warehouse1.add_space(space1)
    order_line1 = OrderLine('1312-4', "producto de pruea", 1, 1, 2,
                            "order line 1")
    allocate(order_line1, space1)
    fakeWhRep.add(warehouse1)
    assert fakeWhRep.get('Bodega-1').get_warehouse_ref() == 'Bodega-1'
    with pytest.raises(EmptyWarehouseReference):
        fakeWhRep.get('Bodega-1').change_warehouse_ref('')
    fakeWhRep.get('Bodega-1').change_warehouse_ref('Bodega-2')
    assert fakeWhRep.get('Bodega-2').get_space('space-1').get_product(
        '1312-4').description == "producto de pruea"
Esempio n. 13
0
 def add_space(self, space: Space):
     space.space_assigned()
     self.allocated_spaces.append(space)