e6c82ee3 by 周伟奇

fix amount

1 parent 26691edc
......@@ -37,7 +37,26 @@ DEALER_CODE = 'ocr_situ_group'
# ---------银行流水模板相关--------------------------------------------------------------------------------------------
TRANS = str.maketrans('Cc((oODlLAsSbgE', '000000011455699')
TRANS_MAP = {
'C': "0",
'c': "0",
'(': "0",
'(': "0",
'o': "0",
'O': "0",
'D': "0",
'[': "1",
'l': "1",
'L': "1",
'A': "4",
's': "5",
'S': "5",
'b': "6",
'g': "9",
'E': "9",
'B': "13",
}
TRANS = str.maketrans(TRANS_MAP)
CARD_RATIO = 0.9
UNKNOWN_CARD = '未知卡号'
......
......@@ -203,6 +203,17 @@ class BSWorkbook(Workbook):
ms.append(row)
return ms
@staticmethod
def amount_format(amount_str):
if not isinstance(amount_str, str) or amount_str == '':
return amount_str
# 替换
res_str = amount_str.translate(consts.TRANS)
# 删除多余的-
res_str = res_str[0] + res_str[1:].replace('-', '')
# TODO 逗号与句号处理
return res_str
def build_month_sheet(self, card, month_mapping, ms, is_reverse):
tmp_ws = self.create_sheet('tmp_ws')
for month in sorted(month_mapping.keys()):
......@@ -235,9 +246,7 @@ class BSWorkbook(Workbook):
# 3.3.余额转数值
over_cell = rows[consts.OVER_IDX]
try:
if isinstance(over_cell.value, str):
over_cell.value = over_cell.value.translate(consts.TRANS)
over_cell.value = locale.atof(over_cell.value)
over_cell.value = locale.atof(self.amount_format(over_cell.value))
except Exception as e:
continue
else:
......@@ -246,22 +255,16 @@ class BSWorkbook(Workbook):
# 3.4.金额转数值
try:
try:
if isinstance(amount_cell.value, str): # TODO 可在转化数字失败后,再替换
amount_cell.value = amount_cell.value.translate(consts.TRANS)
amount_cell.value = locale.atof(amount_cell.value)
amount_cell.value = locale.atof(self.amount_format(amount_cell.value))
except Exception as e:
try:
if isinstance(rows[consts.INCOME_IDX].value, str):
rows[consts.OUTLAY_IDX].value = rows[consts.INCOME_IDX].value.translate(consts.TRANS)
amount_cell.value = locale.atof(rows[consts.OUTLAY_IDX].value)
amount_cell.value = locale.atof(self.amount_format(rows[consts.INCOME_IDX].value))
if amount_cell.value == 0:
raise
elif amount_cell.value < 0:
amount_cell.value = -amount_cell.value
except Exception as e:
if isinstance(rows[consts.OUTLAY_IDX].value, str):
rows[consts.OUTLAY_IDX].value = rows[consts.OUTLAY_IDX].value.translate(consts.TRANS)
amount_cell.value = locale.atof(rows[consts.OUTLAY_IDX].value)
amount_cell.value = locale.atof(self.amount_format(rows[consts.OUTLAY_IDX].value))
if amount_cell.value > 0:
amount_cell.value = -amount_cell.value
except Exception as e:
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!