File packages/price_upload.py changed (mode: 100644) (index 481553f..e581288) |
|
1 |
|
import inspect |
|
2 |
|
from collections import OrderedDict |
1 |
3 |
from csv import DictReader |
from csv import DictReader |
2 |
|
try: |
|
3 |
|
from sortedcontainers import SortedDict |
|
4 |
|
except ImportError: |
|
5 |
|
print("the sortedcontainers module is required to run this program.") |
|
6 |
|
raise ImportError |
|
|
4 |
|
from packages.item_upload import warnPrint, infoPrint |
7 |
5 |
|
|
8 |
6 |
|
|
9 |
7 |
def priceUpload(flatfile): |
def priceUpload(flatfile): |
|
... |
... |
def priceUpload(flatfile): |
15 |
13 |
'ebay':{'id':'3', 'value':''}, |
'ebay':{'id':'3', 'value':''}, |
16 |
14 |
'amazon':{'id':'4', 'value':''}, |
'amazon':{'id':'4', 'value':''}, |
17 |
15 |
'webshop':{'id':'5', 'value':''}, |
'webshop':{'id':'5', 'value':''}, |
18 |
|
'etsy':{'id':'6', 'value':''} |
|
|
16 |
|
'etsy':{'id':'6', 'value':''}, |
|
17 |
|
'cdiscount':{'id':'7', 'value':''} |
19 |
18 |
} |
} |
20 |
19 |
|
|
21 |
|
# create a Data Dictionary and fill it with the necessary values from the |
|
|
20 |
|
# create a data Dictionary and fill it with the necessary values from the |
22 |
21 |
# flatfile |
# flatfile |
23 |
|
Data = SortedDict() |
|
|
22 |
|
data = OrderedDict() |
24 |
23 |
standard_price = 0 |
standard_price = 0 |
25 |
24 |
variation_price = 0 |
variation_price = 0 |
|
25 |
|
round_price = 0 |
|
26 |
|
percent_diff = 0 |
|
27 |
|
adjust = 0 |
26 |
28 |
|
|
27 |
29 |
with open(flatfile['path'], mode='r', encoding=flatfile['encoding']) as item: |
with open(flatfile['path'], mode='r', encoding=flatfile['encoding']) as item: |
28 |
30 |
reader = DictReader(item, delimiter=";") |
reader = DictReader(item, delimiter=";") |
29 |
31 |
for row in reader: |
for row in reader: |
30 |
32 |
# Make sure that there is price even at parents |
# Make sure that there is price even at parents |
31 |
|
if(not( row['standard_price'] )): |
|
32 |
|
print("row:{0} doesnt have a price!".format(row['item_sku'])) |
|
|
33 |
|
if not row['standard_price']: |
|
34 |
|
warnPrint(f"row:{row['item_sku']} doesnt have a price!", |
|
35 |
|
linenumber=inspect.currentframe().f_back.f_lineno, |
|
36 |
|
err='') |
33 |
37 |
for scndrow in reader: |
for scndrow in reader: |
34 |
|
if(row['parent_child'] == 'parent'): |
|
35 |
|
if(scndrow['parent_child'] == 'child' and scndrow['standard_price'] and row['item_sku'] == scndrow['parent_sku']): |
|
36 |
|
print("parent without price add:{0} from:{1} to:{2}" |
|
37 |
|
.format(scndrow['standard_price'], |
|
38 |
|
scndrow['item_sku'], |
|
39 |
|
row['item_sku'])) |
|
|
38 |
|
if row['parent_child'] == 'parent': |
|
39 |
|
if scndrow['parent_child'] == 'child' and\ |
|
40 |
|
scndrow['standard_price'] and\ |
|
41 |
|
row['item_sku'] == scndrow['parent_sku']: |
|
42 |
|
infoPrint( |
|
43 |
|
"parent without price add:{0} from:{1} to:{2}" |
|
44 |
|
.format(scndrow['standard_price'], |
|
45 |
|
scndrow['item_sku'], |
|
46 |
|
row['item_sku'])) |
40 |
47 |
standard_price = scndrow['standard_price'] |
standard_price = scndrow['standard_price'] |
41 |
48 |
break |
break |
42 |
|
elif(row['parent_child'] == 'child'): |
|
43 |
|
if(scndrow['parent_child'] == 'child' and scndrow['standard_price'] and row['parent_sku'] == scndrow['parent_sku']): |
|
|
49 |
|
elif row['parent_child'] == 'child': |
|
50 |
|
if scndrow['parent_child'] == 'child' and\ |
|
51 |
|
scndrow['standard_price'] and\ |
|
52 |
|
row['parent_sku'] == scndrow['parent_sku']: |
44 |
53 |
standard_price = scndrow['standard_price'] |
standard_price = scndrow['standard_price'] |
45 |
54 |
break |
break |
46 |
55 |
|
|
|
... |
... |
def priceUpload(flatfile): |
48 |
57 |
reader = DictReader(item, delimiter=";") |
reader = DictReader(item, delimiter=";") |
49 |
58 |
|
|
50 |
59 |
for row in reader: |
for row in reader: |
51 |
|
if(row['standard_price']): |
|
|
60 |
|
if row['standard_price']: |
52 |
61 |
variation_price = row['standard_price'] |
variation_price = row['standard_price'] |
53 |
62 |
else: |
else: |
54 |
63 |
variation_price = standard_price |
variation_price = standard_price |
55 |
64 |
for price in prices: |
for price in prices: |
56 |
|
if(prices[ price ]['id'] == '3'): |
|
57 |
|
# Ebay price calculation |
|
58 |
|
prices[ price ]['value'] = ( int( round( float( variation_price ) - (float( variation_price ) * 0.10) ) ) - 0.05 ) |
|
59 |
|
if(prices[ price ]['id'] == '5'): |
|
60 |
|
# Webshop price calculation |
|
61 |
|
prices[ price ]['value'] = ( int( round( float( variation_price ) - (float( variation_price ) * 0.16666666) ) ) - 0.05 ) |
|
62 |
|
if(prices[ price ]['id'] == '6'): |
|
63 |
|
# Etsy price calculation |
|
64 |
|
prices[ price ]['value'] = ( int( round( float( variation_price ) + (float( variation_price ) * 0.1) ) ) - 0.15 ) |
|
|
65 |
|
if prices[price]['id'] == '3': |
|
66 |
|
percent_diff = 0.10 |
|
67 |
|
adjust = 0.05 |
|
68 |
|
if prices[price]['id'] == '5': |
|
69 |
|
percent_diff = 0.166666666 |
|
70 |
|
adjust = 0.05 |
|
71 |
|
if prices[price]['id'] == '6': |
|
72 |
|
percent_diff = 0.1 |
|
73 |
|
adjust = 0.15 |
|
74 |
|
if prices[price]['id'] == '7': |
|
75 |
|
percent_diff = 0.2 |
|
76 |
|
adjust = 0.05 |
65 |
77 |
else: |
else: |
66 |
|
prices[ price ]['value'] = variation_price |
|
67 |
|
values = [prices['price']['value'], prices['ebay']['value'], |
|
68 |
|
prices['amazon']['value'], prices['webshop']['value'], |
|
69 |
|
prices['etsy']['value']] |
|
70 |
|
Data[row['item_sku']] = SortedDict(zip(column_names, values)) |
|
|
78 |
|
percent_diff = 0 |
|
79 |
|
adjust = 0 |
|
80 |
|
|
|
81 |
|
round_price = round(float(variation_price)+\ |
|
82 |
|
(float(variation_price*percent_diff))) |
|
83 |
|
prices[price]['value'] = int(round_price)-adjust |
71 |
84 |
|
|
72 |
|
return Data |
|
|
85 |
|
values = [prices['price']['value'], prices['ebay']['value'], |
|
86 |
|
prices['amazon']['value'], prices['webshop']['value'], |
|
87 |
|
prices['etsy']['value']] |
|
88 |
|
data[row['item_sku']] = OrderedDict(zip(column_names, values)) |
73 |
89 |
|
|
|
90 |
|
return data |