invoice_az/invoice_az/vat_operations.py

55 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Copyright (c) 2026, Jey ERP and contributors
# For license information, please see license.txt
import frappe
@frappe.whitelist()
def on_delete_journal_entry(doc, method):
"""
Удаляет связанные E-Taxes VAT Operations при удалении Journal Entry
Args:
doc: Документ Journal Entry
method: Метод события (on_trash или on_cancel)
"""
try:
# Ищем все VAT Operations, связанные с этим Journal Entry
vat_records = frappe.get_all(
"E-Taxes VAT Operations",
filters={"journal_entry": doc.name},
fields=["name"]
)
if vat_records:
for record in vat_records:
frappe.logger().info(
f"Deleting E-Taxes VAT Operations {record.name} "
f"due to Journal Entry {doc.name} deletion"
)
# Прямое удаление из БД (обходит on_trash)
frappe.db.delete('E-Taxes VAT Operations', {'name': record.name})
frappe.db.commit()
frappe.logger().info(f"Successfully deleted {len(vat_records)} VAT Operations records")
except Exception as e:
frappe.log_error(
f"Error deleting E-Taxes VAT Operations for Journal Entry {doc.name}: {str(e)}\n{frappe.get_traceback()}",
"Journal Entry Delete Error"
)
# Не прерываем удаление JE, только логируем ошибку
def set_title_from_customer_name(doc, method):
"""
Устанавливает title из customer_name_etaxes если поле заполнено
Args:
doc: Документ Journal Entry
method: Метод события (before_save)
"""
if hasattr(doc, 'customer_name_etaxes') and doc.customer_name_etaxes:
doc.title = doc.customer_name_etaxes