예제 #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"
예제 #3
0
 def post(self, id):
     try:
         inventory = WayBillService.get_by_id(id)
         status = request.json['data']['status']
         WayBillService.status(inventory, status)
         db.session.add(inventory)
         db.session.commit()
         return inventory
     except Exception as exc:
         message = u" Не удалось сменить статус `накладной` %s." % id
         error(message + unicode(exc))
         abort(400, message=message)
예제 #4
0
    def get(self):

        args = parser.parse_args()
        ids = json.loads(args['ids'])
        path = WayBillService.report_multi(ids)

        return {'link': path}
예제 #5
0
    def get(self):
        args = parser.parse_args()
        invoice_id = args['invoice_id']
        receiver_id = args['receiver_id']
        pointsale_id = args['pointsale_id']
        type = args['type']

        count = WayBillService.count_exists(invoice_id, receiver_id,
                                            pointsale_id, type)
        if count:
            if count > 1:
                return {'status': True, 'extra': 'multi'}
            else:
                waybill = WayBillService.get_by_attr(invoice_id, receiver_id,
                                                     pointsale_id, type)
                return {'status': True, 'data': waybill, 'extra': 'single'}
        else:
            return {'status': False}
예제 #6
0
    def get_items_acceptance(cls, acc_id, remain=True):
        from applications.point_sale.service import PointSaleService
        from applications.acceptance.service import AcceptanceService
        from applications.waybill.service import WayBillService
        acceptance = AcceptanceService.get_by_id(acc_id)
        pointsale = acceptance.pointsale

        def get_count_remain(remain, item, pointsale_id):
            if remain:
                return PointSaleService.item_to_pointsale_good(
                    pointsale.id, item.good_id).count \
                    if PointSaleService.item_to_pointsale_good(
                    pointsale.id, item.good_id) else ""
            else:
                return item.count

        if acceptance.invoice:

            return [{
                "id": item.id,
                "full_name": item.full_name,
                "good_id": item.good_id,
                "price_without_NDS": item.price_without_NDS,
                "price_with_NDS": item.price_with_NDS,
                "price_retail": GoodService.get_price(
                    item.good_id).price_retail if GoodService.get_price(
                    item.good_id) else "",
                "price_gross": GoodService.get_price(
                    item.good_id).price_gross if GoodService.get_price(
                    item.good_id) else "",
                "count": get_count_remain(remain, item, pointsale.id),
                "fact_count": item.fact_count

            } for item in cls.get_items(invoice_id=acceptance.invoice_id)]

        elif acceptance.waybill_crud:
            return [{
                "id": item.id,
                "full_name": item.good.full_name,
                "good_id": item.good_id,
                "price_retail": GoodService.get_price(
                    item.good_id).price_retail if GoodService.get_price(
                    item.good_id) else "",
                "price_gross": GoodService.get_price(
                    item.good_id).price_gross if GoodService.get_price(
                    item.good_id) else "",
                "count": get_count_remain(remain, item, pointsale.id),

            } for item in WayBillService.get_items(acceptance.waybill_id)]
예제 #7
0
 def get(self, id):
     waybill = WayBillService.get_by_id(id)
     return {'items': [convert_itemitems_to_json(x, waybill.type) for x in
                       waybill.items]}
예제 #8
0
    def get(self, id):

        path = WayBillService.report(id)

        return {"link": path}