Esempio n. 1
0
 def save_typing(self, update, context):
     sign_ask_for = self.base_handler.get_data(update, context, self.base_handler.SIGNIN_ASK_FOR, None)
     if not sign_ask_for:
         return
     
     session = Session.get_from(context.user_data)
 
     go_to = None
     if re.search('odoo_connector_url$', sign_ask_for):
         session.set_auth_args(url= update.message.text)
         go_to = self.workflow_connector(update, context)
     elif re.search('odoo_connector_db$', sign_ask_for):
         session.set_auth_args(database= update.message.text)
         go_to = self.workflow_connector(update, context)
     elif re.search('username$', sign_ask_for):
         session.set_auth_args(username= update.message.text)
     
 
     elif re.search('password$', sign_ask_for):
         session.set_auth_args(password = update.message.text)
     
     Session.set_from(context.user_data, session)
 
     #self.base_handler.set_data(update, context, 
     #    self.base_handler.SIGN_HANDLER_MSG,
     #    'Got it! Please select to update.'
     #)
 
     return go_to or self.workflow_connector(update, context)
    def account(self, update, context):
        session = Session.get_from(context.user_data)
        accounts = session.datasource.account()
        reply_markup = None
        if isinstance(accounts, dict) and accounts.get('Success') and len(
                accounts.get('Data', [])):
            msg = 'Select the account'
            keyboard = []
            keyboardline = []
            for row in accounts.get('Data', []):
                if len(keyboardline) <= 1:
                    keyboardline.append(
                        InlineKeyboardButton(row.get('name'),
                                             callback_data='account_{}'.format(
                                                 row.get('id'))))
                if len(keyboardline) == 2:
                    keyboard.append(keyboardline)
                    keyboardline = []

            if len(keyboardline):
                keyboard.append(keyboardline)
            if len(keyboard):
                reply_markup = InlineKeyboardMarkup(keyboard)
            Log.info(accounts)
        else:
            Log.error(accounts)
            msg = "Could not get accounts, try later /done"

        self.base_handler.reply_text(update,
                                     context,
                                     text=msg,
                                     reply_markup=reply_markup)
        return self.WELCOME
    def confirm(self, update, context):
        session = Session.get_from(context.user_data)
        try:
            oper = self.operation(update, context)
            if oper == 'unidefined':
                raise Exception(
                    "First define what operation you want to do /income or /expense"
                )

            amount = self.base_handler.get_data(update, context,
                                                self.base_handler.HWH_AMOUNT,
                                                0)
            if not amount:
                raise Exception(
                    "Please run the command /income or /expense and capture the amount"
                )

            product_id = self.base_handler.get_data(
                update, context, self.base_handler.HWH_PRODUCT_ID, False)
            description = self.base_handler.get_data(
                update, context, self.base_handler.HWH_DESCRIPTION, False)
            account_id = self.base_handler.get_data(
                update, context, self.base_handler.HWH_ACCOUNT_ID, False)

            req = None
            if oper == 'income':
                req = session.datasource.income(product_id,
                                                description,
                                                amount,
                                                account_journal_id=account_id)
            elif oper == 'expense':
                req = session.datasource.expense(product_id,
                                                 description,
                                                 amount,
                                                 account_journal_id=account_id)

            if req and isinstance(req, dict) and req.get('Success'):
                msg = "The {} has been recorded\n\n"\
                    "{}\n"\
                    "Record other /income or /expense or get /help".format(
                        oper, self.state_text(update, context),
                    )
                self._reset(update, context)
                Log.info(req)
            else:
                Log.error(req)
                raise Exception("Failed to register the %s,  try later /done" %
                                oper)
        except Exception as e:
            Log.error(e)
            msg = str(e)
        self.base_handler.reply_text(update,
                                     context,
                                     text=msg,
                                     parse_mode='MarkdownV2')
        return self.WELCOME
 def save_typing(self, update, context):
     session = Session.get_from(context.user_data)
     if session.sign_handler and self.__class__.__name__ == 'SignHandler':
         return session.sign_handler.save_typing(update, context)
     else:
         sign_ask_for = self.base_handler.get_data(
             update, context, self.base_handler.SIGNIN_ASK_FOR, None)
         self.base_handler.set_data(update, context, sign_ask_for,
                                    update.message.text)
     return self.workflow_connector(update, context)
 def ask_for(self, update, context):
     session = Session.get_from(context.user_data)
     if session.sign_handler and self.__class__.__name__ == 'SignHandler':
         return session.sign_handler.ask_for(update, context)
     else:
         data = update.callback_query.data
         self.base_handler.set_data(update, context,
                                    self.base_handler.SIGNIN_ASK_FOR, data)
         text = 'Okay, tell me your {}'.format(data)
         self.base_handler.reply_text(update, context, text=text)
     return self.base_handler.STATE_TYPING_SIGNIN
Esempio n. 6
0
 def workflow_connector(self, update, context):
     connector = update.callback_query.data
     Session.del_from(context.user_data)
     session = Session.get_from(context.user_data)
     if connector == str(self.CALLBACK_ODOO_CONNECTOR):
         session.sign_handler = OdooSignHandler(self) 
         session.hey_wallet_handler = OdooHeyWalletHandler(self)
         session.datasource = Odoo()
     else:
         session.sign_handler = None
         session.hey_wallet_handler = None
         session.datasource = None
     
     Session.set_from(context.user_data, session)
     
     if session.sign_handler:
         return session.sign_handler.workflow_connector(update, context)
     
     return self.sign_handler.workflow_connector(update, context)
Esempio n. 7
0
    def auth(self, update, context):     
        session = Session.get_from(context.user_data)
        text = 'First  add  your  username and password '
        if session.get_auth_args('password', True) and session.get_auth_args('username', True):
            try:
                session.datasource.auth(**session.auth_args)
                if session.datasource.is_auth():
                    Session.set_from(context.user_data,session)
                    return session.hey_wallet_handler.welcome(update, context)
                else:
                    text = 'Fail auth, update your username or password'
            except Exception as e:
                text = 'Fail auth, update your username or password'
                if getattr(session.datasource, 'auth_exception'):
                    text= session.datasource.auth_exception(e) or text
                logger.error(str(e))

        self.base_handler.set_data(
            update, context,
            self.base_handler.SIGN_HANDLER_MSG,
            value=text
        )
        return self.workflow_connector(update, context)
    def auth(self, update, context):
        session = Session.get_from(context.user_data)
        if session.sign_handler and self.__class__.__name__ == 'SignHandler':
            return session.sign_handler.auth(update, context)

        return self.base_handler.hey_wallet_handler.welcome(update, context)
Esempio n. 9
0
 def button_connect(self, update, context):
     Session.get_from(context.user_data)
     return self.sign_handler.workflow_connect(update, context)
Esempio n. 10
0
 def auth(self, update, context):
     session = Session.get_from(context.user_data)
     if session.sign_handler:
         return session.sign_handler.auth(update, context)
     return self.sign_handler.auth(update, context)
Esempio n. 11
0
 def save_typing(self, update, context):
     session = Session.get_from(context.user_data)
     if session.sign_handler:
         return session.sign_handler.save_typing(update, context)
     return self.sign_handler.save_typing(update, context)
    def category(self, update, context):
        oper = self.operation(update, context)
        categories = None
        category_id_callback = getattr(update, 'callback_query') and getattr(
            update.callback_query, 'data') or None
        session = Session.get_from(context.user_data)

        if oper == 'income' and not category_id_callback:
            categories = session.datasource.category_income()
        elif oper == 'expense' and not category_id_callback:
            categories = session.datasource.category_expense()
        elif category_id_callback:
            categories = {
                'Success':
                True,
                'Data': [{
                    'id':
                    ''.join(filter(str.isdigit, category_id_callback))
                }]
            }
        else:
            msg = "Not is running commad /income or /expense for get category list"

        reply_markup = None
        if categories and isinstance(categories,
                                     dict) and categories.get('Success'):
            msg = 'Select the {} category.'.format(oper if oper else '')
            categories_data = categories.get('Data')
            category_product = None
            req = {}
            if len(categories_data) == 1:
                category_product = 'product_'
                req = session.datasource.product(categories_data[0].get('id'))
            elif len(categories_data) > 1:
                category_product = 'category_'
                req = categories
            if category_product:
                if isinstance(req, dict) and req.get('Success', False) and len(
                        req.get('Data', [])):
                    keyboard = []
                    keyboardline = []
                    for l in req.get('Data'):
                        if len(keyboardline) <= 1:
                            keyboardline.append(
                                InlineKeyboardButton(
                                    Emoji.add_label_category(l.get('name')),
                                    callback_data='{}{}'.format(
                                        category_product, l.get('id'))))

                        if len(keyboardline) == 2:
                            keyboard.append(keyboardline)
                            keyboardline = []

                    if len(keyboardline):
                        keyboard.append(keyboardline)
                    if len(keyboard):
                        reply_markup = InlineKeyboardMarkup(keyboard)
                else:
                    msg = "Could not get use categories use command /description"
            else:
                msg = "Could not get use categories use command /description"
        self.base_handler.reply_text(update,
                                     context,
                                     text=msg,
                                     reply_markup=reply_markup)
        return self.WELCOME