Esempio n. 1
0
    def handle(self, pi, id):
        from applications.good.service import GoodService
        inventory = InventoryService.get_by_id(id)

        su = sum(map(
            lambda it: GoodService.get_price(
                it.good_id).price_retail * it.count_after, inventory.items))

        pi.set_cells(0, 0, [('number', 2)])
        pi.set_cells(0, 2, ['a', 'date', 'c', 'c', 'c', 'sum'])
        pi.set_cells(0, 3, ['a', 'pointsale'])
        pi.set_cells(0, 6, [('name', 5), 'price', 'a', 'count', 'b', 'c', 'd'])

        pi.write(0, 0, 0, [{'number': inventory.number}])
        pi.write(0, 2, 1, [{'date': inventory.datetimenew.strftime(
            "%d.%m.%Y - %H:%M:%S"), 'sum': su}])
        pi.write(0, 3, 0, [{'pointsale': inventory.location.name}])

        items = [
            {'name': it.good.full_name, 'count': it.count_after or "",
             'price': GoodService.get_price(it.good_id).price_retail,
             'a': '',
             'b': '',
             'c': '',
             'd': ''} for it in inventory.items]
        pi.write(0, 6, 2, items)
Esempio n. 2
0
def convert_itemitems_to_json(item, type):
    price = GoodService.get_price(item.good_id)

    return {
        'id': item.id,
        'full_name': item.good.full_name,
        'good_id': item.good_id,
        'count_invoice': item.count,
        'price': price.price_retail if type == 1 else price.price_gross,
        'price_gross': price.price_gross,
        'price_retail': price.price_retail,
        'is_approve': True
    }
Esempio n. 3
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)]
Esempio n. 4
0
    def get_item_to_acceptance(cls, invoice_id, acceptance_id):
        from applications.point_sale.service import PointSaleService
        from applications.acceptance.service import AcceptanceService
        acceptance = AcceptanceService.get_by_id(acceptance_id)
        pointsale = acceptance.pointsale

        return [{
            "id": item.id,
            "full_name": item.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": PointSaleService.item_to_pointsale_good(
                pointsale.id, item.good_id).count
            if PointSaleService.item_to_pointsale_good(
                pointsale.id, item.good_id) else "",

        } for item in cls.get_items(invoice_id=invoice_id)]
Esempio n. 5
0
    def report_multi(cls, ids):
        import uuid
        import os
        from config import PATH_TO_GENERATE_INVOICE, PATH_WEB
        from excel.output import PATH_TEMPLATE
        from applications.good.service import GoodService

        COUNT_ROW = 42
        COUNT_ROW2 = 91
        file_name = str(uuid.uuid4()) + ".xlsx"
        path_to_target = os.path.join(PATH_TO_GENERATE_INVOICE, file_name)
        path = os.path.join(PATH_WEB, file_name)

        report = SpreadsheetReport(os.path.join(
            PATH_TEMPLATE, 'print_invoice2.xlsx'))

        for id in ids:

            waybill = WayBillService.get_by_id(id)
            sec_sub = report.get_section("sec1")
            sec_items = report.get_section("secitem")
            sec_data = {}
            sec_data['number'] = waybill.number
            sec_data['date'] = waybill.date.strftime('%d.%m.%Y').decode("utf-8")
            sec_data['point'] = waybill.pointsale_from.name
            sec_data['typeInv'] = waybill.type
            sec_data['rec'] = waybill.rec
            sec_sub.flush(sec_data)
            if waybill.type == RETAIL:

                for it in waybill.items:
                    sec_items_data = {
                        'name': it.good.full_name, 'count': it.count or "",
                        'price_pay': GoodService.get_price(it.good_id).price_retail,
                        'mul': it.count * GoodService.get_price(
                            it.good_id).price_retail if it.count else ''}
                    sec_items.flush(sec_items_data)
                if waybill.items.count() <= COUNT_ROW:
                    for i in xrange(COUNT_ROW - waybill.items.count()):
                        sec_items.flush({'name': '', 'count': '',
                                         'price_pay': '', 'mul': ''})
                elif waybill.items.count() <= COUNT_ROW2:
                    for i in xrange(COUNT_ROW2 - waybill.items.count()):
                        sec_items.flush({'name': '', 'count': '',
                                         'price_pay': '', 'mul': ''})
            else:
                for it in waybill.items:
                    sec_items_data = {'name': it.good.full_name,
                                      'count': it.count or "",
                     'price_pay': GoodService.get_price(it.good_id).price_gross,
                     'mul': it.count * GoodService.get_price(
                         it.good_id).price_gross if it.count else ''}
                    sec_items.flush(sec_items_data)
                if waybill.items.count() <= COUNT_ROW:
                    for i in xrange(COUNT_ROW - waybill.items.count()):
                        sec_items.flush({'name': '', 'count': '',
                                         'price_pay': '', 'mul': ''})
                elif waybill.items.count() <= COUNT_ROW2:
                    for i in xrange(COUNT_ROW2 - waybill.items.count()):
                        sec_items.flush({'name': '', 'count': '',
                                         'price_pay': '', 'mul': ''})

        report.build(path_to_target)

        return path