improved items searching code

This commit is contained in:
Ali 2025-07-11 15:31:48 +04:00
parent 94659173f6
commit 295dfb2267
3 changed files with 86 additions and 15 deletions

View File

@ -1194,7 +1194,7 @@ def import_invoice_with_mapping(invoice_data, purchase_order_name=None, schedule
item_name = item.get("productName", "").strip() item_name = item.get("productName", "").strip()
item_code = item.get("itemId", "") or f"CODE-{invoice_data.get('serialNumber', '')}" item_code = item.get("itemId", "") or f"CODE-{invoice_data.get('serialNumber', '')}"
# ИСПРАВЛЕНО: Ищем соответствие с учетом регистра и без # Ищем соответствие товара
mapped_item = item_mappings.get(item_name) mapped_item = item_mappings.get(item_name)
# Если не найдено, ищем без учета регистра # Если не найдено, ищем без учета регистра
@ -1205,6 +1205,15 @@ def import_invoice_with_mapping(invoice_data, purchase_order_name=None, schedule
mapped_item = mapping_value mapped_item = mapping_value
break break
# Если все еще не найдено, ищем с нормализацией азербайджанских символов
if not mapped_item:
normalized_input = normalize_string(item_name, consider_azeri=True)
for mapping_key, mapping_value in item_mappings.items():
normalized_key = normalize_string(mapping_key, consider_azeri=True)
if normalized_key == normalized_input:
mapped_item = mapping_value
break
if not mapped_item: if not mapped_item:
# Если соответствие не найдено, добавляем в список несопоставленных # Если соответствие не найдено, добавляем в список несопоставленных
unmatched_items.append({ unmatched_items.append({
@ -2289,16 +2298,18 @@ def normalize_string(text, consider_azeri=True):
if not text: if not text:
return '' return ''
# Convert to lowercase # ДОБАВЛЕНО: Сначала заменяем азербайджанские/турецкие символы ДО приведения к нижнему регистру
text = text.lower()
# Remove all special characters and numbers
text = re.sub(r'[^\w\s]', '', text)
text = re.sub(r'\d+', '', text)
# Replace Azerbaijani characters if needed
if consider_azeri: if consider_azeri:
azeri_replacements = { azeri_replacements = {
# Заглавные буквы
'Ə': 'E',
'Ü': 'U',
'Ö': 'O',
'Ğ': 'G',
'İ': 'I',
'Ç': 'C',
'Ş': 'S',
# Строчные буквы
'ə': 'e', 'ə': 'e',
'ü': 'u', 'ü': 'u',
'ö': 'o', 'ö': 'o',
@ -2311,6 +2322,13 @@ def normalize_string(text, consider_azeri=True):
for azeri_char, latin_char in azeri_replacements.items(): for azeri_char, latin_char in azeri_replacements.items():
text = text.replace(azeri_char, latin_char) text = text.replace(azeri_char, latin_char)
# Convert to lowercase ПОСЛЕ замены символов
text = text.lower()
# Remove all special characters and numbers
text = re.sub(r'[^\w\s]', '', text)
text = re.sub(r'\d+', '', text)
# Remove extra spaces # Remove extra spaces
text = ' '.join(text.split()) text = ' '.join(text.split())

View File

@ -40,7 +40,7 @@
"fieldname": "etaxes_party_type", "fieldname": "etaxes_party_type",
"fieldtype": "Select", "fieldtype": "Select",
"label": "E-Taxes Type", "label": "E-Taxes Type",
"options": "Sender\nReceiver", "options": "Sender\nReceiver\nSender/Receiver",
"read_only": 1 "read_only": 1
}, },
{ {
@ -69,7 +69,7 @@
"fieldname": "erp_party_type", "fieldname": "erp_party_type",
"fieldtype": "Select", "fieldtype": "Select",
"label": "System Party Type", "label": "System Party Type",
"options": "Supplier\nCustomer", "options": "Supplier\nCustomer\nSupplier/Customer",
"read_only": 1 "read_only": 1
}, },
{ {
@ -110,7 +110,7 @@
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2025-07-04 16:03:02.271586", "modified": "2025-07-11 14:14:02.884948",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Invoice Az", "module": "Invoice Az",
"name": "E-Taxes Parties", "name": "E-Taxes Parties",

View File

@ -339,7 +339,7 @@ def import_sales_invoice_with_mapping(invoice_data, schedule_date=None, warehous
item_name = re.sub(r'\s+', ' ', item.get("productName", "")).strip() item_name = re.sub(r'\s+', ' ', item.get("productName", "")).strip()
item_code = item.get("itemId", "") or f"CODE-{invoice_data.get('serialNumber', '')}" item_code = item.get("itemId", "") or f"CODE-{invoice_data.get('serialNumber', '')}"
# ИСПРАВЛЕНО: Ищем соответствие товара с учетом регистра и без # Ищем соответствие товара
mapped_item = item_mappings.get(item_name) mapped_item = item_mappings.get(item_name)
# Если не найдено, ищем без учета регистра # Если не найдено, ищем без учета регистра
@ -350,6 +350,15 @@ def import_sales_invoice_with_mapping(invoice_data, schedule_date=None, warehous
mapped_item = mapping_value mapped_item = mapping_value
break break
# Если все еще не найдено, ищем с нормализацией азербайджанских символов
if not mapped_item:
normalized_input = normalize_string(item_name, consider_azeri=True)
for mapping_key, mapping_value in item_mappings.items():
normalized_key = normalize_string(mapping_key, consider_azeri=True)
if normalized_key == normalized_input:
mapped_item = mapping_value
break
if not mapped_item: if not mapped_item:
# Если соответствие не найдено, добавляем в список несопоставленных # Если соответствие не найдено, добавляем в список несопоставленных
unmatched_items.append({ unmatched_items.append({
@ -630,3 +639,47 @@ def get_etaxes_sales():
'success': False, 'success': False,
'message': "An unknown error occurred, please try again in a few minutes." 'message': "An unknown error occurred, please try again in a few minutes."
} }
@frappe.whitelist()
def normalize_string(text, consider_azeri=True):
"""Normalizing string for comparison"""
import re
if not text:
return ''
# ДОБАВЛЕНО: Сначала заменяем азербайджанские/турецкие символы ДО приведения к нижнему регистру
if consider_azeri:
azeri_replacements = {
# Заглавные буквы
'Ə': 'E',
'Ü': 'U',
'Ö': 'O',
'Ğ': 'G',
'İ': 'I',
'Ç': 'C',
'Ş': 'S',
# Строчные буквы
'ə': 'e',
'ü': 'u',
'ö': 'o',
'ğ': 'g',
'ı': 'i',
'ç': 'c',
'ş': 's'
}
for azeri_char, latin_char in azeri_replacements.items():
text = text.replace(azeri_char, latin_char)
# Convert to lowercase ПОСЛЕ замены символов
text = text.lower()
# Remove all special characters and numbers
text = re.sub(r'[^\w\s]', '', text)
text = re.sub(r'\d+', '', text)
# Remove extra spaces
text = ' '.join(text.split())
return text