M
M
mx60012019-03-01 22:05:33
Python
mx6001, 2019-03-01 22:05:33

How to allocate goods with options and warehouses to orders?

I can’t solve the combinatorics problem, I don’t even know what this problem is called, but for sure there are ready-made libraries / functions / scripts for solving it.
There are goods and options that are in stock. A product or option can have a fixed quantity or be infinite (None is specified instead of the quantity). When ordering, you can combine one product with several options, respectively, you need to distribute the ordered products with options by warehouse into orders. If the goods in the order can be sent from several warehouses, then you need to select all of them, if not, then split them into several orders by warehouses. Does anyone have a solution or at least a name for this problem?
For clarity (Python syntax). IDs of options, products, warehouses are taken at random, you can insert your own.
Dictionary with all available goods, warehouses where it is available and quantities (None - infinite) in these warehouses {product_id: {warehouse_id: quantity}, ...}:

{1: {2: 7, 4: 3}, 13: {2: 7, 4: 3}, 21: {2: None, 4: None}}

Similar to option(None - infinite) {option_id: {warehouse_id: quantity}, ...}:
{3: {2: None, 4: None}, 10: {2: 10}, 9: {2: 10, 4: 10}, 8: {4: 2}}

Order, quantity in this case determines the quantity of this product and the quantity of each option in this configuration, i.e. with a quantity of 2pcs, you need to take 2pcs of the product and 2pcs of each option. The same product with different combinations of options is considered separate:
[{'product_id': 1, 'quantity': 2, 'options': [3, 10, 9]}, {'product_id': 1, 'quantity': 1, 'options': [3, 9]}, {'product_id': 13, 'quantity': 5, 'options': [10, 9]}]

As a result, I would like to get something like this. order_products - key from the order array.
If it is impossible to send from one warehouse:
[{'warehouses': [4], order_products: [0, 1]}, {'warehouses': [2], order_products: [2, 3]}]

If it is possible to send from several warehouses:
[{'warehouses': [2, 4], order_products: [0, 1, 2, 3]}]

If it is possible to ship from several warehouses and only from one warehouse:
[{'warehouses': [2, 4], order_products: [0, 1]}, {'warehouses': [6], order_products: [3]}]

Items in the order (order_products) that are not or are not in stock (taking into account the options) should be pushed into a separate array with the maximum quantity, for example:
limit_exceeded = [{'order_product': 1, 'max_quantity': 2}, ...]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Ostanin, 2019-03-14
@bazilio91

Make selections from IDs by features (availability in stock, USB version) in advance, then cross. Otherwise, faceted search on good volumes will be stupid.
https://youtu.be/Pqm88cqI-4A?t=276

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question