mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-19 06:45:11 +00:00
Co-authored-by: nishkagosalia <nishka.gosalia@gmail.com>
This commit is contained in:
@@ -101,49 +101,23 @@ class Warehouse(NestedSet):
|
|||||||
def warn_about_multiple_warehouse_account(self):
|
def warn_about_multiple_warehouse_account(self):
|
||||||
"If Warehouse value is split across multiple accounts, warn."
|
"If Warehouse value is split across multiple accounts, warn."
|
||||||
|
|
||||||
def get_accounts_where_value_is_booked(name):
|
if not frappe.db.count("Stock Ledger Entry", {"warehouse": self.name}):
|
||||||
sle = frappe.qb.DocType("Stock Ledger Entry")
|
|
||||||
gle = frappe.qb.DocType("GL Entry")
|
|
||||||
ac = frappe.qb.DocType("Account")
|
|
||||||
|
|
||||||
return (
|
|
||||||
frappe.qb.from_(sle)
|
|
||||||
.join(gle)
|
|
||||||
.on(sle.voucher_no == gle.voucher_no)
|
|
||||||
.join(ac)
|
|
||||||
.on(ac.name == gle.account)
|
|
||||||
.select(gle.account)
|
|
||||||
.distinct()
|
|
||||||
.where((sle.warehouse == name) & (ac.account_type == "Stock"))
|
|
||||||
.orderby(sle.creation)
|
|
||||||
.run(as_dict=True)
|
|
||||||
)
|
|
||||||
|
|
||||||
if self.is_new():
|
|
||||||
return
|
return
|
||||||
|
|
||||||
old_wh_account = frappe.db.get_value("Warehouse", self.name, "account")
|
doc_before_save = self.get_doc_before_save()
|
||||||
|
old_wh_account = doc_before_save.account if doc_before_save else None
|
||||||
|
|
||||||
# WH account is being changed or set get all accounts against which wh value is booked
|
if self.is_new() or (self.account and old_wh_account == self.account):
|
||||||
if self.account != old_wh_account:
|
return
|
||||||
accounts = get_accounts_where_value_is_booked(self.name)
|
|
||||||
accounts = [d.account for d in accounts]
|
|
||||||
|
|
||||||
if not accounts or (len(accounts) == 1 and self.account in accounts):
|
frappe.msgprint(
|
||||||
# if same singular account has stock value booked ignore
|
title=_("Warning: Account changed for warehouse"),
|
||||||
return
|
indicator="orange",
|
||||||
|
msg=_(
|
||||||
warning = _("Warehouse's Stock Value has already been booked in the following accounts:")
|
"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."
|
||||||
account_str = "<br>" + ", ".join(frappe.bold(ac) for ac in accounts)
|
),
|
||||||
reason = "<br><br>" + _(
|
alert=True,
|
||||||
"Booking stock value across multiple accounts will make it harder to track stock and account value."
|
)
|
||||||
)
|
|
||||||
|
|
||||||
frappe.msgprint(
|
|
||||||
warning + account_str + reason,
|
|
||||||
title=_("Multiple Warehouse Accounts"),
|
|
||||||
indicator="orange",
|
|
||||||
)
|
|
||||||
|
|
||||||
def check_if_sle_exists(self):
|
def check_if_sle_exists(self):
|
||||||
return frappe.db.exists("Stock Ledger Entry", {"warehouse": self.name})
|
return frappe.db.exists("Stock Ledger Entry", {"warehouse": self.name})
|
||||||
|
|||||||
Reference in New Issue
Block a user