Beispiel #1
0
    def execute(self, bot, update, trans, subaction_id, data=None):
        if subaction_id == self.ACTION_SHARE_ALL:
            print("3. Parsing: " + str(datetime.datetime.now().time()))
            cbq = update.callback_query
            bill_id = data.get(const.JSON_BILL_ID)

            __, __, __, is_closed = trans.get_bill_gen_info(bill_id)
            if is_closed is not None:
                debts, unique_users = utils.calculate_remaining_debt(
                    bill_id, trans)
                text, pm = utils.format_debts_bill_text(
                    bill_id, debts, unique_users, trans)
                btns = DisplayPayItemsKB.get_payment_buttons(bill_id,
                                                             cbq.from_user.id,
                                                             trans,
                                                             debts=debts)
                kb = InlineKeyboardMarkup(btns)
                cbq.answer()
                return cbq.edit_message_text(text=text,
                                             parse_mode=pm,
                                             reply_markup=kb)

            user_id = data.get(const.JSON_USER_ID)
            if user_id is None:
                raise Exception('Missing user_id')
            self.share_all_items(bot, cbq, bill_id, user_id, trans)
            print("7. Sent: " + str(datetime.datetime.now().time()))
            counter.Counter.remove_count()
Beispiel #2
0
    def get_payment_buttons(bill_id, user_id, trans, debts=None):
        kb = []
        if debts is None:
            debts, __ = utils.calculate_remaining_debt(bill_id, trans)
        for debt in debts:
            text = '💸 Pay '
            for debtor in debt['debtors']:
                if (debtor['debtor'][0] == user_id
                        and debtor['status'] == '(Pending)'):
                    text = '💰 Unpay '
                    break

            credtr = debt['creditor']
            refresh_btn = InlineKeyboardButton(
                text="🔄 Refresh Bill",
                callback_data=utils.get_action_callback_data(
                    MODULE_ACTION_TYPE, ACTION_REFRESH_BILL,
                    {const.JSON_BILL_ID: bill_id}))
            pay_btn = InlineKeyboardButton(
                text=text + utils.format_name(credtr[3], credtr[1], credtr[2]),
                callback_data=utils.get_action_callback_data(
                    MODULE_ACTION_TYPE, ACTION_PAY_DEBT, {
                        const.JSON_BILL_ID: bill_id,
                        const.JSON_CREDITOR_ID: credtr[0]
                    }))
            kb.append([refresh_btn])
            kb.append([pay_btn])

        return kb
Beispiel #3
0
 def refresh_debt_bill(self, bill_id, cbq, trans):
     debts, unique_users = utils.calculate_remaining_debt(bill_id, trans)
     text, pm = utils.format_debts_bill_text(bill_id, debts, unique_users,
                                             trans)
     kb = get_redirect_pay_keyboard(bill_id)
     cbq.answer()
     cbq.edit_message_text(text=text, parse_mode=pm, reply_markup=kb)
 def get_debts_bill_msg(bill_id, user_id, trans):
     __, owner_id, __, __ = trans.get_bill_gen_info(bill_id)
     if user_id == owner_id:
         return SendDebtsBillAdmin.get_debts_bill_msg(bill_id, trans)
     debts, unique_users = utils.calculate_remaining_debt(bill_id, trans)
     text, pm = utils.format_debts_bill_text(bill_id, debts, unique_users,
                                             trans)
     kb = DisplayPayItemsKB.get_payment_buttons(bill_id, trans, debts=debts)
     return text, pm, InlineKeyboardMarkup(kb)
Beispiel #5
0
 def get_debt_bill_result(bill_id, trans):
     details = trans.get_bill_details(bill_id)
     debts, unique_users = utils.calculate_remaining_debt(bill_id, trans)
     text, pm = utils.format_debts_bill_text(bill_id, debts, unique_users,
                                             trans)
     kb = get_redirect_pay_keyboard(bill_id)
     return InlineQueryResultArticle(
         id=bill_id,
         title=details.get('title'),
         input_message_content=InputTextMessageContent(text, parse_mode=pm),
         reply_markup=kb,
         description='{}\nItems: {}'.format(
             utils.format_time(details.get('time')),
             str(len(details.get('items')))))
    def get_payment_buttons(bill_id, trans, debts=None):
        kb = []
        if debts is None:
            debts, __ = utils.calculate_remaining_debt(bill_id, trans)
        for debt in debts:
            credtr = debt['creditor']
            pay_btn = InlineKeyboardButton(
                text='Pay ' +
                utils.format_name(credtr[3], credtr[1], credtr[2]),
                callback_data=utils.get_action_callback_data(
                    MODULE_ACTION_TYPE, ACTION_PAY_DEBT, {
                        const.JSON_BILL_ID: bill_id,
                        const.JSON_CREDITOR_ID: credtr[0]
                    }))
            kb.append([pay_btn])

        return kb