File packages/stock_upload.py changed (mode: 100644) (index 037a228..c261e71) |
... |
... |
def priceUpload(flatfile, export, folder): |
41 |
41 |
# The column header names |
# The column header names |
42 |
42 |
column_names = ['VariationID', 'IsNet', 'VariationPrice', 'SalesPriceID'] |
column_names = ['VariationID', 'IsNet', 'VariationPrice', 'SalesPriceID'] |
43 |
43 |
|
|
44 |
|
price_id = ['1', '4'] |
|
|
44 |
|
prices = { |
|
45 |
|
'price':{'id':'1', 'value':''}, |
|
46 |
|
'ebay':{'id':'3', 'value':''}, |
|
47 |
|
'amazon':{'id':'4', 'value':''}, |
|
48 |
|
'webshop':{'id':'5', 'value':''} |
|
49 |
|
} |
|
50 |
|
|
45 |
51 |
# create a Data Dictionary and fill it with the necessary values from the |
# create a Data Dictionary and fill it with the necessary values from the |
46 |
52 |
# flatfile |
# flatfile |
47 |
53 |
Data = SortedDict() |
Data = SortedDict() |
|
... |
... |
def priceUpload(flatfile, export, folder): |
49 |
55 |
with open(flatfile, mode='r') as item: |
with open(flatfile, mode='r') as item: |
50 |
56 |
reader = DictReader(item, delimiter=";") |
reader = DictReader(item, delimiter=";") |
51 |
57 |
for row in reader: |
for row in reader: |
52 |
|
if(row['external_product_id']): |
|
53 |
|
for ident in price_id: |
|
54 |
|
values = ['', 0, row['standard_price'], ident] |
|
55 |
|
Data[row['item_sku']] = SortedDict(zip(column_names, values)) |
|
|
58 |
|
# Make sure that there is price even at parents |
|
59 |
|
if(not( row['standard_price'] )): |
|
60 |
|
print("row:{0} doesnt have a price!".format(row['item_sku'])) |
|
61 |
|
for scndrow in reader: |
|
62 |
|
if(row['parent_child'] == 'parent'): |
|
63 |
|
if(scndrow['parent_child'] == 'child' and scndrow['standard_price'] and row['item_sku'] == scndrow['parent_sku']): |
|
64 |
|
row['standard_price'] = scndrow['standard_price'] |
|
65 |
|
break |
|
66 |
|
elif(row['parent_child'] == 'child'): |
|
67 |
|
if(scndrow['parent_child'] == 'child' and scndrow['standard_price'] and row['parent_sku'] == scndrow['parent_sku']): |
|
68 |
|
row['standard_price'] = scndrow['standard_price'] |
|
69 |
|
break |
|
70 |
|
if(row['standard_price']): |
|
71 |
|
for price in prices: |
|
72 |
|
if(prices[ price ]['id'] == '3'): |
|
73 |
|
# Ebay price calculation |
|
74 |
|
prices[ price ]['value'] = ( int( round( float( row['standard_price'] ) - (float( row['standard_price'] ) * 0.10) ) ) - 0.05 ) |
|
75 |
|
if(prices[ price ]['id'] == '5'): |
|
76 |
|
# Webshop price calculation |
|
77 |
|
prices[ price ]['value'] = ( int( round( float( row['standard_price'] ) - (float( row['standard_price'] ) * 0.16666666) ) ) - 0.05 ) |
|
78 |
|
else: |
|
79 |
|
prices[ price ]['value'] = row['standard_price'] |
|
80 |
|
values = ['', 0, prices[ price ]['value'], prices[ price ]['id']] |
|
81 |
|
|
|
82 |
|
print("row:{0}, id:{1}, value:{2}".format(row['item_sku'], prices[price]['id'], prices[price]['value'])) |
|
83 |
|
Data[row['item_sku'] + '_' + price] = SortedDict(zip(column_names, values)) |
|
84 |
|
else: |
|
85 |
|
print("{0} doesn't have a price!\n".format(row['item_sku'])) |
56 |
86 |
|
|
57 |
87 |
with open(export, mode='r') as item: |
with open(export, mode='r') as item: |
58 |
88 |
reader = DictReader(item, delimiter=";") |
reader = DictReader(item, delimiter=";") |
59 |
89 |
for row in reader: |
for row in reader: |
60 |
|
if(row['VariationNumber'] in [*Data]): |
|
61 |
|
Data[row['VariationNumber']]['VariationID'] = row['VariationID'] |
|
|
90 |
|
for price in prices: |
|
91 |
|
if((row['VariationNumber'] + '_' + price) in [*Data]): |
|
92 |
|
Data[row['VariationNumber'] + '_' + price]['VariationID'] = row['VariationID'] |
|
93 |
|
|
|
94 |
|
# Open the flatfile again to check for items that didn't have variationID |
|
95 |
|
with open(flatfile, mode='r') as item: |
|
96 |
|
reader = DictReader(item,delimiter=';') |
|
97 |
|
for row in reader: |
|
98 |
|
for price in prices: |
|
99 |
|
sku_price = row['item_sku'] + '_' + price |
|
100 |
|
if(( sku_price ) in [*Data]): |
|
101 |
|
if(not( Data[sku_price]['VariationID'] )): |
|
102 |
|
print("sku: {0} has no VariationID!".format(row['item_sku'])) |
|
103 |
|
eraseKey(Data, sku_price) |
62 |
104 |
|
|
63 |
105 |
output_path = variation_upload.writeCSV(Data, 'SalesPriceVariation', column_names, folder) |
output_path = variation_upload.writeCSV(Data, 'SalesPriceVariation', column_names, folder) |
|
106 |
|
|
|
107 |
|
def eraseKey(dictionary, key): |
|
108 |
|
if isinstance(dictionary, dict): |
|
109 |
|
if key in dictionary: |
|
110 |
|
dictionary.pop(key) |
|
111 |
|
else: |
|
112 |
|
print("Deletion failed {0} was not in the dictionary".format(key)) |
|
113 |
|
else: |
|
114 |
|
print("Deletion failed for {0}".format(key)) |