Skip to content

Instantly share code, notes, and snippets.

@atom-tr
Created August 9, 2022 09:58
Show Gist options
  • Save atom-tr/db6e3effc7605a110573cc16b1a1b937 to your computer and use it in GitHub Desktop.
Save atom-tr/db6e3effc7605a110573cc16b1a1b937 to your computer and use it in GitHub Desktop.
Opera_Record object
class Opera_Record(object):
"""Application record formats and data
flows to be used for data communications between a Oracle Hospitality Property
Management System (PMS) and a Hotel Property vendor system. It gives a general
description of record formats and data flow requirements, and covers specifics for
Record Types, Field Types, and Field usage
+ AN - Alphanumeric characters. Correspond to the character set of ASCII Code Page with
codes 32-127. No Control Character.
+ ANS - Complete character set of used Code Page (all printable character), No Control
Character.
+ N - Numeric characters, includes '0' - '9', the minus sign ('-') as leading character, and
where necessary 'A' - 'F' and 'a' - 'f' as hex characters. These fields always reflect integer
values (no decimal positions). No Alpha character, No Control character
+ M - Monetary characters, includes all numeric characters and period (‘.’) as decimal
indicators where necessary when coming FROM the PMS record TO the PMS must be
without decimal indicator. The PMS can handle monetary fields without an implied
decimal point depending on the regional/local setting and currency.
+ D - Date, numeric characters, formatted as YYMMDD
+ T - Time, numeric characters, formatted as HHMMS
Args:
object (_type_): _description_
Raises:
Exception: _description_
"""
type = None
datas = []
def __init__(self, message):
datas = str(message).split('|')
if len(datas) > 1:
self.datas = datas[1:]
if len(datas[0]) == 2:
self.type = datas[0]
else:
raise Exception('Invalid message')
def is_valid(self):
match self.type:
case 'GI':
"""Guest Check In"""
if all([self.RN, self.GID]):
return True
case 'GO':
"""Guest Check Out"""
if self.RN:
return True
case 'GC':
"""Guest data change / Name Change / RoomMove"""
if all([self.RN, self.GID, self.GS]): # RN, GID, GS
return True
return False
@property
def RN(self):
"""RN: Room Number - ANS, max. 8 (can be longer with Suite8 or OPERA-PMS)"""
a = list(filter(lambda e: 'RN' in e, self.datas))
return a[0].removeprefix('RN') if a else None
@property
def GN(self)->str:
"""GN: Guest Name - ANS, max. 200"""
a = list(filter(lambda e: 'GN' in e, self.datas))
return a[0].removeprefix('GN') if a else None
@property
def GID(self)->int:
"""G#: Reservation Number - N, max. 10"""
a = list(filter(lambda e: 'G#' in e, self.datas))
return int(a[0].removeprefix('G#')) if a else None
@property
def GV(self)->str:
"""GV: Guest VIP Status - AN, max. 20 (normally numeric values)"""
a = list(filter(lambda e: 'GV' in e, self.datas))
return a[0].removeprefix('GV') if a else None
@property
def GS(self)-> bool:
"""GS: Share Flag - AN, 1 char (Y/N)"""
a = list(filter(lambda e: 'GS' in e, self.datas))
if a:
flag = a[0].removeprefix('GS')
return True if flag == 'Y' else False
return None
@property
def RO(self):
"""RO: Old Room Number (source room) - ANS, max. 8 (can be longer with Suite8 or OPERA-PMS)"""
a = list(filter(lambda e: 'RO' in e, self.datas))
return a[0].removeprefix('RO') if a else None
ms = "GI|RN1003|GSY|G#12329|"
c = Opera_Record(ms)
if not c.is_valid():
raise Exception('Invalid message')
# if message is valid, then do something
match c.type:
case 'GI': pass #do something
case 'GO': pass #do something
case 'GC': pass #do something
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment