fix: get stock balance filtered by company for validating stock value in jv (backport #45549) (#45578)

* 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

(cherry picked from commit 9f20854bd9)

* fix: correct args for test case function

---------

Co-authored-by: Lakshit Jain <108322669+ljain112@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: ljain112 <ljain112@gmail.com>
This commit is contained in:
mergify[bot]
2025-01-29 15:39:30 +05:30
committed by GitHub
parent a2ffdc7805
commit ef2f4118d9
4 changed files with 11 additions and 8 deletions

View File

@@ -146,10 +146,9 @@ class TestJournalEntry(unittest.TestCase):
"credit_in_account_currency": 0 if diff > 0 else abs(diff), "credit_in_account_currency": 0 if diff > 0 else abs(diff),
}, },
) )
jv.insert()
if account_bal == stock_bal: if account_bal == stock_bal:
self.assertRaises(StockAccountInvalidTransaction, jv.submit) self.assertRaises(StockAccountInvalidTransaction, jv.save)
frappe.db.rollback() frappe.db.rollback()
else: else:
jv.submit() jv.submit()

View File

@@ -83,8 +83,7 @@ class TestPaymentRequest(FrappeTestCase):
def test_payment_entry_against_purchase_invoice(self): def test_payment_entry_against_purchase_invoice(self):
si_usd = make_purchase_invoice( si_usd = make_purchase_invoice(
customer="_Test Supplier USD", supplier="_Test Supplier USD",
debit_to="_Test Payable USD - _TC",
currency="USD", currency="USD",
conversion_rate=50, conversion_rate=50,
) )
@@ -108,8 +107,7 @@ class TestPaymentRequest(FrappeTestCase):
def test_multiple_payment_entry_against_purchase_invoice(self): def test_multiple_payment_entry_against_purchase_invoice(self):
purchase_invoice = make_purchase_invoice( purchase_invoice = make_purchase_invoice(
customer="_Test Supplier USD", supplier="_Test Supplier USD",
debit_to="_Test Payable USD - _TC",
currency="USD", currency="USD",
conversion_rate=50, conversion_rate=50,
) )

View File

@@ -1644,7 +1644,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 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") precision = frappe.get_precision("Journal Entry Account", "debit_in_account_currency")
return flt(account_balance, precision), flt(total_stock_value, precision), related_warehouses return flt(account_balance, precision), flt(total_stock_value, precision), related_warehouses

View File

@@ -58,7 +58,10 @@ def get_stock_value_from_bin(warehouse=None, item_code=None):
def get_stock_value_on( 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: ) -> float:
if not posting_date: if not posting_date:
posting_date = nowdate() posting_date = nowdate()
@@ -84,6 +87,9 @@ def get_stock_value_on(
if item_code: if item_code:
query = query.where(sle.item_code == 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] return query.run(as_list=True)[0][0]