mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 11:19:09 +00:00
Merge pull request #30991 from frappe/mergify/bp/version-13-hotfix/pr-30968
fix(accounts): minor fixes & validations (backport #30968)
This commit is contained in:
@@ -357,6 +357,12 @@ class PaymentEntry(AccountsController):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if ref_doc.doctype == "Purchase Invoice" and ref_doc.get("on_hold"):
|
||||||
|
frappe.throw(
|
||||||
|
_("{0} {1} is on hold").format(d.reference_doctype, d.reference_name),
|
||||||
|
title=_("Invalid Invoice"),
|
||||||
|
)
|
||||||
|
|
||||||
if ref_doc.docstatus != 1:
|
if ref_doc.docstatus != 1:
|
||||||
frappe.throw(_("{0} {1} must be submitted").format(d.reference_doctype, d.reference_name))
|
frappe.throw(_("{0} {1} must be submitted").format(d.reference_doctype, d.reference_name))
|
||||||
|
|
||||||
|
|||||||
@@ -743,6 +743,21 @@ class TestPaymentEntry(unittest.TestCase):
|
|||||||
flt(payment_entry.total_taxes_and_charges, 2), flt(10 / payment_entry.target_exchange_rate, 2)
|
flt(payment_entry.total_taxes_and_charges, 2), flt(10 / payment_entry.target_exchange_rate, 2)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_payment_entry_against_onhold_purchase_invoice(self):
|
||||||
|
pi = make_purchase_invoice()
|
||||||
|
|
||||||
|
pe = get_payment_entry("Purchase Invoice", pi.name, bank_account="_Test Bank USD - _TC")
|
||||||
|
pe.reference_no = "1"
|
||||||
|
pe.reference_date = "2016-01-01"
|
||||||
|
|
||||||
|
# block invoice after creating payment entry
|
||||||
|
# since `get_payment_entry` will not attach blocked invoice to payment
|
||||||
|
pi.block_invoice()
|
||||||
|
with self.assertRaises(frappe.ValidationError) as err:
|
||||||
|
pe.save()
|
||||||
|
|
||||||
|
self.assertTrue("is on hold" in str(err.exception).lower())
|
||||||
|
|
||||||
|
|
||||||
def create_payment_entry(**args):
|
def create_payment_entry(**args):
|
||||||
payment_entry = frappe.new_doc("Payment Entry")
|
payment_entry = frappe.new_doc("Payment Entry")
|
||||||
|
|||||||
@@ -3086,6 +3086,39 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
si.reload()
|
si.reload()
|
||||||
self.assertTrue(si.items[0].serial_no)
|
self.assertTrue(si.items[0].serial_no)
|
||||||
|
|
||||||
|
def test_sales_invoice_with_disabled_account(self):
|
||||||
|
try:
|
||||||
|
account = frappe.get_doc("Account", "VAT 5% - _TC")
|
||||||
|
account.disabled = 1
|
||||||
|
account.save()
|
||||||
|
|
||||||
|
si = create_sales_invoice(do_not_save=True)
|
||||||
|
si.posting_date = add_days(getdate(), 1)
|
||||||
|
si.taxes = []
|
||||||
|
|
||||||
|
si.append(
|
||||||
|
"taxes",
|
||||||
|
{
|
||||||
|
"charge_type": "On Net Total",
|
||||||
|
"account_head": "VAT 5% - _TC",
|
||||||
|
"cost_center": "Main - _TC",
|
||||||
|
"description": "VAT @ 5.0",
|
||||||
|
"rate": 9,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
si.save()
|
||||||
|
|
||||||
|
with self.assertRaises(frappe.ValidationError) as err:
|
||||||
|
si.submit()
|
||||||
|
|
||||||
|
self.assertTrue(
|
||||||
|
"Cannot create accounting entries against disabled accounts" in str(err.exception)
|
||||||
|
)
|
||||||
|
|
||||||
|
finally:
|
||||||
|
account.disabled = 0
|
||||||
|
account.save()
|
||||||
|
|
||||||
def test_gain_loss_with_advance_entry(self):
|
def test_gain_loss_with_advance_entry(self):
|
||||||
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry
|
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ def make_gl_entries(
|
|||||||
if gl_map:
|
if gl_map:
|
||||||
if not cancel:
|
if not cancel:
|
||||||
validate_accounting_period(gl_map)
|
validate_accounting_period(gl_map)
|
||||||
|
validate_disabled_accounts(gl_map)
|
||||||
gl_map = process_gl_map(gl_map, merge_entries)
|
gl_map = process_gl_map(gl_map, merge_entries)
|
||||||
if gl_map and len(gl_map) > 1:
|
if gl_map and len(gl_map) > 1:
|
||||||
save_entries(gl_map, adv_adj, update_outstanding, from_repost)
|
save_entries(gl_map, adv_adj, update_outstanding, from_repost)
|
||||||
@@ -43,6 +44,26 @@ def make_gl_entries(
|
|||||||
make_reverse_gl_entries(gl_map, adv_adj=adv_adj, update_outstanding=update_outstanding)
|
make_reverse_gl_entries(gl_map, adv_adj=adv_adj, update_outstanding=update_outstanding)
|
||||||
|
|
||||||
|
|
||||||
|
def validate_disabled_accounts(gl_map):
|
||||||
|
accounts = [d.account for d in gl_map if d.account]
|
||||||
|
|
||||||
|
Account = frappe.qb.DocType("Account")
|
||||||
|
|
||||||
|
disabled_accounts = (
|
||||||
|
frappe.qb.from_(Account)
|
||||||
|
.where(Account.name.isin(accounts) & Account.disabled == 1)
|
||||||
|
.select(Account.name, Account.disabled)
|
||||||
|
).run(as_dict=True)
|
||||||
|
|
||||||
|
if disabled_accounts:
|
||||||
|
account_list = "<br>"
|
||||||
|
account_list += ", ".join([frappe.bold(d.name) for d in disabled_accounts])
|
||||||
|
frappe.throw(
|
||||||
|
_("Cannot create accounting entries against disabled accounts: {0}").format(account_list),
|
||||||
|
title=_("Disabled Account Selected"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def validate_accounting_period(gl_map):
|
def validate_accounting_period(gl_map):
|
||||||
accounting_periods = frappe.db.sql(
|
accounting_periods = frappe.db.sql(
|
||||||
""" SELECT
|
""" SELECT
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ def tax_account_query(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
{account_type_condition}
|
{account_type_condition}
|
||||||
AND is_group = 0
|
AND is_group = 0
|
||||||
AND company = %(company)s
|
AND company = %(company)s
|
||||||
|
AND disabled = %(disabled)s
|
||||||
AND (account_currency = %(currency)s or ifnull(account_currency, '') = '')
|
AND (account_currency = %(currency)s or ifnull(account_currency, '') = '')
|
||||||
AND `{searchfield}` LIKE %(txt)s
|
AND `{searchfield}` LIKE %(txt)s
|
||||||
{mcond}
|
{mcond}
|
||||||
@@ -175,6 +176,7 @@ def tax_account_query(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
dict(
|
dict(
|
||||||
account_types=filters.get("account_type"),
|
account_types=filters.get("account_type"),
|
||||||
company=filters.get("company"),
|
company=filters.get("company"),
|
||||||
|
disabled=filters.get("disabled", 0),
|
||||||
currency=company_currency,
|
currency=company_currency,
|
||||||
txt="%{}%".format(txt),
|
txt="%{}%".format(txt),
|
||||||
offset=start,
|
offset=start,
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ frappe.ui.form.on(cur_frm.doctype, {
|
|||||||
query: "erpnext.controllers.queries.tax_account_query",
|
query: "erpnext.controllers.queries.tax_account_query",
|
||||||
filters: {
|
filters: {
|
||||||
"account_type": account_type,
|
"account_type": account_type,
|
||||||
"company": doc.company
|
"company": doc.company,
|
||||||
|
"disabled": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user