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:
parent
2b0426de0b
commit
ed92176ce4
|
|
@ -16,10 +16,16 @@ from frappe import _
|
||||||
from frappe.utils import flt
|
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):
|
def on_payment_entry_submit(doc, method):
|
||||||
"""Hook: called when Payment Entry is submitted."""
|
"""Hook: called when Payment Entry is submitted."""
|
||||||
company = doc.company
|
company = doc.company
|
||||||
accounting_method = frappe.db.get_value("Company", company, "accounting_method")
|
accounting_method = _get_accounting_method(company)
|
||||||
|
|
||||||
if accounting_method != "Kassa metodu":
|
if accounting_method != "Kassa metodu":
|
||||||
return
|
return
|
||||||
|
|
@ -156,7 +162,7 @@ def _create_transfer_je(payment, entry, settings):
|
||||||
def on_journal_entry_submit(doc, method):
|
def on_journal_entry_submit(doc, method):
|
||||||
"""Hook: when JE with Дт 226 / Кт 211 is submitted, auto-allocate via FIFO."""
|
"""Hook: when JE with Дт 226 / Кт 211 is submitted, auto-allocate via FIFO."""
|
||||||
company = doc.company
|
company = doc.company
|
||||||
accounting_method = frappe.db.get_value("Company", company, "accounting_method")
|
accounting_method = _get_accounting_method(company)
|
||||||
|
|
||||||
if accounting_method != "Kassa metodu":
|
if accounting_method != "Kassa metodu":
|
||||||
return
|
return
|
||||||
|
|
@ -265,7 +271,7 @@ def on_journal_entry_submit(doc, method):
|
||||||
def on_payment_entry_cancel(doc, method):
|
def on_payment_entry_cancel(doc, method):
|
||||||
"""Hook: cancel related cash method JEs when Payment is cancelled."""
|
"""Hook: cancel related cash method JEs when Payment is cancelled."""
|
||||||
company = doc.company
|
company = doc.company
|
||||||
accounting_method = frappe.db.get_value("Company", company, "accounting_method")
|
accounting_method = _get_accounting_method(company)
|
||||||
|
|
||||||
if accounting_method != "Kassa metodu":
|
if accounting_method != "Kassa metodu":
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,13 @@ Runs after migrate — checks if accounts exist and creates them if missing.
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
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 = [
|
REQUIRED_ACCOUNTS = [
|
||||||
{
|
{
|
||||||
"account_number": "245.1",
|
"account_number": "245.1",
|
||||||
|
|
@ -48,7 +55,7 @@ def check_and_create_accounts():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Check accounting method — only create if Kassa
|
# 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:
|
if "Kassa" not in method:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -110,7 +117,7 @@ def _create_account(company, abbr, acc_def):
|
||||||
|
|
||||||
def update_tax_templates_for_method(company):
|
def update_tax_templates_for_method(company):
|
||||||
"""Switch Sales/Purchase Tax Templates based on accounting method."""
|
"""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")
|
abbr = frappe.db.get_value("Company", company, "abbr")
|
||||||
|
|
||||||
if "Kassa" in method:
|
if "Kassa" in method:
|
||||||
|
|
@ -163,6 +170,8 @@ def update_tax_templates_for_method(company):
|
||||||
|
|
||||||
def on_company_update(doc, method):
|
def on_company_update(doc, method):
|
||||||
"""Hook: when Company is saved, update templates if accounting method changed."""
|
"""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 ""
|
old_method = doc.get_db_value("accounting_method") if not doc.is_new() else ""
|
||||||
new_method = doc.accounting_method or ""
|
new_method = doc.accounting_method or ""
|
||||||
|
|
||||||
|
|
@ -181,7 +190,7 @@ def check_required_accounts(company):
|
||||||
return {"accounts": [], "missing": []}
|
return {"accounts": [], "missing": []}
|
||||||
|
|
||||||
abbr = frappe.db.get_value("Company", company, "abbr")
|
abbr = frappe.db.get_value("Company", company, "abbr")
|
||||||
method = frappe.db.get_value("Company", company, "accounting_method") or ""
|
method = _get_accounting_method(company)
|
||||||
|
|
||||||
accounts = []
|
accounts = []
|
||||||
missing = []
|
missing = []
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue