improved items searching code
This commit is contained in:
parent
94659173f6
commit
295dfb2267
|
|
@ -1194,7 +1194,7 @@ def import_invoice_with_mapping(invoice_data, purchase_order_name=None, schedule
|
|||
item_name = item.get("productName", "").strip()
|
||||
item_code = item.get("itemId", "") or f"CODE-{invoice_data.get('serialNumber', '')}"
|
||||
|
||||
# ИСПРАВЛЕНО: Ищем соответствие с учетом регистра и без
|
||||
# Ищем соответствие товара
|
||||
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
|
||||
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:
|
||||
# Если соответствие не найдено, добавляем в список несопоставленных
|
||||
unmatched_items.append({
|
||||
|
|
@ -2289,16 +2298,18 @@ def normalize_string(text, consider_azeri=True):
|
|||
if not text:
|
||||
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:
|
||||
azeri_replacements = {
|
||||
# Заглавные буквы
|
||||
'Ə': 'E',
|
||||
'Ü': 'U',
|
||||
'Ö': 'O',
|
||||
'Ğ': 'G',
|
||||
'İ': 'I',
|
||||
'Ç': 'C',
|
||||
'Ş': 'S',
|
||||
# Строчные буквы
|
||||
'ə': 'e',
|
||||
'ü': 'u',
|
||||
'ö': 'o',
|
||||
|
|
@ -2311,6 +2322,13 @@ def normalize_string(text, consider_azeri=True):
|
|||
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())
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
"fieldname": "etaxes_party_type",
|
||||
"fieldtype": "Select",
|
||||
"label": "E-Taxes Type",
|
||||
"options": "Sender\nReceiver",
|
||||
"options": "Sender\nReceiver\nSender/Receiver",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
|
|
@ -69,7 +69,7 @@
|
|||
"fieldname": "erp_party_type",
|
||||
"fieldtype": "Select",
|
||||
"label": "System Party Type",
|
||||
"options": "Supplier\nCustomer",
|
||||
"options": "Supplier\nCustomer\nSupplier/Customer",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
|
|
@ -110,7 +110,7 @@
|
|||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2025-07-04 16:03:02.271586",
|
||||
"modified": "2025-07-11 14:14:02.884948",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Invoice Az",
|
||||
"name": "E-Taxes Parties",
|
||||
|
|
|
|||
|
|
@ -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_code = item.get("itemId", "") or f"CODE-{invoice_data.get('serialNumber', '')}"
|
||||
|
||||
# ИСПРАВЛЕНО: Ищем соответствие товара с учетом регистра и без
|
||||
# Ищем соответствие товара
|
||||
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
|
||||
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:
|
||||
# Если соответствие не найдено, добавляем в список несопоставленных
|
||||
unmatched_items.append({
|
||||
|
|
@ -630,3 +639,47 @@ def get_etaxes_sales():
|
|||
'success': False,
|
||||
'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
|
||||
|
|
|
|||
Loading…
Reference in New Issue