Repository URL to install this package:
|
Version:
0.4.184 ▾
|
lib-py-b2b
/
service_center.py
|
|---|
from abc import abstractmethod
from datetime import datetime
from dateutil.tz import gettz
from lib_b2b.address import Address
from lib_b2b.holidays import Holidays
from lib_b2b.persistent import Persistable
from pprint import pformat
import calendar
import logging
logger = logging.getLogger(__name__)
class ServiceCenter(Persistable):
def __init__(self, center_id: str, name: str, address: Address, time_zone: str, workdays: [int], holidays: Holidays):
self.holidays = holidays
self.workdays = workdays
self.time_zone = time_zone
self.tz = gettz(time_zone)
self.address = address
self.name = name
self.center_id = center_id
@abstractmethod
def operating_calendar(self, customer):
raise NotImplementedError()
def describe(self):
_str = ""
_str += f"id: {self.center_id}\n"
_str += f"name: {self.name}\n"
_str += f"address: {self.address.address1}, {self.address.address2 + ', ' if self.address.address2 else ''}{self.address.city}, {self.address.state}, {self.address.postalCode} {self.address.phone}\n"
_str += f"timezone: {self.time_zone} with offset of {datetime.now(tz=self.tz).strftime('%z')}\n"
_str += f"workdays: {', '.join(list(map(lambda d: list(calendar.day_abbr)[d] , self.workdays)))}\n"
_str += f"holidays: {self.holidays.describe()}\n"
return _str
def __eq__(self, other):
if isinstance(other, ServiceCenter):
o: ServiceCenter = other
return self.center_id == o.center_id
else:
return super().__eq__(other)
@staticmethod
def from_dict(data: dict):
return ServiceCenter(
center_id=data.get('id'),
name=data.get('name'),
address=Address.from_dict(data.get('address')),
time_zone=data.get('time_zone'),
workdays=data.get('workdays'),
holidays=Holidays.get(data.get('holidays'))
)
def as_dict(self) -> dict:
return {
'id': self.center_id,
'name': self.name,
'address': self.address.as_dict(),
'time_zone': self.time_zone,
'workdays': self.workdays,
'holidays': self.holidays.name
}