Subject | Hash | Author | Date (UTC) |
---|---|---|---|
Unit test for find_price function | c19fa28ad9bf0dd1b5361e871dc498f6704cb196 | Sebastian Fricke | 2020-04-27 12:53:20 |
Remove price calculation from script | d852cb3ef648336ed94daeaaa220721e6055dd7c | Sebastian Fricke | 2020-04-27 12:50:52 |
Function description priceUpload | 2c5735f4f4c79607f55c77b1359aa5984d1e6699 | Sebastian Fricke | 2020-04-23 09:34:30 |
similar attribute search regardless of the parent | 4bb0970408d78d25264d479428fe8c3389483215 | Sebastian Fricke | 2020-04-23 09:28:19 |
Fix marking dropdown bug | 0d1695083d2b4e49fd364a36a7ef3c92a192d62f | Sebastian Fricke | 2020-04-23 09:26:46 |
update desktop specific build script for windows | 8a6536d6173f7383022fab92f234ab25fc81204b | Sebastian Fricke | 2020-04-22 10:15:05 |
Refactor config handling | a9be950a4e8d97fa97c7e9caff33fcbb1f476d9d | Sebastian Fricke | 2020-04-22 10:11:57 |
Fix gui/category_chooser: file change bug | 9879e65c9aad9b1feb05b6121a0e33c129a8beb5 | Sebastian Fricke | 2020-04-22 10:09:36 |
update .gitignore | 6c7628af605a72ced1e146c27da8639225ab9c6c | Sebastian Fricke | 2020-04-22 10:08:47 |
Fix error.py: Fix colorful messages on windows | 31f0b106c7aee1962bba3efb5758f647170eceff | Sebastian Fricke | 2020-04-22 10:07:30 |
Enhanced error output to extra module | dda37a22d21db1af6330fd62395682b91f46f5ec | Sebastian Fricke | 2020-01-27 10:56:00 |
Introduction infoPrint, removed unnecessary parameter | 98b6779f95fcf6d3350f64e7d2a8151932415458 | Sebastian Fricke | 2020-01-16 14:27:15 |
Add Cdiscount price & coding style review | 7c5451b067760100904aed947b2ba484ab9c9e45 | Sebastian Fricke | 2020-01-16 14:25:15 |
coding style, naming conventions & uninitialized | 218378ca191510dc2092108a87e63ff83b4c6b31 | Sebastian Fricke | 2020-01-16 13:58:24 |
coding style & cleanup image upload module | 04ac13fb764baecd1a419cbffcd9696a3ff5b680 | Sebastian Fricke | 2020-01-16 13:56:07 |
coding style improvements and colorful error msg | 401db811c0edd62b14c7a0a29e2c1f6d2791774c | Sebastian Fricke | 2020-01-16 13:54:25 |
code cleanup and coding style category.py | b1e41b45fe405d3826a9b6e452fb9e2f9f6697bf | Sebastian Fricke | 2020-01-16 10:43:44 |
Added the category config to the gitignore file | b8b522d9ade4b59b5d0a0bd4f9b7c79e8db334c6 | Sebastian Fricke | 2020-01-15 14:56:06 |
Removed log function for category_config(not needed) | c8ca8a3b6b968f1835697073e7d5fe1ea70b15ba | Sebastian Fricke | 2020-01-15 14:54:15 |
Added category_config functionality | 7bd8256398b4af5c1feb3033d74cd9f29b047edc | Sebastian Fricke | 2020-01-15 14:53:20 |
File | Lines added | Lines deleted |
---|---|---|
packages/price_upload.py | 0 | 103 |
tests/files/test_price_sample.csv | 5 | 0 |
tests/files/test_price_sample_bad.csv | 5 | 0 |
tests/test_price.py | 30 | 0 |
File packages/price_upload.py deleted (index 654338e..0000000) | |||
1 | import inspect | ||
2 | from collections import OrderedDict | ||
3 | from csv import DictReader | ||
4 | from packages import error | ||
5 | |||
6 | |||
7 | def priceUpload(flatfile): | ||
8 | """ | ||
9 | Parameter: | ||
10 | flatfile [Dictionary] => path and encoding as strings | ||
11 | of the flatfile | ||
12 | |||
13 | Description: | ||
14 | Take the standard_price field from the flatfile and apply | ||
15 | price calculation rules to set the price values for different | ||
16 | markets. | ||
17 | |||
18 | Return: | ||
19 | data => Ordered dictionary with of the variation with | ||
20 | 'column_names' as fields | ||
21 | """ | ||
22 | |||
23 | column_names = ['price', 'ebay', 'amazon', 'webshop', 'etsy'] | ||
24 | |||
25 | prices = { | ||
26 | 'price':{'id':'1', 'value':''}, | ||
27 | 'ebay':{'id':'3', 'value':''}, | ||
28 | 'amazon':{'id':'4', 'value':''}, | ||
29 | 'webshop':{'id':'5', 'value':''}, | ||
30 | 'etsy':{'id':'6', 'value':''}, | ||
31 | 'cdiscount':{'id':'7', 'value':''} | ||
32 | } | ||
33 | |||
34 | data = OrderedDict() | ||
35 | standard_price = 0 | ||
36 | variation_price = 0 | ||
37 | round_price = 0 | ||
38 | percent_diff = 0 | ||
39 | adjust = 0 | ||
40 | |||
41 | with open(flatfile['path'], mode='r', encoding=flatfile['encoding']) as item: | ||
42 | reader = DictReader(item, delimiter=";") | ||
43 | for row in reader: | ||
44 | # Take a price from a variation in case the parent does not own one | ||
45 | if not row['standard_price']: | ||
46 | error.warnPrint( | ||
47 | msg=f"row:{row['item_sku']} doesnt have a price!", | ||
48 | linenumber=inspect.currentframe().f_back.f_lineno, | ||
49 | err='') | ||
50 | for scndrow in reader: | ||
51 | if row['parent_child'] == 'parent': | ||
52 | if scndrow['parent_child'] == 'child' and\ | ||
53 | scndrow['standard_price'] and\ | ||
54 | row['item_sku'] == scndrow['parent_sku']: | ||
55 | error.infoPrint( | ||
56 | "parent without price add:{0} from:{1} to:{2}" | ||
57 | .format(scndrow['standard_price'], | ||
58 | scndrow['item_sku'], | ||
59 | row['item_sku'])) | ||
60 | standard_price = scndrow['standard_price'] | ||
61 | break | ||
62 | elif row['parent_child'] == 'child': | ||
63 | if scndrow['parent_child'] == 'child' and\ | ||
64 | scndrow['standard_price'] and\ | ||
65 | row['parent_sku'] == scndrow['parent_sku']: | ||
66 | standard_price = scndrow['standard_price'] | ||
67 | break | ||
68 | |||
69 | with open(flatfile['path'], mode='r', encoding=flatfile['encoding']) as item: | ||
70 | reader = DictReader(item, delimiter=";") | ||
71 | |||
72 | for row in reader: | ||
73 | if row['standard_price']: | ||
74 | variation_price = float(row['standard_price']) | ||
75 | else: | ||
76 | variation_price = float(standard_price) | ||
77 | for price in prices: | ||
78 | if prices[price]['id'] == '3': | ||
79 | percent_diff = 0.10 | ||
80 | adjust = 0.05 | ||
81 | if prices[price]['id'] == '5': | ||
82 | percent_diff = 0.166666666 | ||
83 | adjust = 0.05 | ||
84 | if prices[price]['id'] == '6': | ||
85 | percent_diff = 0.1 | ||
86 | adjust = 0.15 | ||
87 | if prices[price]['id'] == '7': | ||
88 | percent_diff = 0.2 | ||
89 | adjust = 0.05 | ||
90 | else: | ||
91 | percent_diff = 0 | ||
92 | adjust = 0 | ||
93 | |||
94 | round_price = round(float(variation_price)+\ | ||
95 | (float(variation_price*percent_diff))) | ||
96 | prices[price]['value'] = int(round_price)-adjust | ||
97 | |||
98 | values = [prices['price']['value'], prices['ebay']['value'], | ||
99 | prices['amazon']['value'], prices['webshop']['value'], | ||
100 | prices['etsy']['value']] | ||
101 | data[row['item_sku']] = OrderedDict(zip(column_names, values)) | ||
102 | |||
103 | return data |
File tests/files/test_price_sample.csv added (mode: 100644) (index 0000000..a9dd7ee) | |||
1 | feed_product_type;item_sku;brand_name;external_product_id;external_product_id_type;item_name;recommended_browse_nodes;outer_material_type;color_map;color_name;size_name;style_name;band_size_num;band_size_num_unit_of_measure;special_features1;special_features2;special_features3;special_features4;special_features5;frame_material_type;lens_material_type;lens_width;lens_width_unit_of_measure;lifestyle;polarization_type;department_name;size_map;item_shape;is_adult_product;standard_price;quantity;main_image_url;material_composition;item_length_description;other_image_url1;other_image_url2;other_image_url3;other_image_url4;other_image_url5;other_image_url6;other_image_url7;other_image_url8;parent_child;parent_sku;relationship_type;variation_theme;update_delete;product_description;inner_material_type;care_instructions;model_name;model;closure_type;part_number;gtin_exemption_reason;manufacturer;generic_keywords;fit_type;top_style;bullet_point1;bullet_point2;bullet_point3;bullet_point4;bullet_point5;platinum_keywords1;platinum_keywords2;platinum_keywords3;platinum_keywords4;platinum_keywords5;seasons;specific_uses_keywords1;specific_uses_keywords2;specific_uses_keywords3;specific_uses_keywords4;specific_uses_keywords5;target_audience_keywords1;target_audience_keywords2;target_audience_keywords3;target_audience_keywords4;target_audience_keywords5;style_keywords;catalog_number;collection_name;sleeve_type;neck_style;neck_size;neck_size_unit_of_measure;fabric_wash;waist_style;inseam_length;inseam_length_unit_of_measure;waist_size;waist_size_unit_of_measure;cup_size;special_features;material_type;lens_color;website_shipping_weight;website_shipping_weight_unit_of_measure;item_width;item_height;item_dimensions_unit_of_measure;item_length;item_width_unit_of_measure;unit_count;item_height_unit_of_measure;item_length_unit_of_measure;fulfillment_center_id;package_length;package_width;package_height;package_weight;package_weight_unit_of_measure;package_dimensions_unit_of_measure;legal_disclaimer_description;safety_warning;eu_toys_safety_directive_age_warning;eu_toys_safety_directive_warning;eu_toys_safety_directive_language;country_of_origin;batteries_required;are_batteries_included;battery_cell_composition;battery_type1;battery_type2;battery_type3;number_of_batteries1;number_of_batteries2;number_of_batteries3;battery_weight;battery_weight_unit_of_measure;number_of_lithium_metal_cells;number_of_lithium_ion_cells;lithium_battery_packaging;lithium_battery_energy_content;lithium_battery_energy_content_unit_of_measure;lithium_battery_weight;lithium_battery_weight_unit_of_measure;supplier_declared_dg_hz_regulation1;supplier_declared_dg_hz_regulation2;supplier_declared_dg_hz_regulation3;supplier_declared_dg_hz_regulation4;supplier_declared_dg_hz_regulation5;hazmat_united_nations_regulatory_id;safety_data_sheet_url;item_weight;item_weight_unit_of_measure;item_volume;item_volume_unit_of_measure;flash_point;fabric_type;fedas_id;ghs_classification_class1;ghs_classification_class2;ghs_classification_class3;condition_type;condition_note;currency;fulfillment_latency;sale_price;sale_from_date;sale_end_date;max_aggregate_ship_quantity;item_package_quantity;number_of_items;offering_can_be_gift_messaged;offering_can_be_giftwrapped;is_discontinued_by_manufacturer;product_site_launch_date;restock_date;delivery_schedule_group_id;product_tax_code;offering_end_date;max_order_quantity;merchant_shipping_group_name;offering_start_date;business_price;quantity_price_type;quantity_lower_bound1;quantity_price1;quantity_lower_bound2;quantity_price2;quantity_lower_bound3;quantity_price3;quantity_lower_bound4;quantity_price4;quantity_lower_bound5;quantity_price5;national_stock_number;unspsc_code;pricing_action;pattern_type;collar_style;opacity;bottom_style;special_size_type;magnification_strength;lens_color_map | ||
2 | swimwear;A_parent;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
3 | swimwear;A_001;;;;;;;;;;;;;;;;;;;;;;;;;;;;16.8;;;;;;;;;;;;;;A_parent;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;16.8;percent;10;5;20;10;;;;;;;;;;;;;;;; | ||
4 | swimwear;A_002;;;;;;;;;;;;;;;;;;;;;;;;;;;;16.8;;;;;;;;;;;;;;A_parent;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;16.8;percent;10;5;20;10;;;;;;;;;;;;;;;; | ||
5 | swimwear;A_003;;;;;;;;;;;;;;;;;;;;;;;;;;;;16.8;;;;;;;;;;;;;;A_parent;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;16.8;percent;10;5;20;10;;;;;;;;;;;;;;;; |
File tests/files/test_price_sample_bad.csv added (mode: 100644) (index 0000000..ade2bd6) | |||
1 | feed_product_type;item_sku;brand_name;external_product_id;external_product_id_type;item_name;recommended_browse_nodes;outer_material_type;color_map;color_name;size_name;style_name;band_size_num;band_size_num_unit_of_measure;special_features1;special_features2;special_features3;special_features4;special_features5;frame_material_type;lens_material_type;lens_width;lens_width_unit_of_measure;lifestyle;polarization_type;department_name;size_map;item_shape;is_adult_product;standard_price;quantity;main_image_url;material_composition;item_length_description;other_image_url1;other_image_url2;other_image_url3;other_image_url4;other_image_url5;other_image_url6;other_image_url7;other_image_url8;parent_child;parent_sku;relationship_type;variation_theme;update_delete;product_description;inner_material_type;care_instructions;model_name;model;closure_type;part_number;gtin_exemption_reason;manufacturer;generic_keywords;fit_type;top_style;bullet_point1;bullet_point2;bullet_point3;bullet_point4;bullet_point5;platinum_keywords1;platinum_keywords2;platinum_keywords3;platinum_keywords4;platinum_keywords5;seasons;specific_uses_keywords1;specific_uses_keywords2;specific_uses_keywords3;specific_uses_keywords4;specific_uses_keywords5;target_audience_keywords1;target_audience_keywords2;target_audience_keywords3;target_audience_keywords4;target_audience_keywords5;style_keywords;catalog_number;collection_name;sleeve_type;neck_style;neck_size;neck_size_unit_of_measure;fabric_wash;waist_style;inseam_length;inseam_length_unit_of_measure;waist_size;waist_size_unit_of_measure;cup_size;special_features;material_type;lens_color;website_shipping_weight;website_shipping_weight_unit_of_measure;item_width;item_height;item_dimensions_unit_of_measure;item_length;item_width_unit_of_measure;unit_count;item_height_unit_of_measure;item_length_unit_of_measure;fulfillment_center_id;package_length;package_width;package_height;package_weight;package_weight_unit_of_measure;package_dimensions_unit_of_measure;legal_disclaimer_description;safety_warning;eu_toys_safety_directive_age_warning;eu_toys_safety_directive_warning;eu_toys_safety_directive_language;country_of_origin;batteries_required;are_batteries_included;battery_cell_composition;battery_type1;battery_type2;battery_type3;number_of_batteries1;number_of_batteries2;number_of_batteries3;battery_weight;battery_weight_unit_of_measure;number_of_lithium_metal_cells;number_of_lithium_ion_cells;lithium_battery_packaging;lithium_battery_energy_content;lithium_battery_energy_content_unit_of_measure;lithium_battery_weight;lithium_battery_weight_unit_of_measure;supplier_declared_dg_hz_regulation1;supplier_declared_dg_hz_regulation2;supplier_declared_dg_hz_regulation3;supplier_declared_dg_hz_regulation4;supplier_declared_dg_hz_regulation5;hazmat_united_nations_regulatory_id;safety_data_sheet_url;item_weight;item_weight_unit_of_measure;item_volume;item_volume_unit_of_measure;flash_point;fabric_type;fedas_id;ghs_classification_class1;ghs_classification_class2;ghs_classification_class3;condition_type;condition_note;currency;fulfillment_latency;sale_price;sale_from_date;sale_end_date;max_aggregate_ship_quantity;item_package_quantity;number_of_items;offering_can_be_gift_messaged;offering_can_be_giftwrapped;is_discontinued_by_manufacturer;product_site_launch_date;restock_date;delivery_schedule_group_id;product_tax_code;offering_end_date;max_order_quantity;merchant_shipping_group_name;offering_start_date;business_price;quantity_price_type;quantity_lower_bound1;quantity_price1;quantity_lower_bound2;quantity_price2;quantity_lower_bound3;quantity_price3;quantity_lower_bound4;quantity_price4;quantity_lower_bound5;quantity_price5;national_stock_number;unspsc_code;pricing_action;pattern_type;collar_style;opacity;bottom_style;special_size_type;magnification_strength;lens_color_map | ||
2 | swimwear;A_parent;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
3 | swimwear;A_001;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A_parent;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;16.8;percent;10;5;20;10;;;;;;;;;;;;;;;; | ||
4 | swimwear;A_002;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A_parent;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;16.8;percent;10;5;20;10;;;;;;;;;;;;;;;; | ||
5 | swimwear;A_003;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A_parent;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;16.8;percent;10;5;20;10;;;;;;;;;;;;;;;; |
File tests/test_price.py added (mode: 100644) (index 0000000..2f7d38b) | |||
1 | import pytest | ||
2 | |||
3 | from packages import price | ||
4 | |||
5 | @pytest.fixture | ||
6 | def price_file(): | ||
7 | pfile = {'path':'./tests/files/test_price_sample.csv', 'encoding':'utf-8'} | ||
8 | return pfile | ||
9 | |||
10 | @pytest.fixture | ||
11 | def bad_file(): | ||
12 | pfile = {'path':'./tests/files/test_price_sample_bad.csv', | ||
13 | 'encoding':'utf-8'} | ||
14 | return pfile | ||
15 | |||
16 | def test_find_price_good(price_file): | ||
17 | parent = 'A_parent' | ||
18 | result = 0 | ||
19 | |||
20 | result = price.find_price(price_file, parent) | ||
21 | |||
22 | assert 16.8 == result | ||
23 | |||
24 | def test_find_price_bad(bad_file): | ||
25 | parent = 'A_parent' | ||
26 | result = 0 | ||
27 | |||
28 | result = price.find_price(bad_file, parent) | ||
29 | |||
30 | assert 0 == result |