add statistics script
Showing
4 changed files
with
97 additions
and
3 deletions
... | @@ -729,6 +729,7 @@ MVI_CLASSIFY = 29 | ... | @@ -729,6 +729,7 @@ MVI_CLASSIFY = 29 |
729 | MVI_FIELD_ORDER = (('发票代码', '发票代码'), | 729 | MVI_FIELD_ORDER = (('发票代码', '发票代码'), |
730 | ('发票号码', '发票号码'), | 730 | ('发票号码', '发票号码'), |
731 | ('开票日期', '开票日期'), | 731 | ('开票日期', '开票日期'), |
732 | ('不含税价(逻辑计算)', '不含税价(逻辑计算)'), | ||
732 | ('不含税价', '不含税价'), | 733 | ('不含税价', '不含税价'), |
733 | ('发票类型', '发票联'), | 734 | ('发票类型', '发票联'), |
734 | ('购方名称', '购买方名称'), | 735 | ('购方名称', '购买方名称'), | ... | ... |
1 | import re | ||
2 | import os | ||
3 | import ast | ||
4 | import json | ||
5 | import datetime | ||
6 | from openpyxl import Workbook | ||
7 | from django.core.management import BaseCommand | ||
8 | from settings import conf | ||
9 | from common.mixins import LoggerMixin | ||
10 | from apps.doc import consts | ||
11 | |||
12 | |||
13 | class Command(BaseCommand, LoggerMixin): | ||
14 | |||
15 | def __init__(self): | ||
16 | super().__init__() | ||
17 | self.log_base = '[bs statistics]' | ||
18 | |||
19 | def add_arguments(self, parser): | ||
20 | parser.add_argument( | ||
21 | '--date', | ||
22 | default=datetime.date.today() - datetime.timedelta(days=1), | ||
23 | dest='date', | ||
24 | help='将要计算的日期,格式: 2018-01-01' | ||
25 | ) | ||
26 | |||
27 | def handle(self, *args, **kwargs): | ||
28 | date = kwargs.get('date') | ||
29 | if isinstance(date, str): | ||
30 | if not re.match(r'\d{4}-\d{2}-\d{2}', date): | ||
31 | print('date format error') | ||
32 | return | ||
33 | date_str = date | ||
34 | else: | ||
35 | date_str = date.strftime('%Y-%m-%d') | ||
36 | |||
37 | excel_path = os.path.join(conf.LOG_DIR, 'bs_{0}.xlsx'.format(date_str)) | ||
38 | log_path = os.path.join(conf.LOG_DIR, 'bs.log.{0}'.format(date_str)) | ||
39 | if not os.path.exists(log_path): | ||
40 | print('log_path not exists') | ||
41 | return | ||
42 | |||
43 | wb = Workbook() | ||
44 | ws = wb.get_sheet_by_name('Sheet') | ||
45 | ws.title = date_str | ||
46 | ws.append(('版式', '数目')) | ||
47 | |||
48 | with open(log_path, 'r', encoding='utf-8') as fp: | ||
49 | for line in fp: | ||
50 | search_obj = re.search(r'(\d{1,2}):(\d+)', line) | ||
51 | classify = search_obj.group(1) | ||
52 | count = search_obj.group(2) | ||
53 | label = consts.CLASSIFY_LIST[int(classify)][0] | ||
54 | ws.append((label, int(count))) | ||
55 | |||
56 | wb.save(excel_path) |
1 | import json | ||
2 | import re | 1 | import re |
2 | import os | ||
3 | import ast | 3 | import ast |
4 | import datetime | ||
4 | from openpyxl import Workbook | 5 | from openpyxl import Workbook |
5 | from django.core.management import BaseCommand | 6 | from django.core.management import BaseCommand |
7 | from settings import conf | ||
6 | from common.mixins import LoggerMixin | 8 | from common.mixins import LoggerMixin |
7 | from apps.doc.models import HILDoc, AFCDoc | 9 | from apps.doc.models import HILDoc, AFCDoc |
8 | from apps.doc import consts | 10 | from apps.doc import consts |
... | @@ -50,8 +52,30 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -50,8 +52,30 @@ class Command(BaseCommand, LoggerMixin): |
50 | '备注')], | 52 | '备注')], |
51 | } | 53 | } |
52 | 54 | ||
55 | def add_arguments(self, parser): | ||
56 | parser.add_argument( | ||
57 | '--date', | ||
58 | default=datetime.date.today() - datetime.timedelta(days=1), | ||
59 | dest='date', | ||
60 | help='将要计算的日期,格式: 2018-01-01' | ||
61 | ) | ||
62 | |||
53 | def handle(self, *args, **kwargs): | 63 | def handle(self, *args, **kwargs): |
54 | excel_path = '/bmw-ocr/data/license_res.xlsx' | 64 | date = kwargs.get('date') |
65 | if isinstance(date, str): | ||
66 | if not re.match(r'\d{4}-\d{2}-\d{2}', date): | ||
67 | print('date format error') | ||
68 | return | ||
69 | date_str = date | ||
70 | else: | ||
71 | date_str = date.strftime('%Y-%m-%d') | ||
72 | |||
73 | excel_path = os.path.join(conf.LOG_DIR, 'license_{0}.xlsx'.format(date_str)) | ||
74 | log_path = os.path.join(conf.LOG_DIR, 'license.log.{0}'.format(date_str)) | ||
75 | if not os.path.exists(log_path): | ||
76 | print('log_path not exists') | ||
77 | return | ||
78 | |||
55 | wb = Workbook() | 79 | wb = Workbook() |
56 | for classify, (_, name, _, _, _, _) in consts.LICENSE_ORDER: | 80 | for classify, (_, name, _, _, _, _) in consts.LICENSE_ORDER: |
57 | ws = wb.create_sheet(name) | 81 | ws = wb.create_sheet(name) |
... | @@ -60,7 +84,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -60,7 +84,7 @@ class Command(BaseCommand, LoggerMixin): |
60 | ws.append(header) | 84 | ws.append(header) |
61 | wb.remove(wb.get_sheet_by_name('Sheet')) | 85 | wb.remove(wb.get_sheet_by_name('Sheet')) |
62 | 86 | ||
63 | with open('/bmw-ocr/logs/license_bak.log', 'r', encoding='utf-8') as fp: | 87 | with open(log_path, 'r', encoding='utf-8') as fp: |
64 | for line in fp: | 88 | for line in fp: |
65 | search_obj = re.search(r'task=(.*) license_summary=(.*)', line) | 89 | search_obj = re.search(r'task=(.*) license_summary=(.*)', line) |
66 | task_str = search_obj.group(1) | 90 | task_str = search_obj.group(1) | ... | ... |
... | @@ -608,6 +608,19 @@ class BSWorkbook(Workbook): | ... | @@ -608,6 +608,19 @@ class BSWorkbook(Workbook): |
608 | if side_diff: | 608 | if side_diff: |
609 | key, field_order_yes, field_order_no = consts.FIELD_ORDER_MAP.get(classify) | 609 | key, field_order_yes, field_order_no = consts.FIELD_ORDER_MAP.get(classify) |
610 | field_order = field_order_yes if key in license_dict else field_order_no | 610 | field_order = field_order_yes if key in license_dict else field_order_no |
611 | if classify == consts.MVI_CLASSIFY: | ||
612 | price = '' | ||
613 | rate_str = license_dict.get('增值税税率') | ||
614 | price_total_str = license_dict.get('价税合计小写') | ||
615 | if rate_str is not None and price_total_str is not None: | ||
616 | try: | ||
617 | rate = int(rate_str) | ||
618 | price_total = float(price_total_str) | ||
619 | except Exception as e: | ||
620 | pass | ||
621 | else: | ||
622 | price = price_total*100/(rate+100) | ||
623 | license_dict['不含税价(逻辑计算)'] = price | ||
611 | for search_field, write_field in field_order: | 624 | for search_field, write_field in field_order: |
612 | field_value = license_dict.get(search_field, '') | 625 | field_value = license_dict.get(search_field, '') |
613 | if isinstance(field_value, list): | 626 | if isinstance(field_value, list): | ... | ... |
-
Please register or sign in to post a comment