feat(telegram): Unify Trezorerie button (Casa + Banca combined)

- Replace separate [Trezorerie Casa] and [Trezorerie Banca] buttons
  with single unified [Trezorerie] button in main menu
- Add format_treasury_combined_response() formatter showing:
  - Grand total (Sold Trezorerie)
  - Casa section with total + all accounts
  - Banca section with total + all accounts
- Compact menu layout: Row 2 [Sold Companie][Trezorerie],
  Row 3 [Sold Clienti][Sold Furnizori], Row 4 [Evolutie Incasari]
- Use Romanian number format (period as thousands separator)

Also includes:
- Oracle pool: Support both SERVICE_NAME and SID connections
  (ORACLE_SERVICE_NAME takes priority over ORACLE_SID)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-30 19:15:05 +02:00
parent ab160b628d
commit 4a886f0b64
9 changed files with 843 additions and 19 deletions

View File

@@ -15,7 +15,8 @@ ORACLE_USER=CONTAFIN_ORACLE
ORACLE_PASSWORD=your_oracle_password_here
ORACLE_HOST=localhost
ORACLE_PORT=1526
ORACLE_SID=roa
# ORACLE_SID=roa # Deprecated
ORACLE_SERVICE_NAME=ROA
# TEST: Start SSH tunnel before running backend
# ./ssh-tunnel-test.sh start
@@ -109,7 +110,7 @@ TEST_COMPANY_SCHEMA=MARIUSM_AUTO
# ============================================================================
# Obtain bot token from @BotFather on Telegram
TELEGRAM_BOT_TOKEN=your_bot_token_from_botfather
TELEGRAM_BOT_TOKEN=8483383555:AAGNY1z6WiBkvVfy1ZV_gM_JnAqW4q4MlEY
# Backend URL for bot to communicate with API
BACKEND_URL=http://localhost:8000

View File

@@ -187,6 +187,61 @@ def format_treasury_banca_response(data: Dict[str, Any], company_name: str = Non
return text
def format_treasury_combined_response(data: Dict[str, Any], company_name: str = None) -> str:
"""
Format combined treasury data (Casa + Banca) for Telegram.
Shows grand total, Casa section with accounts, and Banca section with accounts
in a single unified message. Compact format without section titles.
Args:
data: Dict with 'casa' and 'banca' keys from get_treasury_breakdown_split()
company_name: Company name (kept for compatibility, not used)
Returns:
Formatted Markdown string with grand total and both sections
Example:
data = {'casa': {...}, 'banca': {...}}
text = format_treasury_combined_response(data)
"""
def format_amount(amount: int) -> str:
"""Format amount with period as thousands separator (Romanian style)."""
return f"{amount:,}".replace(",", ".")
text = ""
# Extract totals - rounded to whole RON
casa_total = round(data.get('casa', {}).get('total', 0))
banca_total = round(data.get('banca', {}).get('total', 0))
grand_total = casa_total + banca_total
# Grand total header
text += f"**Sold Trezorerie:** {format_amount(grand_total)} RON\n\n"
# Casa section - compact
text += f"**Casa:** {format_amount(casa_total)} RON\n"
casa_accounts = data.get('casa', {}).get('accounts', [])
if casa_accounts:
for acc in casa_accounts:
name = acc.get('name', 'N/A')
balance = round(acc.get('balance', 0))
text += f" - {name}: {format_amount(balance)} RON\n"
text += "\n"
# Banca section - compact
text += f"**Banca:** {format_amount(banca_total)} RON\n"
banca_accounts = data.get('banca', {}).get('accounts', [])
if banca_accounts:
for acc in banca_accounts:
name = acc.get('name', 'N/A')
balance = round(acc.get('balance', 0))
text += f" - {name}: {format_amount(balance)} RON\n"
return text
def format_clients_balance_response(
clients: List[Dict[str, Any]],
maturity_data: Dict[str, Any],

View File

@@ -1483,6 +1483,37 @@ async def handle_menu_callback(query, telegram_user_id: int, callback_data: str)
is_callback=True
)
elif action == "trezorerie":
# Trezorerie unified (Casa + Banca combined)
from backend.modules.telegram.bot.helpers import get_treasury_breakdown_split
treasury_data = await get_treasury_breakdown_split(company['id'], jwt_token)
from backend.modules.telegram.bot.formatters import format_treasury_combined_response, add_performance_footer
from backend.modules.telegram.bot.menus import create_action_buttons, format_response_with_company
content = format_treasury_combined_response(treasury_data)
response = format_response_with_company(content, company['name'])
# Add performance footer if cache metadata is available
if 'cache_hit' in treasury_data and 'response_time_ms' in treasury_data:
cache_hit = treasury_data['cache_hit']
response_time_ms = treasury_data['response_time_ms']
cache_source = treasury_data.get('cache_source', None)
response = add_performance_footer(response, cache_hit, response_time_ms, cache_source)
keyboard = create_action_buttons("trezorerie", show_export=False, show_refresh=False)
try:
await query.edit_message_text(
response,
reply_markup=keyboard,
parse_mode=ParseMode.MARKDOWN
)
except Exception as e:
# Ignore "Message is not modified" error
if "Message is not modified" not in str(e):
raise
elif action == "casa":
# Trezorerie casa
from backend.modules.telegram.bot.helpers import get_treasury_breakdown_split

View File

@@ -230,18 +230,17 @@ def create_main_menu(
)
])
# Rows 2-4: Financial options (2 buttons per row, made wide by message text padding)
# Rows 2-4: Financial options (compact layout with unified Trezorerie button)
keyboard.extend([
[
InlineKeyboardButton("Sold Companie", callback_data="menu:sold"),
InlineKeyboardButton("Trezorerie Casa", callback_data="menu:casa")
InlineKeyboardButton("Trezorerie", callback_data="menu:trezorerie")
],
[
InlineKeyboardButton("Trezorerie Banca", callback_data="menu:banca"),
InlineKeyboardButton("Sold Clienti", callback_data="menu:clienti")
InlineKeyboardButton("Sold Clienti", callback_data="menu:clienti"),
InlineKeyboardButton("Sold Furnizori", callback_data="menu:furnizori")
],
[
InlineKeyboardButton("Sold Furnizori", callback_data="menu:furnizori"),
InlineKeyboardButton("Evolutie Incasari", callback_data="menu:evolutie")
]
])