Ejemplo n.º 1
0
    def _get_template(self):
        file_name = str(uuid.uuid4()) + ".xls"
        path_to_target = os.path.join(PATH_TO_GENERATE_INVOICE, file_name)
        path = os.path.join(PATH_WEB, file_name)

        pi = PrintInvoice(
            path=os.path.join(PATH_TEMPLATE, self.TEMPLATE),
            destination=path_to_target)
        pi.path_web = path
        return pi
Ejemplo n.º 2
0
    def save_retail_invoice(cls, retail, items, path_target):
        """
        Сохраняем позиции розничной накладной и формируем бланк.
        """
        from services.goodservice import GoodService
        retail.retailinvoiceitems.delete()

        db.session.add(retail)

        for it in items:
            #Проверяем проставлена ли цена розницу.
            print it.id_good
            good = GoodService.get_good(it.id_good)
            if not PriceService.get_price(good.price_id).price_retail:
                raise RetailNotPriceException(
                    u"У товара должна быть указана розничная цена. %s" % it.full_name)

            retailitem_q = RetailInvoiceItem.query.filter(
                RetailInvoiceItem.retailinvoice==retail,
                RetailInvoiceItem.good_id==good.id)

            if retailitem_q.count() > 0:
                retail_item = retailitem_q.one()
                raise RetailDuplicateItemsException(
                    u"В накладной не может быть двух одинаковых позиций. %s" % retail_item.full_name)

            retail_item = RetailInvoiceItem(
                good_id=good.id, retailinvoice=retail)
            db.session.add(retail_item)

        pi = PrintInvoice(
            path=os.path.join(path_template, 'print_invoice.xls'),
            destination=path_target)
        pi.set_cells(0, 0, ['a', 'b', 'c', 'date'])
        pi.set_cells(0, 2, ['name', 'count', 'price_pay', 'mul'])
        pi.write(0, 0, [{'a': u'', 'b': u'', 'c': u'', 'date': retail.date.strftime('%d.%m.%Y')}, ])

        pi.write(0, 2, [
            {'name': it.full_name, 'count': '',
             'price_pay': GoodService.get_price(it.id_good).price_retail, 'mul': ''} for it in items])

        retail.file = path_target
        db.session.commit()
Ejemplo n.º 3
0
    def upgrade_items(cls, waybill, items, path_target, path):
        from priceserv import PriceService
        from services import GoodService
        from pointsale import PointSaleService

        # for waybl_item in waybill.items:
        #     pointsaleitem = PointSaleService.get_item_to_pointsale_good(
        #         waybill.pointsale_from_id, waybl_item.good_id)
        #     if waybl_item.count:
        #         pointsaleitem.count += waybl_item.count
        #         db.session.add(pointsaleitem)

        waybill.items.delete()
        #
        db.session.add(waybill)

        items = filter(lambda x: x.is_approve, items)

        for it in items:
            good = GoodService.get_good(it.good_id)
            if waybill.type == RETAIL:
                if not good.price_id or not PriceService.get_price(good.price_id).price_retail:
                    raise WayBillServiceException(
                        u"Товар без розничной цены. %s" % good.full_name)
            else:
                if not good.price_id or not PriceService.get_price(good.price_id).price_gross:
                    raise WayBillServiceException(
                        u"Товар без оптовой цены. %s" % good.full_name)

            retail_item = WayBillItems(
                good_id=good.id, waybill=waybill, count=it.count if it.count else None)
            # if it.count:
            #     count = int(it.count)
                # pointsaleitem = PointSaleService.get_item_to_pointsale_good(
                # waybill.pointsale_from_id, good.id)
                # pointsaleitem.count -= count
                # db.session.add(pointsaleitem)
            db.session.add(retail_item)

        pi = PrintInvoice(
            path=os.path.join(PATH_TEMPLATE, 'print_invoice.xls'),
            destination=path_target)
        pi.set_cells(0, 0, ['a', 'b', 'c', 'date'])
        pi.set_cells(0, 2, ['name', 'count', 'price_pay', 'mul'])
        pi.write(0, 0, [{'a': u'', 'b': u'', 'c': u'', 'date': waybill.date.strftime('%d.%m.%Y')}, ])

        if waybill.type == RETAIL:
            pi.write(0, 2, [
                {'name': it.fullname, 'count': it.count or "",
                 'price_pay': GoodService.get_price(it.good_id).price_retail, 'mul': ''} for it in items])
        else:
            pi.write(0, 2, [
                {'name': it.fullname, 'count': it.count or "",
                 'price_pay': GoodService.get_price(it.good_id).price_gross, 'mul': ''} for it in items])


        waybill.file = path
Ejemplo n.º 4
0
    def get(self, id):

        waybill = WayBillReturnService.get_by_id(id)

        file_name = str(uuid.uuid4()) + ".xls"
        path_to_target = os.path.join(PATH_TO_GENERATE_INVOICE, file_name)
        path = os.path.join(PATH_WEB, file_name)

        pi = PrintInvoice(
            path=os.path.join(PATH_TEMPLATE, 'print_waybillreturn.xls'),
            destination=path_to_target)
        pi.set_cells(0, 0, [('number', 2)])
        pi.set_cells(0, 3, ['a', 'date', 'c', 'c', 'c', 'receiver'])
        pi.set_cells(0, 4, ['a', 'date_to'])
        pi.set_cells(0, 5, ['a', 'type'])
        pi.set_cells(0, 7, [('name', 5), 'count_plan', 'count'])

        pi.write(0, 0, 0, [{'number': waybill.number}])
        pi.write(0, 3, 2, [{'date': waybill.date.strftime(
            '%d.%m.%Y').decode("utf-8"), 'receiver': waybill.rec}])
        pi.write(0, 4, 0, [{'date_to': waybill.date_to.strftime(
            '%d.%m.%Y').decode("utf-8")}])
        pi.write(0, 5, 0, [{'type': waybill.type}])

        if waybill.type == RETAIL:
            items = [
                {'name': it.good.full_name, 'count_plan': it.count_plan or "",
                 'count': it.count or ""} for it in waybill.items]
            pi.write(0, 7, 2, items)
        else:
            items = [
                {'name': it.good.full_name, 'count_plan': it.count_plan or "",
                 'count': it.count or ""} for it in waybill.items]
            pi.write(0, 7, 2, items)

        return {"link": path}