fix amount
Showing
2 changed files
with
35 additions
and
13 deletions
... | @@ -37,7 +37,26 @@ DEALER_CODE = 'ocr_situ_group' | ... | @@ -37,7 +37,26 @@ DEALER_CODE = 'ocr_situ_group' |
37 | 37 | ||
38 | # ---------银行流水模板相关-------------------------------------------------------------------------------------------- | 38 | # ---------银行流水模板相关-------------------------------------------------------------------------------------------- |
39 | 39 | ||
40 | TRANS = str.maketrans('Cc((oODlLAsSbgE', '000000011455699') | 40 | TRANS_MAP = { |
41 | 'C': "0", | ||
42 | 'c': "0", | ||
43 | '(': "0", | ||
44 | '(': "0", | ||
45 | 'o': "0", | ||
46 | 'O': "0", | ||
47 | 'D': "0", | ||
48 | '[': "1", | ||
49 | 'l': "1", | ||
50 | 'L': "1", | ||
51 | 'A': "4", | ||
52 | 's': "5", | ||
53 | 'S': "5", | ||
54 | 'b': "6", | ||
55 | 'g': "9", | ||
56 | 'E': "9", | ||
57 | 'B': "13", | ||
58 | } | ||
59 | TRANS = str.maketrans(TRANS_MAP) | ||
41 | 60 | ||
42 | CARD_RATIO = 0.9 | 61 | CARD_RATIO = 0.9 |
43 | UNKNOWN_CARD = '未知卡号' | 62 | UNKNOWN_CARD = '未知卡号' | ... | ... |
... | @@ -203,6 +203,17 @@ class BSWorkbook(Workbook): | ... | @@ -203,6 +203,17 @@ class BSWorkbook(Workbook): |
203 | ms.append(row) | 203 | ms.append(row) |
204 | return ms | 204 | return ms |
205 | 205 | ||
206 | @staticmethod | ||
207 | def amount_format(amount_str): | ||
208 | if not isinstance(amount_str, str) or amount_str == '': | ||
209 | return amount_str | ||
210 | # 替换 | ||
211 | res_str = amount_str.translate(consts.TRANS) | ||
212 | # 删除多余的- | ||
213 | res_str = res_str[0] + res_str[1:].replace('-', '') | ||
214 | # TODO 逗号与句号处理 | ||
215 | return res_str | ||
216 | |||
206 | def build_month_sheet(self, card, month_mapping, ms, is_reverse): | 217 | def build_month_sheet(self, card, month_mapping, ms, is_reverse): |
207 | tmp_ws = self.create_sheet('tmp_ws') | 218 | tmp_ws = self.create_sheet('tmp_ws') |
208 | for month in sorted(month_mapping.keys()): | 219 | for month in sorted(month_mapping.keys()): |
... | @@ -235,9 +246,7 @@ class BSWorkbook(Workbook): | ... | @@ -235,9 +246,7 @@ class BSWorkbook(Workbook): |
235 | # 3.3.余额转数值 | 246 | # 3.3.余额转数值 |
236 | over_cell = rows[consts.OVER_IDX] | 247 | over_cell = rows[consts.OVER_IDX] |
237 | try: | 248 | try: |
238 | if isinstance(over_cell.value, str): | 249 | over_cell.value = locale.atof(self.amount_format(over_cell.value)) |
239 | over_cell.value = over_cell.value.translate(consts.TRANS) | ||
240 | over_cell.value = locale.atof(over_cell.value) | ||
241 | except Exception as e: | 250 | except Exception as e: |
242 | continue | 251 | continue |
243 | else: | 252 | else: |
... | @@ -246,22 +255,16 @@ class BSWorkbook(Workbook): | ... | @@ -246,22 +255,16 @@ class BSWorkbook(Workbook): |
246 | # 3.4.金额转数值 | 255 | # 3.4.金额转数值 |
247 | try: | 256 | try: |
248 | try: | 257 | try: |
249 | if isinstance(amount_cell.value, str): # TODO 可在转化数字失败后,再替换 | 258 | amount_cell.value = locale.atof(self.amount_format(amount_cell.value)) |
250 | amount_cell.value = amount_cell.value.translate(consts.TRANS) | ||
251 | amount_cell.value = locale.atof(amount_cell.value) | ||
252 | except Exception as e: | 259 | except Exception as e: |
253 | try: | 260 | try: |
254 | if isinstance(rows[consts.INCOME_IDX].value, str): | 261 | amount_cell.value = locale.atof(self.amount_format(rows[consts.INCOME_IDX].value)) |
255 | rows[consts.OUTLAY_IDX].value = rows[consts.INCOME_IDX].value.translate(consts.TRANS) | ||
256 | amount_cell.value = locale.atof(rows[consts.OUTLAY_IDX].value) | ||
257 | if amount_cell.value == 0: | 262 | if amount_cell.value == 0: |
258 | raise | 263 | raise |
259 | elif amount_cell.value < 0: | 264 | elif amount_cell.value < 0: |
260 | amount_cell.value = -amount_cell.value | 265 | amount_cell.value = -amount_cell.value |
261 | except Exception as e: | 266 | except Exception as e: |
262 | if isinstance(rows[consts.OUTLAY_IDX].value, str): | 267 | amount_cell.value = locale.atof(self.amount_format(rows[consts.OUTLAY_IDX].value)) |
263 | rows[consts.OUTLAY_IDX].value = rows[consts.OUTLAY_IDX].value.translate(consts.TRANS) | ||
264 | amount_cell.value = locale.atof(rows[consts.OUTLAY_IDX].value) | ||
265 | if amount_cell.value > 0: | 268 | if amount_cell.value > 0: |
266 | amount_cell.value = -amount_cell.value | 269 | amount_cell.value = -amount_cell.value |
267 | except Exception as e: | 270 | except Exception as e: | ... | ... |
-
Please register or sign in to post a comment