Esempio n. 1
0
    def save_staging_records(self, request):
        from ..models import gen_uniq_staging_inbound_record_id

        staging_records = json.loads(request.POST['staging_records'])
        forecast_inbound_id = request.POST['forecast_inbound_id']
        forecast_inbound = ForecastInbound.objects.get(id=forecast_inbound_id)
        supplier_id = forecast_inbound.supplier_id

        for staging_record in staging_records:
            record_id = staging_record['record_id']
            if record_id:
                record = StagingInBound.objects.get(id=record_id)
                record.record_num = staging_record['record_num']
                record.save()
            else:
                product_id = staging_record['product_id']
                sku_id = staging_record['sku_id']
                product = Product.objects.get(id=product_id)
                creator = get_admin_name(request.user)

                staging_inbound = StagingInBound(
                    forecast_inbound=forecast_inbound,
                    supplier_id=supplier_id,
                    ware_house=product.ware_by,
                    product_id=product_id,
                    sku_id=sku_id,
                    record_num=staging_record['record_num'],
                    uniq_key=gen_uniq_staging_inbound_record_id(
                        supplier_id, product.ware_by, creator, sku_id),
                    creator=creator)
                staging_inbound.save()
        return Response('OK')
Esempio n. 2
0
    def create(self, request):
        content = request.POST
        records = json.loads(content['records'])
        forecast_inbound_id = int(content['forecast_inbound_id'])

        forecast_inbound = ForecastInbound.objects.get(id=forecast_inbound_id)
        supplier_id = forecast_inbound.supplier_id
        real_inbound = RealInbound(forecast_inbound=forecast_inbound,
                                   ware_house=forecast_inbound.ware_house,
                                   supplier=forecast_inbound.supplier,
                                   creator=get_admin_name(request.user))
        real_inbound.save()

        for record in records:
            record_id = record['record_id']
            record_num = record['record_num']
            sku_id = record['sku_id']
            product_id = record['product_id']

            if record_id:
                StagingInBound.objects.filter(id=record_id).update(
                    record_num=record_num, status=StagingInBound.COMPLETED)
            if record_num <= 0:
                continue
            sku = ProductSku.objects.get(id=sku_id)
            barcode = sku.barcode
            product_name = sku.product.name
            product_img = sku.product.PIC_PATH
            real_inbound_detail = RealInboundDetail(
                inbound=real_inbound,
                product_id=product_id,
                sku_id=sku_id,
                barcode=barcode,
                product_name=product_name,
                product_img=product_img,
                arrival_quantity=record_num)
            real_inbound_detail.save()

        creator = get_admin_name(request.user)
        StagingInBound.objects.filter(
            forecast_inbound=forecast_inbound,
            creator=creator).update(status=StagingInBound.COMPLETED)
        return Response({'real_inbound_id': real_inbound.id})
Esempio n. 3
0
 def get_main_queryset(self, request):
     return self.queryset.filter(creator=get_admin_name(request.user))
Esempio n. 4
0
    def get(self, request):
        from common.utils import get_admin_name

        start_date = datetime.datetime.strptime(request.GET['start_date'],
                                                '%Y%m%d').date()
        end_date = datetime.datetime.strptime(request.GET['end_date'],
                                              '%Y%m%d').date()

        data = []
        for orderlist in OrderList.objects.filter(
                created__gte=start_date, created__lte=end_date).exclude(
                    status=OrderList.ZUOFEI).order_by('id'):
            username = get_admin_name(orderlist.buyer)
            interval = (orderlist.updated - datetime.datetime.combine(
                orderlist.created, datetime.time.min)).days
            created_str = orderlist.created.strftime('%Y-%m-%d')
            updated_str = orderlist.updated.strftime('%Y-%m-%d %H:%M:%S')
            amount = orderlist.order_amount

            supplier_name = ''
            if orderlist.supplier_id and orderlist.supplier:
                supplier_name = orderlist.supplier.supplier_name

            num = 0
            product_ids = set()
            for orderdetail in orderlist.order_list.all():
                product_ids.add(orderdetail.product_id)
                num += orderdetail.buy_quantity
            status, buyer_status = self.get_status(orderlist.status)

            data.append((orderlist.id, username, status, buyer_status,
                         created_str, updated_str, interval, supplier_name,
                         len(product_ids), num, amount))

        buff = StringIO()
        workbook = xlsxwriter.Workbook(buff)
        worksheet = workbook.add_worksheet()
        worksheet.write('A1', '订货单ID')
        worksheet.write('B1', '负责人')
        worksheet.write('C1', '状态')
        worksheet.write('D1', '是否完成')
        worksheet.write('E1', '创建日期')
        worksheet.write('F1', '更新时间')
        worksheet.write('G1', '间隔天数')
        worksheet.write('H1', '供应商名')
        worksheet.write('I1', '款数')
        worksheet.write('J1', '件数')
        worksheet.write('K1', '总金额')

        i = 1
        for row in data:
            for j, cell in enumerate(row):
                worksheet.write(i, j, cell)
            i += 1
        workbook.close()

        filename = '%s-%s.xlsx' % (start_date.strftime('%y年%m月%d'),
                                   end_date.strftime('%y年%m月%d'))
        response = HttpResponse(
            buff.getvalue(),
            content_type=
            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        )
        response['Content-Disposition'] = 'attachment;filename="%s"' % filename
        return response
Esempio n. 5
0
 def get_username(cls, user):
     from common.utils import get_admin_name
     return get_admin_name(user)