fix: respect data loading checkboxes in reference data loading

Checkbox values (load_items, load_units, load_customers, load_suppliers)
were collected in the dialog but never passed through the loading pipeline,
causing all data types to always be created regardless of user selection.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ali 2026-03-27 19:40:46 +04:00
parent dca5a13de3
commit d3775786a3
2 changed files with 198 additions and 175 deletions

View File

@ -3764,7 +3764,9 @@ def get_reference_data_lists(data_type, limit=100, offset=0):
return {'success': False, 'message': str(e)}
@frappe.whitelist()
def process_single_invoice_for_reference_data(token, invoice_id, source_type='purchase'):
def process_single_invoice_for_reference_data(token, invoice_id, source_type='purchase',
load_items=1, load_units=1,
load_customers=1, load_suppliers=1):
"""Обрабатывает один инвойс и создает все 4 типа доктайпов"""
record_etaxes_activity()
@ -3805,8 +3807,12 @@ def process_single_invoice_for_reference_data(token, invoice_id, source_type='pu
'message': invoice_details.get('message', 'Failed to get invoice details')
}
# Создаем все доктайпы из одного инвойса
result = create_reference_data_from_single_invoice(invoice_details, source_type)
# Создаем доктайпы из одного инвойса (только выбранные типы)
result = create_reference_data_from_single_invoice(
invoice_details, source_type,
load_items=int(load_items), load_units=int(load_units),
load_customers=int(load_customers), load_suppliers=int(load_suppliers)
)
return result
@ -3818,8 +3824,10 @@ def process_single_invoice_for_reference_data(token, invoice_id, source_type='pu
}
@frappe.whitelist()
def create_reference_data_from_single_invoice(invoice_details, source_type):
"""Создает все 4 типа доктайпов из одного инвойса с EQM кодами - оптимизированная версия"""
def create_reference_data_from_single_invoice(invoice_details, source_type,
load_items=1, load_units=1,
load_customers=1, load_suppliers=1):
"""Создает доктайпы из одного инвойса с EQM кодами - оптимизированная версия"""
try:
stats = {
'items_created': 0,
@ -3838,6 +3846,7 @@ def create_reference_data_from_single_invoice(invoice_details, source_type):
receiver = invoice_details.get('receiver', {})
# === СОЗДАНИЕ ТОВАРОВ С EQM КОДАМИ ===
if int(load_items):
processed_items = set()
for item in items:
item_name = item.get('productName', '').strip()
@ -3950,6 +3959,7 @@ def create_reference_data_from_single_invoice(invoice_details, source_type):
frappe.log_error(f"Error creating E-Taxes Item {item_name}: {str(e)}", "Create Item Error")
# === СОЗДАНИЕ ЕДИНИЦ ===
if int(load_units):
processed_units = set()
for item in items:
unit_name = item.get('unit', '').strip()
@ -3983,7 +3993,7 @@ def create_reference_data_from_single_invoice(invoice_details, source_type):
frappe.log_error(f"Error creating E-Taxes Unit {unit_name}: {str(e)}", "Create Unit Error")
# === СОЗДАНИЕ КЛИЕНТОВ (RECEIVER) ===
if receiver:
if int(load_customers) and receiver:
receiver_name = (receiver.get('name') or '').strip()
receiver_tin = (receiver.get('tin') or '').strip()
receiver_address = (receiver.get('address') or '').strip()
@ -4021,7 +4031,7 @@ def create_reference_data_from_single_invoice(invoice_details, source_type):
sender_name = ' '.join(sender_name.split()) # Убираем лишние пробелы
if sender_name and sender_tin:
if source_type == 'purchase':
if source_type == 'purchase' and int(load_suppliers):
# Sender = Supplier для purchase инвойсов
if not frappe.db.exists('E-Taxes Suppliers', sender_name):
try:
@ -4043,7 +4053,7 @@ def create_reference_data_from_single_invoice(invoice_details, source_type):
frappe.log_error(f"Error creating E-Taxes Suppliers {sender_name}: {str(e)}", "Create Supplier Error")
else:
stats['suppliers_skipped'] += 1
else:
elif source_type != 'purchase' and int(load_customers):
# Sender = Customer для sales инвойсов
if not frappe.db.exists('E-Taxes Customers', sender_name):
try:

View File

@ -983,7 +983,7 @@ function start_reference_data_loading(frm, values) {
start_staged_invoice_loading(frm, values);
}
function process_invoices_for_reference_data(invoices, token, accumulated_data, current_index = 0, frm) {
function process_invoices_for_reference_data(invoices, token, accumulated_data, current_index = 0, frm, load_flags = null) {
// Инициализация при первом вызове
if (current_index === 0) {
window.cancelReferenceLoading = false;
@ -1050,7 +1050,11 @@ function process_invoices_for_reference_data(invoices, token, accumulated_data,
args: {
'token': token,
'invoice_id': invoice_id,
'source_type': source_type
'source_type': source_type,
'load_items': load_flags ? load_flags.load_items : 1,
'load_units': load_flags ? load_flags.load_units : 1,
'load_customers': load_flags ? load_flags.load_customers : 1,
'load_suppliers': load_flags ? load_flags.load_suppliers : 1
},
callback: function(r) {
if (r.message) {
@ -1071,7 +1075,7 @@ function process_invoices_for_reference_data(invoices, token, accumulated_data,
token = token_r.message.token;
setTimeout(function() {
if (!window.cancelReferenceLoading) {
process_invoices_for_reference_data(invoices, token, accumulated_data, current_index, frm);
process_invoices_for_reference_data(invoices, token, accumulated_data, current_index, frm, load_flags);
}
}, 100);
} else {
@ -1101,7 +1105,7 @@ function process_invoices_for_reference_data(invoices, token, accumulated_data,
// Переходим к следующему инвойсу
setTimeout(function() {
if (!window.cancelReferenceLoading) {
process_invoices_for_reference_data(invoices, token, accumulated_data, current_index + 1, frm);
process_invoices_for_reference_data(invoices, token, accumulated_data, current_index + 1, frm, load_flags);
}
}, 50);
@ -1117,14 +1121,14 @@ function process_invoices_for_reference_data(invoices, token, accumulated_data,
token = token_r.message.token;
setTimeout(function() {
if (!window.cancelReferenceLoading) {
process_invoices_for_reference_data(invoices, token, accumulated_data, current_index, frm);
process_invoices_for_reference_data(invoices, token, accumulated_data, current_index, frm, load_flags);
}
}, 100);
} else {
// Переходим к следующему инвойсу
setTimeout(function() {
if (!window.cancelReferenceLoading) {
process_invoices_for_reference_data(invoices, token, accumulated_data, current_index + 1, frm);
process_invoices_for_reference_data(invoices, token, accumulated_data, current_index + 1, frm, load_flags);
}
}, 100);
}
@ -1134,7 +1138,7 @@ function process_invoices_for_reference_data(invoices, token, accumulated_data,
// При других ошибках переходим к следующему инвойсу
setTimeout(function() {
if (!window.cancelReferenceLoading) {
process_invoices_for_reference_data(invoices, token, accumulated_data, current_index + 1, frm);
process_invoices_for_reference_data(invoices, token, accumulated_data, current_index + 1, frm, load_flags);
}
}, 100);
}
@ -2174,7 +2178,11 @@ function start_staged_invoice_loading(frm, values) {
inbox_completed: false,
outbox_completed: false,
token: null,
last_update_count: 0 // Для отслеживания когда показывать обновление
last_update_count: 0, // Для отслеживания когда показывать обновление
load_items: values.load_items ? 1 : 0,
load_units: values.load_units ? 1 : 0,
load_customers: values.load_customers ? 1 : 0,
load_suppliers: values.load_suppliers ? 1 : 0
};
window.cancelReferenceLoading = false;
@ -2344,7 +2352,12 @@ function check_loading_completion(loading_state, frm) {
suppliers_created: 0,
suppliers_skipped: 0,
total_invoices: loading_state.all_invoices.length
}, 0, frm);
}, 0, frm, {
load_items: loading_state.load_items,
load_units: loading_state.load_units,
load_customers: loading_state.load_customers,
load_suppliers: loading_state.load_suppliers
});
}, 2000);
}
}