Skip to content

Commit

Permalink
Merge PR #1034 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
OCA-git-bot committed Aug 3, 2023
2 parents c76975a + acefd9c commit 553a50b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Do NOT update manually; changes here will be overwritten by Copier
_commit: v1.14.2
_commit: v1.15.0
_src_path: gh:oca/oca-addons-repo-template
ci: GitHub
dependency_installation_mode: PIP
Expand All @@ -11,6 +11,7 @@ github_enable_makepot: true
github_enable_stale_action: true
github_enforce_dev_status_compatibility: true
include_wkhtmltopdf: true
odoo_test_flavor: OCB
odoo_version: 12.0
org_name: Odoo Community Association (OCA)
org_slug: OCA
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
pre-commit:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
with:
python-version: "3.6"
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
name: Detect unreleased dependencies
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: |
for reqfile in requirements.txt test-requirements.txt ; do
if [ -f ${reqfile} ] ; then
Expand All @@ -35,11 +35,9 @@ jobs:
fail-fast: false
matrix:
include:
- container: ghcr.io/oca/oca-ci/py3.6-odoo12.0:latest
makepot: "true"
name: test with Odoo
- container: ghcr.io/oca/oca-ci/py3.6-ocb12.0:latest
name: test with OCB
makepot: "true"
services:
postgres:
image: postgres:9.6
Expand All @@ -50,7 +48,7 @@ jobs:
ports:
- 5432:5432
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
persist-credentials: false
- name: Install addons and dependencies
Expand Down
43 changes: 22 additions & 21 deletions hw_telium_payment_terminal/test-scripts/telium-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import curses.ascii
import time
import pycountry

import logging
logger = logging.getLogger(__name__)

DEVICE = '/dev/ttyACM0'
DEVICE_RATE = 9600
Expand All @@ -27,7 +28,7 @@ def initialize_msg(serial):
if get_one_byte_answer(serial, 'ACK'):
return True
else:
print("Terminal : SAME PLAYER TRY AGAIN")
logger.info("Terminal : SAME PLAYER TRY AGAIN")
send_one_byte_signal(serial, 'EOT')
# Wait 1 sec between each attempt
time.sleep(1)
Expand All @@ -39,15 +40,15 @@ def send_one_byte_signal(serial, signal):
assert signal in ascii_names, 'Wrong signal'
char = ascii_names.index(signal)
serial_write(serial, chr(char))
print('Signal %s sent to terminal' % signal)
logger.info('Signal %s sent to terminal' % signal)


def get_one_byte_answer(serial, expected_signal):
ascii_names = curses.ascii.controlnames
one_byte_read = serial.read(1).decode('ascii')
expected_char = ascii_names.index(expected_signal)
if one_byte_read == chr(expected_char):
print("%s received from terminal" % expected_signal)
logger.info("%s received from terminal" % expected_signal)
return True
else:
return False
Expand All @@ -59,14 +60,14 @@ def prepare_data_to_send():
elif PAYMENT_MODE == 'card':
payment_mode = '1'
else:
print("The payment mode '%s' is not supported" % PAYMENT_MODE)
logger.info("The payment mode '%s' is not supported" % PAYMENT_MODE)
return False
cur_iso_letter = CURRENCY_ISO.upper()
try:
cur = pycountry.currencies.get(alpha_3=cur_iso_letter)
cur_numeric = str(cur.numeric)
except:
print("Currency %s is not recognized" % cur_iso_letter)
logger.info("Currency %s is not recognized" % cur_iso_letter)
return False
data = {
'pos_number': str(1).zfill(2),
Expand Down Expand Up @@ -102,21 +103,21 @@ def send_message(serial, data):
data['private'] +
data['delay'] +
data['auto'])
print('Real message to send = %s' % real_msg)
logger.info('Real message to send = %s' % real_msg)
assert len(real_msg) == 34, 'Wrong length for protocol E+'
real_msg_with_etx = real_msg + chr(ascii_names.index('ETX'))
lrc = generate_lrc(real_msg_with_etx)
message = chr(ascii_names.index('STX')) + real_msg_with_etx + chr(lrc)
serial_write(serial, message)
print('Message sent to terminal')
logger.info('Message sent to terminal')


def compare_data_vs_answer(data, answer_data):
for field in [
'pos_number', 'amount_msg',
'currency_numeric', 'private']:
if data[field] != answer_data[field]:
print(
logger.info(
"Field %s has value '%s' in data and value '%s' in answer"
% (field, data[field], answer_data[field]))

Expand All @@ -130,7 +131,7 @@ def parse_terminal_answer(real_msg, data):
'currency_numeric': real_msg[12:15],
'private': real_msg[15:26],
}
print('answer_data = %s' % answer_data)
logger.info('answer_data = %s' % answer_data)
compare_data_vs_answer(data, answer_data)
return answer_data

Expand All @@ -139,19 +140,19 @@ def get_answer_from_terminal(serial, data):
ascii_names = curses.ascii.controlnames
full_msg_size = 1+2+1+8+1+3+10+1+1
msg = serial.read(size=full_msg_size).decode('ascii')
print('%d bytes read from terminal' % full_msg_size)
logger.info('%d bytes read from terminal' % full_msg_size)
assert len(msg) == full_msg_size, 'Answer has a wrong size'
if msg[0] != chr(ascii_names.index('STX')):
print('The first byte of the answer from terminal should be STX')
logger.info('The first byte of the answer from terminal should be STX')
if msg[-2] != chr(ascii_names.index('ETX')):
print('The byte before final of the answer '
logger.info('The byte before final of the answer '
'from terminal should be ETX')
lrc = msg[-1]
computed_lrc = chr(generate_lrc(msg[1:-1]))
if computed_lrc != lrc:
print('The LRC of the answer from terminal is wrong')
logger.info('The LRC of the answer from terminal is wrong')
real_msg = msg[1:-2]
print('Real answer received = %s' % real_msg)
logger.info('Real answer received = %s' % real_msg)
return parse_terminal_answer(real_msg, data)


Expand All @@ -160,15 +161,15 @@ def transaction_start():
'''
serial = False
try:
print(
logger.info(
'Opening serial port %s for payment terminal with '
'baudrate %d' % (DEVICE, DEVICE_RATE))
# IMPORTANT : don't modify timeout=3 seconds
# This parameter is very important ; the Telium spec say
# that we have to wait to up 3 seconds to get LRC
serial = Serial(
DEVICE, DEVICE_RATE, timeout=3)
print('serial.is_open = %s' % serial.isOpen())
logger.info('serial.is_open = %s' % serial.isOpen())
if initialize_msg(serial):
data = prepare_data_to_send()
if not data:
Expand All @@ -177,19 +178,19 @@ def transaction_start():
if get_one_byte_answer(serial, 'ACK'):
send_one_byte_signal(serial, 'EOT')

print("Now expecting answer from Terminal")
logger.info("Now expecting answer from Terminal")
if get_one_byte_answer(serial, 'ENQ'):
send_one_byte_signal(serial, 'ACK')
get_answer_from_terminal(serial, data)
send_one_byte_signal(serial, 'ACK')
if get_one_byte_answer(serial, 'EOT'):
print("Answer received from Terminal")
logger.info("Answer received from Terminal")

except Exception as e:
print('Exception in serial connection: %s' % str(e))
logger.info('Exception in serial connection: %s' % str(e))
finally:
if serial:
print('Closing serial port for payment terminal')
logger.info('Closing serial port for payment terminal')
serial.close()


Expand Down

0 comments on commit 553a50b

Please sign in to comment.