From 150cc5a664e0b6eb8db2d38f7faf98a2c4feb72a Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 2 May 2025 14:27:53 +0530 Subject: [PATCH 1/3] fix: validation for difference account (cherry picked from commit fb819c558ebaf24fff9e6457729800ebd71e4718) --- .../stock/doctype/stock_entry/stock_entry.py | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 3366309f38c..e5d46563e6f 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -430,17 +430,29 @@ class StockEntry(StockController): ).format(frappe.bold(self.company)) ) - elif ( - self.is_opening == "Yes" - and frappe.db.get_value("Account", d.expense_account, "report_type") == "Profit and Loss" - ): + acc_details = frappe.get_cached_value( + "Account", + d.expense_account, + ["account_type", "report_type"], + as_dict=True, + ) + + if self.is_opening == "Yes" and acc_details.report_type == "Profit and Loss": frappe.throw( _( - "Difference Account must be a Asset/Liability type account, since this Stock Entry is an Opening Entry" + "Difference Account must be a Asset/Liability type account (Temporary Opening), since this Stock Entry is an Opening Entry" ), OpeningEntryAccountError, ) + if acc_details.account_type == "Stock": + frappe.throw( + _( + "At row {0}: the Difference Account must not be a Stock type account, please change the Account Type for the account {1} or select a different account" + ).format(d.idx, get_link_to_form("Account", d.expense_account)), + OpeningEntryAccountError, + ) + def validate_warehouse(self): """perform various (sometimes conditional) validations on warehouse""" From 9adb863787418a9fe723fbdadecd22405e224b24 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 5 May 2025 14:12:07 +0530 Subject: [PATCH 2/3] chore: fix linters issue --- erpnext/stock/doctype/stock_entry/stock_entry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index e5d46563e6f..07eee8e8c95 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -9,7 +9,7 @@ import frappe from frappe import _ from frappe.model.mapper import get_mapped_doc from frappe.query_builder.functions import Sum -from frappe.utils import cint, comma_or, cstr, flt, format_time, formatdate, getdate, nowdate +from frappe.utils import cint, comma_or, cstr, flt, format_time, formatdate, getdate, nowdate, get_link_to_form import erpnext from erpnext.accounts.general_ledger import process_gl_map From e743d5f66bc60c32c56fcf92390d061f69d82c73 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 5 May 2025 14:19:20 +0530 Subject: [PATCH 3/3] chore: fix linters issue --- erpnext/stock/doctype/stock_entry/stock_entry.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 07eee8e8c95..90764180217 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -9,7 +9,17 @@ import frappe from frappe import _ from frappe.model.mapper import get_mapped_doc from frappe.query_builder.functions import Sum -from frappe.utils import cint, comma_or, cstr, flt, format_time, formatdate, getdate, nowdate, get_link_to_form +from frappe.utils import ( + cint, + comma_or, + cstr, + flt, + format_time, + formatdate, + get_link_to_form, + getdate, + nowdate, +) import erpnext from erpnext.accounts.general_ledger import process_gl_map