mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-16 16:15:02 +00:00
fix: get stock balance filtered by company for validating stock value in jv (#45549)
* fix: get stock balance filtered by company for validating stock value in jv * test: error is raised on validate
This commit is contained in:
@@ -154,10 +154,9 @@ class TestJournalEntry(IntegrationTestCase):
|
||||
"credit_in_account_currency": 0 if diff > 0 else abs(diff),
|
||||
},
|
||||
)
|
||||
jv.insert()
|
||||
|
||||
if account_bal == stock_bal:
|
||||
self.assertRaises(StockAccountInvalidTransaction, jv.submit)
|
||||
self.assertRaises(StockAccountInvalidTransaction, jv.save)
|
||||
frappe.db.rollback()
|
||||
else:
|
||||
jv.submit()
|
||||
|
||||
@@ -1678,7 +1678,7 @@ def get_stock_and_account_balance(account=None, posting_date=None, company=None)
|
||||
if wh_details.account == account and not wh_details.is_group
|
||||
]
|
||||
|
||||
total_stock_value = get_stock_value_on(related_warehouses, posting_date)
|
||||
total_stock_value = get_stock_value_on(related_warehouses, posting_date, company=company)
|
||||
|
||||
precision = frappe.get_precision("Journal Entry Account", "debit_in_account_currency")
|
||||
return flt(account_balance, precision), flt(total_stock_value, precision), related_warehouses
|
||||
|
||||
@@ -58,7 +58,10 @@ def get_stock_value_from_bin(warehouse=None, item_code=None):
|
||||
|
||||
|
||||
def get_stock_value_on(
|
||||
warehouses: list | str | None = None, posting_date: str | None = None, item_code: str | None = None
|
||||
warehouses: list | str | None = None,
|
||||
posting_date: str | None = None,
|
||||
item_code: str | None = None,
|
||||
company: str | None = None,
|
||||
) -> float:
|
||||
if not posting_date:
|
||||
posting_date = nowdate()
|
||||
@@ -84,6 +87,9 @@ def get_stock_value_on(
|
||||
if item_code:
|
||||
query = query.where(sle.item_code == item_code)
|
||||
|
||||
if company:
|
||||
query = query.where(sle.company == company)
|
||||
|
||||
return query.run(as_list=True)[0][0]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user