fix: guard accounting_method queries with has_column check

Prevents migration failure when jey_erp custom fields are not yet
synced (Unknown column 'accounting_method' error).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ali 2026-04-02 23:10:04 +04:00
parent 2b0426de0b
commit ed92176ce4
2 changed files with 21 additions and 6 deletions

View File

@ -16,10 +16,16 @@ from frappe import _
from frappe.utils import flt
def _get_accounting_method(company):
if not frappe.db.has_column("Company", "accounting_method"):
return ""
return frappe.db.get_value("Company", company, "accounting_method") or ""
def on_payment_entry_submit(doc, method):
"""Hook: called when Payment Entry is submitted."""
company = doc.company
accounting_method = frappe.db.get_value("Company", company, "accounting_method")
accounting_method = _get_accounting_method(company)
if accounting_method != "Kassa metodu":
return
@ -156,7 +162,7 @@ def _create_transfer_je(payment, entry, settings):
def on_journal_entry_submit(doc, method):
"""Hook: when JE with Дт 226 / Кт 211 is submitted, auto-allocate via FIFO."""
company = doc.company
accounting_method = frappe.db.get_value("Company", company, "accounting_method")
accounting_method = _get_accounting_method(company)
if accounting_method != "Kassa metodu":
return
@ -265,7 +271,7 @@ def on_journal_entry_submit(doc, method):
def on_payment_entry_cancel(doc, method):
"""Hook: cancel related cash method JEs when Payment is cancelled."""
company = doc.company
accounting_method = frappe.db.get_value("Company", company, "accounting_method")
accounting_method = _get_accounting_method(company)
if accounting_method != "Kassa metodu":
return

View File

@ -6,6 +6,13 @@ Runs after migrate — checks if accounts exist and creates them if missing.
import frappe
from frappe import _
def _get_accounting_method(company):
"""Safely get accounting_method — returns '' if the custom field column doesn't exist yet."""
if not frappe.db.has_column("Company", "accounting_method"):
return ""
return frappe.db.get_value("Company", company, "accounting_method") or ""
REQUIRED_ACCOUNTS = [
{
"account_number": "245.1",
@ -48,7 +55,7 @@ def check_and_create_accounts():
continue
# Check accounting method — only create if Kassa
method = frappe.db.get_value("Company", company.name, "accounting_method") or ""
method = _get_accounting_method(company.name)
if "Kassa" not in method:
continue
@ -110,7 +117,7 @@ def _create_account(company, abbr, acc_def):
def update_tax_templates_for_method(company):
"""Switch Sales/Purchase Tax Templates based on accounting method."""
method = frappe.db.get_value("Company", company, "accounting_method") or ""
method = _get_accounting_method(company)
abbr = frappe.db.get_value("Company", company, "abbr")
if "Kassa" in method:
@ -163,6 +170,8 @@ def update_tax_templates_for_method(company):
def on_company_update(doc, method):
"""Hook: when Company is saved, update templates if accounting method changed."""
if not frappe.db.has_column("Company", "accounting_method"):
return
old_method = doc.get_db_value("accounting_method") if not doc.is_new() else ""
new_method = doc.accounting_method or ""
@ -181,7 +190,7 @@ def check_required_accounts(company):
return {"accounts": [], "missing": []}
abbr = frappe.db.get_value("Company", company, "abbr")
method = frappe.db.get_value("Company", company, "accounting_method") or ""
method = _get_accounting_method(company)
accounts = []
missing = []