def save_drug_list(self, page_start, page_end, categorys, market_status, excel=None, csv=None, append=False, set_detail=False): ''' present_code = {'Y':'급여', 'N': '비급여'} categorys = {'E': '전문', 'O': '일반', 'Q': '의약외품'} market_status = {'AS': '유통/생산 중', 'AE': '유통/생산 미확인', 'AD': '유통/생산 중단'} ''' if append: recs = read_excel(excel) if excel else read_csv(csv, encoding='cp949') else: recs = RecordParser() for ctg in categorys: for mks in market_status: for npage in range(page_start, page_end): try: record = RecordParser( self.get_all(category=ctg, market_status=mks, page=npage, set_detail=set_detail)) except Exception as e: print("Except on", ctg, mks, npage, e) break if not record: break recs += record print('{}-{}-{}'.format(ctg, mks, npage)) recs.distinct(['drug_id']) if excel: recs.to_excel(excel) elif csv: recs.to_csv(csv)
def report_excel_response(invset_slugs): records = [] invests = Invest.objects.filter(slug__in=invset_slugs) for invest in invests: for item in invest.investitem_set.all(): records.append({ 'EDI코드': item.drug.edi, '판매사': item.drug.firm, '약품명': item.drug.name_as, '실사량': item.total, '규격단위': item.drug.standard_unit, '재고단가': item.price, '재고구분': item.drug.invest_class, '유효기한': item.expire }) recs = RecordParser(records) recs = recs.select(['EDI코드', '판매사', '약품명', '실사량', '규격단위', '재고단가', '재고구분', '유효기한']) output = recs.to_excel() filename = '{}.xlsx'.format(' '.join(invset_slugs)) response = HttpResponse(output, content_type='application/vnd.ms-excel') response['Content-Disposition'] = 'attachment; filename='+ filename return response