Exemple #1
0
def create_order(kwargs):
    money_given = int(kwargs.get('amount_entered', 0) * 100)

    total_price = 0
    total_price_without_discount = 0

    for ware in kwargs['wares']:
        total_price = total_price + ware['amount']
        total_price_without_discount += ware['quantity'] * ware['price']

    total_price = round_half_down(total_price, 2)
    total_price_without_discount = round_half_down(
        total_price_without_discount, 2)
    pennies = int(total_price * 100)

    if kwargs['payment_type'] == PaymentChoices.CASH.value:
        process_order(money_given, kwargs)
    elif kwargs['payment_type'] == PaymentChoices.NON_CASH.value:
        kwargs.update({'arcus_data': arcus_purchase(pennies)})
        print_arcus_document(kwargs['arcus_data']['cheque'])
        process_order(pennies, kwargs)

    kwargs.update({'total_price': total_price})
    kwargs.update(
        {'total_price_without_discount': total_price_without_discount})
Exemple #2
0
def find_and_modify_one_ware_with_discount(
        wares, get_only_one_discounted_product=False):
    _wares = deepcopy(wares)
    total_sum = 0
    for w in _wares:
        total_sum = w['price'] * w['quantity'] + total_sum

    total_sum = round_half_down(total_sum, 2)
    num_dec = round_half_down(float(str(total_sum - int(total_sum))[1:]), 2)

    item = max(_wares, key=lambda x: x['price'])

    if not num_dec:
        if get_only_one_discounted_product:
            return {
                'discountedPrice': 0,
                'barcode': item['barcode'],
                'discountedSum': 0,
                'orderSum': total_sum,
                'discountedOrderSum': total_sum
            }
        else:
            return wares

    disc_price = round_half_down(item['price'] - num_dec, 2)
    total_sum_with_discount = round_half_down(total_sum - num_dec, 2)

    if item['quantity'] == 1:
        item.update({'discountedPrice': disc_price})
        item.update({'discount': num_dec})
    if item['quantity'] > 1:
        new_ware = deepcopy(item)
        item.update({'quantity': item['quantity'] - 1})
        item.update({'discountedPrice': 0})
        new_ware.update({'discountedPrice': disc_price})
        new_ware.update({'discount': num_dec})
        new_ware.update({'quantity': 1})
        _wares.append(new_ware)

    if get_only_one_discounted_product:
        _item = max(_wares, key=lambda x: x.get('discountedPrice', 0))
        return {
            'barcode': _item['barcode'],
            'discountedPrice': _item['discountedPrice'],
            'discountedSum': num_dec,
            'orderSum': total_sum,
            'discountedOrderSum': total_sum_with_discount
        }

    return _wares
Exemple #3
0
def _build_wares(wares):
    _wares = []
    copied_wares = deepcopy(wares)
    for pos, ware in enumerate(copied_wares, 1):
        # tax_rate = get_cashbox_tax_from_fiscal_tax(int(ware['tax_number']))
        tax_rate = int(ware['tax_rate'])
        divi = float(f'{1}.{tax_rate // 10}')
        multi = tax_rate / 100
        price = ware.get('discountedPrice') or ware['price']
        price_for_all = round_half_down(price * ware['quantity'], 2)

        tax_sum = round_half_up(price_for_all / divi * multi, 2)

        ware.update({
            'posNumber': pos,
            'priceDiscount': price,
            'taxRate': tax_rate,
            'taxSum': tax_sum,
            'tax_number': get_fiscal_tax_from_cashbox_tax(tax_rate),
            'amount': price_for_all,
            'department': CS['department']
        })
        _wares.append(ware)

    return _wares
Exemple #4
0
    def handle_order(*args, **kwargs):
        cashier = kwargs['cashier_name'] or DEFAULT_CASHIER_NAME
        p_type = kwargs['payment_type']
        d_type = kwargs['document_type']
        order_number = kwargs.get('order_number', 0)
        wares = kwargs['wares']
        money_given = kwargs.get('amount_entered', 0)
        pay_link = kwargs.get('pay_link', '')
        pref = kwargs.get('order_prefix', '')
        order_number += 1
        print('orderr number -> ', order_number, 'pay_link ', pay_link)
        text = f"\n\n\n--------------------------------------------\n" \
               f"(font-style=BIG_BOLD)     НОМЕР ЗАКАЗА: (font-style=BIG_BOLD){pref}{order_number}" \
               f"\n --------------------------------------------\n\n"
        result = real_kkt.new_transaction(
            cashier=cashier, payment_type=p_type, doc_type=d_type,
            wares=copy.copy(wares), amount=money_given, rrn=pay_link,
            # order_prefix=pref,
            print_strings=text if d_type == DocumentTypes.PAYMENT else ''
        )

        if result['error']:
            msg = f'Ошибка во время транзакции: {result["message"]}'
            raise CashboxException(data=msg, to_logging=msg + f'\nИнформация: {result}')

        from pprint import pprint as pp
        print('FROM FISKALNIK')
        pp(result)

        info = {}
        transaction_sum = round_half_down(result['transaction_sum'] - result['discount_sum'], 2)
        info['cashier_name'] = result['cashier']
        info['datetime'] = result['datetime']
        info['doc_number'] = result['doc_number']
        # При наличном платеже с пирита приходит transaction_sum без округления в меньшую сторону,
        # и пока можно оставить строчку ниже без изменений
        info['total_without_discount'] = round_half_down(result['transaction_sum'], 2)

        info['transaction_sum'] = transaction_sum
        # info['check_number'] = result['check_number']
        info['check_number'] = str(int(str(result['check_number']).rsplit('.', maxsplit=1)[-1]))
        info['order_num'] = order_number
        info['rrn'] = result.get('rrn', '')
        info['pan_card'] = result.get('pan_card', '')
        info['cardholder_name'] = result.get('cardholder_name', '')
        return info
Exemple #5
0
def recalc_total(window):
    liststore = window.liststore
    total_value_widget = window.total_value
    total = 0
    for row in liststore:
        total += row[3]

    total = round_half_down(total, 4)
    total_value_widget.set_label(str(total))
Exemple #6
0
async def get_shift_info(*args, **kwargs):
    result = kwargs['opened_port_info']
    current_shift = Cashbox.box().current_opened_shift
    shift_info = {
        'shift_open_time': str(current_shift.creation_date).replace('T', ' '),
        'total_money_in_cashbox': round_half_down(result['cash_balance'], 2),
        'shift_number': current_shift.shiftNumber,
        'shift_total_inserted': current_shift.total_inserted_money_in_shift,
        'shift_total_removed': current_shift.total_removed_money_in_shift,
        'shift_total_sales': current_shift.total_sales_in_shift,
        'shift_total_returns': current_shift.total_returns_in_shift,
        'start_shift_money': current_shift.start_shift_money
    }
    return shift_info
Exemple #7
0
async def partial_return(*args, **kwargs):
    cashbox = Cashbox.box()
    kkt_info = kwargs['opened_port_info']
    data = kwargs['valid_schema_data']
    order_id = data['internal_order_uuid']
    doc_type = DocumentTypes.RETURN.value
    data_for_checkstatus = {
        'proj': cashbox.project_number,
        'clientOrderID': order_id
    }
    checkstatus_url = CS['paygateAddress'] + PaygateURLs.check_order_status
    return_part_url = CS['paygateAddress'] + PaygateURLs.refund_part
    checkstatus = await request_to_paygate(checkstatus_url, 'POST',
                                           data_for_checkstatus)

    # print('| chekstatus response -> ', checkstatus)

    if checkstatus['orderStatus'] == 'cancelled':
        msg = 'Этот заказ уже был отменён'
        to_log = msg + f'\nОтвет с платежного шлюза: {checkstatus}'
        raise CashboxException(data=msg, to_logging=to_log)

    valid_sum = checkstatus['confirmedSum']

    _wares = []
    total_wares_sum = 0

    for ware in data['wares']:
        total_wares_sum += ware['priceDiscount'] * ware['quantity']
        _wares.append({
            'name': ware['name'],
            'price': ware['priceDiscount'],
            'priceDiscount': ware['priceDiscount'],
            'barcode': ware['barcode'],
            'tax_number': ware['tax_number'],
            'quantity': ware['quantity'],
            'discount': 0,
            'posNumber': ware['posNumber']
        })
    total_wares_sum = round_half_down(total_wares_sum, 2)

    # print('total wares sum ', total_wares_sum, 'valid sum ', valid_sum)
    if total_wares_sum > valid_sum:
        msg = 'Сумма переданых товаров превышает оставшуюся сумму заказа!'
        to_log = msg + f'\nСумма товаров: {total_wares_sum} \nСумма заказа в paygate: {valid_sum}'
        raise CashboxException(data=msg, to_logging=to_log)

    to_kkt = {
        'total_wares_sum': total_wares_sum,
        'cashier_name': data['cashier_name'],
        'payment_type': data['payment_type'],
        'document_type': doc_type,
        'amount_entered': data['total_price_with_discount'],
        'pay_link': data['payment_link'],
        'wares': _wares
    }

    result = KKTDevice.handle_order(**to_kkt)

    # pp('formatted info!!!')
    # pp(result)

    to_paygate = {
        'clientOrderID': order_id,
        'proj': cashbox.project_number,
        'wares': _wares,
        'checkNumber': int(result['check_number']),
        'cashID': kkt_info['fn_number'],
        'refundAmount': result['transaction_sum']
    }

    try:
        content = await request_to_paygate(return_part_url, 'POST', to_paygate)
    except CashboxException as exc:
        to_kkt['document_type'] = DocumentTypes.PAYMENT.value
        # TODO: Что-нибудь придумать с этим кейсом. Пока что это не работает должным образом
        KKTDevice.handle_order(**to_kkt)
        raise CashboxException(data=exc.data['errors'], to_logging=exc.data)

    # print('| refund_part response -> ', content)

    return {'actual_order_price': content.get('confirmedSum', 0)}