217518e3 by 周伟奇

add statistics script

1 parent a9491aa6
......@@ -729,6 +729,7 @@ MVI_CLASSIFY = 29
MVI_FIELD_ORDER = (('发票代码', '发票代码'),
('发票号码', '发票号码'),
('开票日期', '开票日期'),
('不含税价(逻辑计算)', '不含税价(逻辑计算)'),
('不含税价', '不含税价'),
('发票类型', '发票联'),
('购方名称', '购买方名称'),
......
import re
import os
import ast
import json
import datetime
from openpyxl import Workbook
from django.core.management import BaseCommand
from settings import conf
from common.mixins import LoggerMixin
from apps.doc import consts
class Command(BaseCommand, LoggerMixin):
def __init__(self):
super().__init__()
self.log_base = '[bs statistics]'
def add_arguments(self, parser):
parser.add_argument(
'--date',
default=datetime.date.today() - datetime.timedelta(days=1),
dest='date',
help='将要计算的日期,格式: 2018-01-01'
)
def handle(self, *args, **kwargs):
date = kwargs.get('date')
if isinstance(date, str):
if not re.match(r'\d{4}-\d{2}-\d{2}', date):
print('date format error')
return
date_str = date
else:
date_str = date.strftime('%Y-%m-%d')
excel_path = os.path.join(conf.LOG_DIR, 'bs_{0}.xlsx'.format(date_str))
log_path = os.path.join(conf.LOG_DIR, 'bs.log.{0}'.format(date_str))
if not os.path.exists(log_path):
print('log_path not exists')
return
wb = Workbook()
ws = wb.get_sheet_by_name('Sheet')
ws.title = date_str
ws.append(('版式', '数目'))
with open(log_path, 'r', encoding='utf-8') as fp:
for line in fp:
search_obj = re.search(r'(\d{1,2}):(\d+)', line)
classify = search_obj.group(1)
count = search_obj.group(2)
label = consts.CLASSIFY_LIST[int(classify)][0]
ws.append((label, int(count)))
wb.save(excel_path)
import json
import re
import os
import ast
import datetime
from openpyxl import Workbook
from django.core.management import BaseCommand
from settings import conf
from common.mixins import LoggerMixin
from apps.doc.models import HILDoc, AFCDoc
from apps.doc import consts
......@@ -50,8 +52,30 @@ class Command(BaseCommand, LoggerMixin):
'备注')],
}
def add_arguments(self, parser):
parser.add_argument(
'--date',
default=datetime.date.today() - datetime.timedelta(days=1),
dest='date',
help='将要计算的日期,格式: 2018-01-01'
)
def handle(self, *args, **kwargs):
excel_path = '/bmw-ocr/data/license_res.xlsx'
date = kwargs.get('date')
if isinstance(date, str):
if not re.match(r'\d{4}-\d{2}-\d{2}', date):
print('date format error')
return
date_str = date
else:
date_str = date.strftime('%Y-%m-%d')
excel_path = os.path.join(conf.LOG_DIR, 'license_{0}.xlsx'.format(date_str))
log_path = os.path.join(conf.LOG_DIR, 'license.log.{0}'.format(date_str))
if not os.path.exists(log_path):
print('log_path not exists')
return
wb = Workbook()
for classify, (_, name, _, _, _, _) in consts.LICENSE_ORDER:
ws = wb.create_sheet(name)
......@@ -60,7 +84,7 @@ class Command(BaseCommand, LoggerMixin):
ws.append(header)
wb.remove(wb.get_sheet_by_name('Sheet'))
with open('/bmw-ocr/logs/license_bak.log', 'r', encoding='utf-8') as fp:
with open(log_path, 'r', encoding='utf-8') as fp:
for line in fp:
search_obj = re.search(r'task=(.*) license_summary=(.*)', line)
task_str = search_obj.group(1)
......
......@@ -608,6 +608,19 @@ class BSWorkbook(Workbook):
if side_diff:
key, field_order_yes, field_order_no = consts.FIELD_ORDER_MAP.get(classify)
field_order = field_order_yes if key in license_dict else field_order_no
if classify == consts.MVI_CLASSIFY:
price = ''
rate_str = license_dict.get('增值税税率')
price_total_str = license_dict.get('价税合计小写')
if rate_str is not None and price_total_str is not None:
try:
rate = int(rate_str)
price_total = float(price_total_str)
except Exception as e:
pass
else:
price = price_total*100/(rate+100)
license_dict['不含税价(逻辑计算)'] = price
for search_field, write_field in field_order:
field_value = license_dict.get(search_field, '')
if isinstance(field_value, list):
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!