diff --git a/invoice_az/api.py b/invoice_az/api.py index 051b6a7..682fccf 100644 --- a/invoice_az/api.py +++ b/invoice_az/api.py @@ -4307,133 +4307,3 @@ def refresh_token_from_asan_login(): 'success': False, 'message': str(e) } - -@frappe.whitelist() -def test_product_groups_api(product_type="service"): - """Test API request to get product groups from e-taxes - - Args: - product_type: Type of products to fetch - "service" or "good" - """ - # Записываем активность - record_etaxes_activity() - - # Получаем токен из настроек - asan_login_settings = get_default_asan_login() - if not asan_login_settings.get('found'): - return { - 'success': False, - 'message': 'No Asan Login settings found. Please configure authentication first.' - } - - token = asan_login_settings.get('main_token') - if not token: - return { - 'success': False, - 'message': 'No authentication token found. Please authenticate first.' - } - - # Валидация типа продукта - if product_type not in ['service', 'good']: - product_type = 'service' - - # URL для запроса - url = f"https://new.e-taxes.gov.az/api/po/dictionary/public/v1/productGroups/find?queryText=&type={product_type}&scope=ALL" - - # Заголовки запроса - headers = { - "Accept": "application/json, text/plain, */*", - "Content-Type": "application/json", - "Cache-Control": "no-cache", - "x-authorization": f"Bearer {token}" - } - - try: - # Выполняем GET запрос - response = requests.get(url, headers=headers, timeout=30) - - # Проверяем статус код 500 - if response.status_code == 500: - frappe.log_error(f"[TEST_PRODUCT_GROUPS] Server error 500", "E-Taxes Server Error") - return { - 'success': False, - 'error': 'server_error', - 'message': 'Service temporarily unavailable. Please try again in a few minutes.', - 'status_code': 500 - } - - # Проверяем статус код 401 - if response.status_code == 401: - frappe.log_error(f"[TEST_PRODUCT_GROUPS] Unauthorized 401", "E-Taxes Auth Error") - return { - 'success': False, - 'error': 'unauthorized', - 'message': 'Authentication required. Please login again.', - 'status_code': 401 - } - - # Проверяем успешность запроса - response.raise_for_status() - - # Получаем JSON данные - data = response.json() - - # Логируем успешный ответ - frappe.log_error( - f"[TEST_PRODUCT_GROUPS] Success: received {len(data) if isinstance(data, list) else 'data'} items for type={product_type}", - "E-Taxes Test API Success" - ) - - return { - 'success': True, - 'message': f'Successfully retrieved product groups (type: {product_type})', - 'data': data, - 'count': len(data) if isinstance(data, list) else None, - 'product_type': product_type - } - - except requests.exceptions.HTTPError as e: - frappe.log_error( - f"[TEST_PRODUCT_GROUPS] HTTP error: {e.response.status_code} - {str(e)}", - "E-Taxes Test API Error" - ) - - if e.response.status_code == 401: - return { - 'success': False, - 'error': 'unauthorized', - 'message': 'Authentication required. Please login again.', - 'status_code': 401 - } - elif e.response.status_code == 500: - return { - 'success': False, - 'error': 'server_error', - 'message': 'Service temporarily unavailable. Please try again in a few minutes.', - 'status_code': 500 - } - - return { - 'success': False, - 'error': 'http_error', - 'message': f'HTTP Error: {str(e)}' - } - - except requests.exceptions.Timeout: - frappe.log_error(f"[TEST_PRODUCT_GROUPS] Request timeout", "E-Taxes Test API Error") - return { - 'success': False, - 'error': 'timeout', - 'message': 'Request timeout. Please try again.' - } - - except Exception as e: - frappe.log_error( - f"[TEST_PRODUCT_GROUPS] Unexpected error: {str(e)}\n{frappe.get_traceback()}", - "E-Taxes Test API Error" - ) - return { - 'success': False, - 'error': 'unknown_error', - 'message': f'An error occurred: {str(e)}' - } diff --git a/invoice_az/client/journal_entry.js b/invoice_az/client/journal_entry.js index 9a72e73..1808515 100644 --- a/invoice_az/client/journal_entry.js +++ b/invoice_az/client/journal_entry.js @@ -1422,9 +1422,9 @@ frappe.listview_settings['Journal Entry'] = { formatters: { expense_income_type: function(value) { if (value === 'Income') { - return '' + value + ''; + return '' + value + ''; } else if (value === 'Expense') { - return '' + value + ''; + return '' + value + ''; } return value || ''; }, @@ -1432,7 +1432,7 @@ frappe.listview_settings['Journal Entry'] = { etaxes_document_type: function(value, field, doc) { // Show blue badge "ƏDV" only for documents loaded from e-taxes if (value === 'ədv' && (doc.loaded_from_etaxes === 1 || doc.loaded_from_etaxes === '1')) { - return 'ƏDV'; + return 'ƏDV'; } return ''; } diff --git a/invoice_az/client/sales_invoice.js b/invoice_az/client/sales_invoice.js index 7e7b2f0..26ad049 100644 --- a/invoice_az/client/sales_invoice.js +++ b/invoice_az/client/sales_invoice.js @@ -1490,15 +1490,6 @@ frappe.ui.form.on('Sales Invoice', { * Add E-Taxes buttons based on current status */ function add_etaxes_buttons(frm) { - // Add test buttons - always visible - frm.add_custom_button(__('Test API - Services'), function() { - test_product_groups_api(frm, 'service'); - }, __('E-Taxes')); - - frm.add_custom_button(__('Test API - Goods'), function() { - test_product_groups_api(frm, 'good'); - }, __('E-Taxes')); - // Status: Sent and Signed - show indicator and details button if (frm.doc.etaxes_send_status === 'Sent and Signed') { frm.page.set_indicator(__('Sent to E-Taxes'), 'green'); @@ -2108,121 +2099,6 @@ function show_etaxes_details(frm) { }); } -/** - * Test Product Groups API function - * @param {object} frm - The form object - * @param {string} productType - Type of products to fetch ('service' or 'good') - */ -function test_product_groups_api(frm, productType) { - productType = productType || 'service'; - const typeLabel = productType === 'service' ? __('Services') : __('Goods'); - - // Show loading dialog - ETaxes.dialogs.showLoading( - __('Testing API'), - __('Requesting {0} from E-Taxes...', [typeLabel]), - __('Please wait') - ); - - // Call backend API - frappe.call({ - method: 'invoice_az.api.test_product_groups_api', - args: { - product_type: productType - }, - callback: function(r) { - if (r.message && r.message.success) { - // Success - const count = r.message.count || 0; - const data = r.message.data || []; - - ETaxes.dialogs.setSuccess( - __('API Test Successful'), - __('Received {0} product groups ({1})', [count, typeLabel]), - function() { - // Show detailed results - let html = '
| Code | Name | Type |
|---|---|---|
| ' + (item.code || '-') + ' | '; - html += '' + (item.name || '-') + ' | '; - html += '' + (item.type || '-') + ' | '; - html += '
Showing first 10 of ' + data.length + ' items
'; - } - } else if (typeof data === 'object') { - html += ''; - html += JSON.stringify(data, null, 2); - html += ''; - } else { - html += '
No data received
'; - } - - html += '