def delete_gl_entries(gl_entries=None, voucher_type=None, voucher_no=None, adv_adj=False, update_outstanding="Yes"): from erpnext.accounts.doctype.gl_entry.gl_entry import validate_balance_type, \ check_freezing_date, update_outstanding_amt, validate_frozen_account if not gl_entries: gl_entries = frappe.db.sql(""" select account, posting_date, party_type, party, cost_center, fiscal_year,voucher_type, voucher_no, against_voucher_type, against_voucher, cost_center, company from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no), as_dict=True) if gl_entries: check_freezing_date(gl_entries[0]["posting_date"], adv_adj) frappe.db.sql("""delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", (voucher_type or gl_entries[0]["voucher_type"], voucher_no or gl_entries[0]["voucher_no"])) for entry in gl_entries: validate_frozen_account(entry["account"], adv_adj) validate_balance_type(entry["account"], adv_adj) validate_expense_against_budget(entry) if entry.get("against_voucher") and update_outstanding == 'Yes': update_outstanding_amt(entry["account"], entry.get("party_type"), entry.get("party"), entry.get("against_voucher_type"), entry.get("against_voucher"), on_cancel=True)
def delete_gl_entries(gl_entries=None, voucher_type=None, voucher_no=None, adv_adj=False, update_outstanding="Yes"): from erpnext.accounts.doctype.gl_entry.gl_entry import validate_balance_type, \ check_freezing_date, update_outstanding_amt, validate_frozen_account if not gl_entries: gl_entries = frappe.db.sql("""select * from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no), as_dict=True) if gl_entries: check_freezing_date(gl_entries[0]["posting_date"], adv_adj) frappe.db.sql( """delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", (voucher_type or gl_entries[0]["voucher_type"], voucher_no or gl_entries[0]["voucher_no"])) for entry in gl_entries: validate_frozen_account(entry["account"], adv_adj) validate_balance_type(entry["account"], adv_adj) validate_expense_against_budget(entry) if entry.get("against_voucher") and update_outstanding == 'Yes': update_outstanding_amt(entry["account"], entry.get("party_type"), entry.get("party"), entry.get("against_voucher_type"), entry.get("against_voucher"), on_cancel=True)
def delete_gl_entries(gl_entries=None, voucher_type=None, voucher_no=None, adv_adj=False, update_outstanding="Yes"): from erpnext.accounts.doctype.gl_entry.gl_entry import validate_balance_type, \ check_freezing_date, update_outstanding_amt, validate_frozen_account if not gl_entries: gl_entries = frappe.db.sql(""" select account, posting_date, party_type, party, cost_center, fiscal_year, voucher_type, voucher_no, against_voucher_type, against_voucher, cost_center from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no), as_dict=True) if gl_entries: check_freezing_date(gl_entries[0]["posting_date"], adv_adj) frappe.db.sql("""delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", (voucher_type or gl_entries[0]["voucher_type"], voucher_no or gl_entries[0]["voucher_no"])) for entry in gl_entries: validate_frozen_account(entry["account"], adv_adj) validate_balance_type(entry["account"], adv_adj) if entry.get("against_voucher") and update_outstanding == 'Yes': update_outstanding_amt(entry["account"], entry.get("party_type"), entry.get("party"), entry.get("against_voucher_type"), entry.get("against_voucher"), on_cancel=True) #reset the committed budget too acc_type = frappe.db.get_value("Account", entry["account"], "account_type") if acc_type == "Expense Account" or acc_type == "Fixed Asset": frappe.db.sql("delete from `tabCommitted Budget` where po_no = %s", entry["voucher_no"]) frappe.db.sql("delete from `tabConsumed Budget` where po_no = %s", entry["voucher_no"])
def delete_gl_entries(gl_entries=None, voucher_type=None, voucher_no=None, adv_adj=False, update_outstanding="Yes"): from erpnext.accounts.doctype.gl_entry.gl_entry import validate_balance_type, \ check_freezing_date, update_outstanding_amt, validate_frozen_account if not gl_entries: gl_entries = frappe.db.sql(""" select account, posting_date, party_type, party, cost_center, fiscal_year,voucher_type, voucher_no, against_voucher_type, against_voucher, cost_center, company from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no), as_dict=True) if gl_entries: check_freezing_date(gl_entries[0]["posting_date"], adv_adj) frappe.db.sql( """delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", (voucher_type or gl_entries[0]["voucher_type"], voucher_no or gl_entries[0]["voucher_no"])) vouchers_for_balance_update = set() for entry in gl_entries: validate_frozen_account(entry["account"], adv_adj) validate_balance_type(entry["account"], adv_adj) if not adv_adj: validate_expense_against_budget(entry) if update_outstanding and not adv_adj and entry.get( "party_type") and entry.get("party"): if entry.get("against_voucher_type") and entry.get( "against_voucher"): vouchers_for_balance_update.add( (entry.get("against_voucher_type"), entry.get("against_voucher"), entry.get("account"), entry.get("party_type"), entry.get("party"))) else: vouchers_for_balance_update.add( (entry.get("voucher_type"), entry.get("voucher_no"), entry.get("account"), entry.get("party_type"), entry.get("party"))) for voucher_type, voucher_no, account, party_type, party in vouchers_for_balance_update: update_outstanding_amt(voucher_type, voucher_no, account, party_type, party, on_cancel=True)
def delete_gl_entries(gl_entries=None, voucher_type=None, voucher_no=None, adv_adj=False, update_outstanding="Yes"): from erpnext.accounts.doctype.gl_entry.gl_entry import validate_balance_type, \ check_freezing_date, update_outstanding_amt, validate_frozen_account if not gl_entries: gl_entries = frappe.db.sql(""" select account, posting_date, party_type, party, cost_center, fiscal_year, voucher_type, voucher_no, against_voucher_type, against_voucher, cost_center from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no), as_dict=True) if gl_entries: check_freezing_date(gl_entries[0]["posting_date"], adv_adj) frappe.db.sql( """delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", (voucher_type or gl_entries[0]["voucher_type"], voucher_no or gl_entries[0]["voucher_no"])) for entry in gl_entries: validate_frozen_account(entry["account"], adv_adj) validate_balance_type(entry["account"], adv_adj) if entry.get("against_voucher") and update_outstanding == 'Yes': update_outstanding_amt(entry["account"], entry.get("party_type"), entry.get("party"), entry.get("against_voucher_type"), entry.get("against_voucher"), on_cancel=True) #reset the committed budget too acc_type = frappe.db.get_value("Account", entry["account"], "account_type") if acc_type == "Expense Account" or acc_type == "Fixed Asset": frappe.db.sql("delete from `tabCommitted Budget` where po_no = %s", entry["voucher_no"]) frappe.db.sql("delete from `tabConsumed Budget` where po_no = %s", entry["voucher_no"])