Переделал на функции. Добавил “Новый склад”.
>>> def f1(warehouse, item, req2):
... res_dic = {}
... i = item
... for x in i['stockByStore']:
... for product in req2:
... if x['name'] == warehouse and product['meta']['href'] == i['meta']['href']:
... res_dic['name'] = warehouse
... res_dic['product'] = product['name']
... res_dic['stock'] = x['stock']
... return res_dic
...
>>>
>>> def f(warehouse_list, req1, req2):
... res = []
... for i in req1:
... for warehouse in warehouse_list:
... res1 = f1(warehouse, i, req2)
... res.append(res1)
... return res
...
>>>
>>> warehouse_list = ['КБ Советская','Кулой','Основной склад', 'Новый склад']
>>>
>>> req1 = [
... {
... "meta": {
... "href": '2ab2a8e1-06fc-11eb-0a80-09950026157e',
... "type": "product",
... "mediaType": "application/json",
... },
... "stockByStore": [
... {
... "meta": {
... "href": "cdf4e4d9-7960-11ea-0a80-02cc00015063",
... "type": "store",
... "mediaType": "application/json"
... },
... "name": "КБ Советская",
... "stock": 12.075,
... "reserve": 0.0,
... "inTransit": 0.0
... },
... {
... "meta": {
... "href": "7acec394-7b04-11ea-0a80-01940002ba4f",
... "type": "store",
... "mediaType": "application/json"
... },
... "name": "Кулой",
... "stock": 8.609,
... "reserve": 0.0,
... "inTransit": 0.0
... },
... {
... "meta": {
... "href": "89e15a69-7950-11ea-0a80-043900008c70",
... "type": "store",
... "mediaType": "application/json"
... },
... "name": "Основной склад",
... "stock": 83.0,
... "reserve": 0.0,
... "inTransit": 0.0
... },
... {
... "meta": {
... "href": "89e15a69-7950-11ea-0a80-043900008c71",
... "type": "store",
... "mediaType": "application/json"
... },
... "name": "Новый склад",
... "stock": 84.0,
... "reserve": 0.0,
... "inTransit": 0.0
... }
... ]
... },
... {
... "meta": {
... "href": "8ec23fae-904e-11ea-0a80-05660005a116",
... "type": "product",
... "mediaType": "application/json"
... },
... "stockByStore": [
... {
... "meta": {
... "href": "cdf4e4d9-7960-11ea-0a80-02cc00015063",
... "type": "store",
... "mediaType": "application/json"
... },
... "name": "КБ Советская",
... "stock": 1.1,
... "reserve": 0.0,
... "inTransit": 0.0
... },
... {
... "meta": {
... "href": "7acec394-7b04-11ea-0a80-01940002ba4f",
... "type": "store",
... "mediaType": "application/json"
... },
... "name": "Кулой",
... "stock": 0.0,
... "reserve": 0.0,
... "inTransit": 0.0
... },
... {
... "meta": {
... "href": "89e15a69-7950-11ea-0a80-043900008c70",
... "type": "store",
... "mediaType": "application/json"
... },
... "name": "Основной склад",
... "stock": 23.0,
... "reserve": 0.0,
... "inTransit": 0.0
... },
... {
... "meta": {
... "href": "89e15a69-7950-11ea-0a80-043900008c71",
... "type": "store",
... "mediaType": "application/json"
... },
... "name": "Новый склад",
... "stock": 84.0,
... "reserve": 0.0,
... "inTransit": 0.0
... }
... ]
... }
... ]
>>>
>>> req2 = [
... {
... "meta": {
... "href": "2ab2a8e1-06fc-11eb-0a80-09950026157e",
... "type": "product",
... "mediaType": "application/json"
... },
... "stock": 103.684,
... "inTransit": 0.0,
... "reserve": 0.0,
... "quantity": 103.684,
... "name": "арахис в хрустящей корочке",
... "code": "00268",
... "price": 18000.0,
... "salePrice": 25000.0,
... "uom": {
... "meta": {
... "type": "uom",
... "mediaType": "application/json"
... },
... "name": "кг"
... },
... "externalCode": "WOywSqXtgrq3Wz0egCiQB2",
... "stockDays": 57.78
... },
... {
... "meta": {
... "href": "8ec23fae-904e-11ea-0a80-05660005a116",
... "type": "product",
... "mediaType": "application/json"
... },
... "stock": 24.1,
... "inTransit": 0.0,
... "reserve": 0.0,
... "quantity": 24.1,
... "name": "арахис соленый",
... "code": "00166",
... "article": "арахис",
... "price": 16141.078838174273,
... "salePrice": 21500.0,
... "uom": {
... "meta": {
... "href": "2ec1170c-3f69-4409-87bb-c68e0011b275",
... "type": "uom",
... "mediaType": "application/json"
... },
... "name": "кг"
... },
... "externalCode": "vLXA07ARjLeF3vvs2LmeF2",
... "stockDays": 150.79
... }
... ]
>>>
>>> out = f(warehouse_list, req1, req2)
>>> print(out)
[{'name': 'КБ Советская', 'product': 'арахис в хрустящей корочке', 'stock': 12.075}, {'name': 'Кулой', 'product': 'арахис в хрустящей корочке', 'stock': 8.609}, {'name': 'Основной склад', 'product': 'арахис в хрустящей корочке', 'stock': 83.0}, {'name': 'Новый склад', 'product': 'арахис в хрустящей корочке', 'stock': 84.0}, {'name': 'КБ Советская', 'product': 'арахис соленый', 'stock': 1.1}, {'name': 'Кулой', 'product': 'арахис соленый', 'stock': 0.0}, {'name': 'Основной склад', 'product': 'арахис соленый', 'stock': 23.0}, {'name': 'Новый склад', 'product': 'арахис соленый', 'stock': 84.0}]
>>>