예제 #1
0
    def save_model(self, obj):
        file_name = str(uuid.uuid4()) + ".xls"
        path_to_target = os.path.join(PATH_TO_GENERATE_INVOICE, file_name)
        try:
            if not obj.id:
                waybill = WayBillService.create(
                    obj.pointsale_from_id, obj.invoice_id, obj.date,
                    obj.receiver_id, obj.pointsale_id, obj.type,
                    obj.typeRec, forse=True)
            else:
                super(WayBillCanon, self).save_model(obj)
                waybill = obj
            if obj.waybill_items:
                debug(u"Сохранение позиций накладной %s." % obj)
                try:
                    items = WayBillService.build_retail_items(
                        obj.waybill_items)
                except Exception as exc:
                    debug(u"Ошибка сохранения накладной %s. " + unicode(
                        exc) % obj)
                    raise WayBillCanon.WayBillCanonException(unicode(exc))

                path = url_for('static', filename='files/' + file_name)
                WayBillService.upgrade_items(
                    waybill, items, path_to_target, path)
                waybill.file_load = path
            else:
                waybill.file_load = waybill.file
        except WayBillServiceException as exc:
            debug(u"Сохранение накладной %s не удалось." % obj)
            raise WayBillCanon.WayBillCanonException(unicode(exc))
        return waybill
예제 #2
0
    def post(self):
        try:
            debug(u"Сохранение пачки накладных.")
            pointSource = request.json['pointSource']
            pointitems = request.json['pointReceiver']
            items = request.json['items']
            date = request.json['date']
            date = HelperService.convert_to_pydate(date)
            type = request.json['type']
            typeRec = request.json['typeRec']
            for it in items:
                it['count'] = 0
            for item in pointitems:
                waybill = WayBillService.create(
                    pointSource['id'], None, date, None, item['id'], type,
                    typeRec)
                waybill.waybill_items = items
                if waybill.waybill_items:
                    debug(u"Сохранение позиций накладной %s." % waybill)
                    try:
                        waybill_items = WayBillService.build_retail_items(
                            waybill.waybill_items)
                    except Exception as exc:
                        debug(u"Ошибка сохранения накладной %s. " + unicode(
                            exc) % waybill)
                        raise WayBillCanon.WayBillCanonException(unicode(exc))

                    WayBillService.upgrade_items(waybill, waybill_items)
        except Exception as exc:
            db.session.rollback()
            debug(u"Сохранение накладной %s не удалось." % unicode(exc))
            abort(400, message=unicode(exc))

        db.session.commit()
        return "ok"