Skip to content

Commit b42e239

Browse files
fix: account change in warehouse (backport #54182) (#54205)
Co-authored-by: nishkagosalia <[email protected]>
1 parent 22774fd commit b42e239

1 file changed

Lines changed: 13 additions & 39 deletions

File tree

erpnext/stock/doctype/warehouse/warehouse.py

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -109,49 +109,23 @@ def on_trash(self):
109109
def warn_about_multiple_warehouse_account(self):
110110
"If Warehouse value is split across multiple accounts, warn."
111111

112-
def get_accounts_where_value_is_booked(name):
113-
sle = frappe.qb.DocType("Stock Ledger Entry")
114-
gle = frappe.qb.DocType("GL Entry")
115-
ac = frappe.qb.DocType("Account")
116-
117-
return (
118-
frappe.qb.from_(sle)
119-
.join(gle)
120-
.on(sle.voucher_no == gle.voucher_no)
121-
.join(ac)
122-
.on(ac.name == gle.account)
123-
.select(gle.account)
124-
.distinct()
125-
.where((sle.warehouse == name) & (ac.account_type == "Stock"))
126-
.orderby(sle.creation)
127-
.run(as_dict=True)
128-
)
129-
130-
if self.is_new():
112+
if not frappe.db.count("Stock Ledger Entry", {"warehouse": self.name}):
131113
return
132114

133-
old_wh_account = frappe.db.get_value("Warehouse", self.name, "account")
115+
doc_before_save = self.get_doc_before_save()
116+
old_wh_account = doc_before_save.account if doc_before_save else None
134117

135-
# WH account is being changed or set get all accounts against which wh value is booked
136-
if self.account != old_wh_account:
137-
accounts = get_accounts_where_value_is_booked(self.name)
138-
accounts = [d.account for d in accounts]
139-
140-
if not accounts or (len(accounts) == 1 and self.account in accounts):
141-
# if same singular account has stock value booked ignore
142-
return
118+
if self.is_new() or (self.account and old_wh_account == self.account):
119+
return
143120

144-
warning = _("Warehouse's Stock Value has already been booked in the following accounts:")
145-
account_str = "<br>" + ", ".join(frappe.bold(ac) for ac in accounts)
146-
reason = "<br><br>" + _(
147-
"Booking stock value across multiple accounts will make it harder to track stock and account value."
148-
)
149-
150-
frappe.msgprint(
151-
warning + account_str + reason,
152-
title=_("Multiple Warehouse Accounts"),
153-
indicator="orange",
154-
)
121+
frappe.msgprint(
122+
title=_("Warning: Account changed for warehouse"),
123+
indicator="orange",
124+
msg=_(
125+
"Stock entries exist with the old account. Changing the account may lead to a mismatch between the warehouse closing balance and the account closing balance. The overall closing balance will still match, but not for the specific account."
126+
),
127+
alert=True,
128+
)
155129

156130
def check_if_sle_exists(self, non_cancelled_only=False):
157131
filters = {"warehouse": self.name}

0 commit comments

Comments
 (0)