Changed ClubID enum class to include a string field used for printing, and define ClubID.OTHER as a default value for the class to handle invalid inputs.
This commit is contained in:
27
promotion.py
27
promotion.py
@@ -1,7 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
|
||||||
from typing import Dict, List, Union
|
from typing import Dict, List, Union
|
||||||
from bs4.element import Tag
|
from bs4.element import Tag
|
||||||
import csv
|
import csv
|
||||||
@@ -9,6 +8,7 @@ import sys
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
import xlsxwriter
|
import xlsxwriter
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
from aenum import Enum
|
||||||
|
|
||||||
from item import Item
|
from item import Item
|
||||||
from utils import (
|
from utils import (
|
||||||
@@ -45,10 +45,19 @@ PROMOTIONS_TABLE_HEADERS = [
|
|||||||
|
|
||||||
|
|
||||||
class ClubID(Enum):
|
class ClubID(Enum):
|
||||||
מבצע_רגיל = 0
|
_init_ = 'value string'
|
||||||
מועדון = 1
|
|
||||||
כרטיס_אשראי = 2
|
REGULAR = 0, 'מבצע רגיל'
|
||||||
אחר = 3
|
CLUB = 1, 'מועדון'
|
||||||
|
CREDIT_CARD = 2, 'כרטיס אשראי'
|
||||||
|
OTHER = 3, 'אחר'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _missing_(cls, value):
|
||||||
|
return ClubID.OTHER
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.string
|
||||||
|
|
||||||
|
|
||||||
class RewardType(Enum):
|
class RewardType(Enum):
|
||||||
@@ -153,7 +162,7 @@ def get_promotion_row_for_table(promo: Promotion, item: Item) -> List:
|
|||||||
item.price,
|
item.price,
|
||||||
promo.promo_func(item),
|
promo.promo_func(item),
|
||||||
(item.price - promo.promo_func(item)) / max(item.price, 1),
|
(item.price - promo.promo_func(item)) / max(item.price, 1),
|
||||||
promo.club_id.name.replace('_', ' '),
|
promo.club_id.string,
|
||||||
promo.max_qty,
|
promo.max_qty,
|
||||||
promo.allow_multiple_discounts,
|
promo.allow_multiple_discounts,
|
||||||
promo.start_date <= datetime.now(),
|
promo.start_date <= datetime.now(),
|
||||||
@@ -231,11 +240,7 @@ def create_new_promo_instance(chain: SupermarketChain, items_dict: Dict[str, Ite
|
|||||||
chain.date_hour_format)
|
chain.date_hour_format)
|
||||||
promo_update_time = datetime.strptime(promo.find(chain.promotion_update_tag_name).text,
|
promo_update_time = datetime.strptime(promo.find(chain.promotion_update_tag_name).text,
|
||||||
chain.update_date_format)
|
chain.update_date_format)
|
||||||
club_id = int(promo.find(re.compile('ClubId', re.IGNORECASE)).text)
|
club_id = ClubID(int(promo.find(re.compile('ClubId', re.IGNORECASE)).text))
|
||||||
if club_id in [club_id.value for club_id in ClubID]:
|
|
||||||
club_id = ClubID(club_id)
|
|
||||||
else:
|
|
||||||
club_id = ClubID(ClubID.אחר)
|
|
||||||
multiple_discounts_allowed = bool(int(promo.find('AllowMultipleDiscounts').text))
|
multiple_discounts_allowed = bool(int(promo.find('AllowMultipleDiscounts').text))
|
||||||
items = chain.get_items(promo, items_dict)
|
items = chain.get_items(promo, items_dict)
|
||||||
|
|
||||||
|
@@ -12,3 +12,4 @@ pytest~=6.2.2
|
|||||||
pandas~=1.2.0
|
pandas~=1.2.0
|
||||||
argparse~=1.4.0
|
argparse~=1.4.0
|
||||||
XlsxWriter~=1.4.3
|
XlsxWriter~=1.4.3
|
||||||
|
aenum
|
Reference in New Issue
Block a user