Skip to content

Commit

Permalink
fix: timeout error while submitting JV
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Jun 28, 2024
1 parent 80c6981 commit e333f36
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 27 deletions.
5 changes: 3 additions & 2 deletions erpnext/accounts/doctype/account/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@
"label": "Account Type",
"oldfieldname": "account_type",
"oldfieldtype": "Select",
"options": "\nAccumulated Depreciation\nAsset Received But Not Billed\nBank\nCash\nChargeable\nCapital Work in Progress\nCost of Goods Sold\nCurrent Asset\nCurrent Liability\nDepreciation\nDirect Expense\nDirect Income\nEquity\nExpense Account\nExpenses Included In Asset Valuation\nExpenses Included In Valuation\nFixed Asset\nIncome Account\nIndirect Expense\nIndirect Income\nLiability\nPayable\nReceivable\nRound Off\nStock\nStock Adjustment\nStock Received But Not Billed\nService Received But Not Billed\nTax\nTemporary"
"options": "\nAccumulated Depreciation\nAsset Received But Not Billed\nBank\nCash\nChargeable\nCapital Work in Progress\nCost of Goods Sold\nCurrent Asset\nCurrent Liability\nDepreciation\nDirect Expense\nDirect Income\nEquity\nExpense Account\nExpenses Included In Asset Valuation\nExpenses Included In Valuation\nFixed Asset\nIncome Account\nIndirect Expense\nIndirect Income\nLiability\nPayable\nReceivable\nRound Off\nStock\nStock Adjustment\nStock Received But Not Billed\nService Received But Not Billed\nTax\nTemporary",
"search_index": 1
},
{
"description": "Rate at which this tax is applied",
Expand Down Expand Up @@ -193,7 +194,7 @@
"idx": 1,
"is_tree": 1,
"links": [],
"modified": "2024-03-27 13:05:55.866034",
"modified": "2024-06-27 16:23:04.444354",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Account",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_payment_against_sales_order_usd_to_inr(self):

expected_gle = dict(
(d[0], d)
for d in [["_Test Receivable USD - _TC", 0, 5500, so.name], ["Cash - _TC", 5500.0, 0, None]]
for d in [["_Test Receivable USD - _TC", 0, 5500, so.name], [pe.paid_to, 5500.0, 0, None]]
)

self.validate_gl_entries(pe.name, expected_gle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,11 @@ def test_multi_je_unlink_on_invoice_cancellation(self):

@change_settings(
"Accounts Settings",
{"unlink_payment_on_cancellation_of_invoice": 1, "delete_linked_ledger_entries": 1},
{
"unlink_payment_on_cancellation_of_invoice": 1,
"delete_linked_ledger_entries": 1,
"unlink_advance_payment_on_cancelation_of_order": 1,
},
)
def test_advance_payment_unlink_on_order_cancellation(self):
transaction_date = nowdate()
Expand Down
24 changes: 13 additions & 11 deletions erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2220,13 +2220,14 @@ def test_rounding_adjustment_2(self):
self.assertEqual(si.total_taxes_and_charges, 229)
self.assertEqual(si.rounding_adjustment, -0.20)

expected_values = [
["_Test Account Service Tax - _TC", 0.0, 114.50],
["_Test Account VAT - _TC", 0.0, 114.50],
[si.debit_to, 1501, 0.0],
["Round Off - _TC", 0.20, 0.0],
["Sales - _TC", 0.0, 1272.20],
]
round_off_account = frappe.get_cached_value("Company", "_Test Company", "round_off_account")
expected_values = {
"_Test Account Service Tax - _TC": [0.0, 114.50],
"_Test Account VAT - _TC": [0.0, 114.50],
si.debit_to: [1501, 0.0],
round_off_account: [0.20, 0.0],
"Sales - _TC": [0.0, 1272.20],
}

gl_entries = frappe.db.sql(
"""select account, sum(debit) as debit, sum(credit) as credit
Expand All @@ -2238,9 +2239,9 @@ def test_rounding_adjustment_2(self):
)

for i, gle in enumerate(gl_entries):
self.assertEqual(expected_values[i][0], gle.account)
self.assertEqual(expected_values[i][1], gle.debit)
self.assertEqual(expected_values[i][2], gle.credit)
expected_account_values = expected_values[gle.account]
self.assertEqual(expected_account_values[0], gle.debit)
self.assertEqual(expected_account_values[1], gle.credit)

def test_rounding_adjustment_3(self):
from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import (
Expand Down Expand Up @@ -2289,14 +2290,15 @@ def test_rounding_adjustment_3(self):
self.assertEqual(si.total_taxes_and_charges, 480.86)
self.assertEqual(si.rounding_adjustment, -0.02)

round_off_account = frappe.get_cached_value("Company", "_Test Company", "round_off_account")
expected_values = dict(
(d[0], d)
for d in [
[si.debit_to, 4488.0, 0.0],
["_Test Account Service Tax - _TC", 0.0, 240.43],
["_Test Account VAT - _TC", 0.0, 240.43],
["Sales - _TC", 0.0, 4007.15],
["Round Off - _TC", 0.01, 0.0],
[round_off_account, 0.01, 0.0],
]
)

Expand Down
33 changes: 24 additions & 9 deletions erpnext/accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from frappe import _, qb, throw
from frappe.model.meta import get_field_precision
from frappe.query_builder import AliasedQuery, Criterion, Table
from frappe.query_builder.functions import Round, Sum
from frappe.query_builder.functions import Count, Round, Sum
from frappe.query_builder.utils import DocType
from frappe.utils import (
add_days,
Expand Down Expand Up @@ -1508,24 +1508,39 @@ def get_stock_accounts(company, voucher_type=None, voucher_no=None):
)
]

return stock_accounts
return list(set(stock_accounts))


def get_stock_and_account_balance(account=None, posting_date=None, company=None):
if not posting_date:
posting_date = nowdate()

warehouse_account = get_warehouse_account_map(company)

account_balance = get_balance_on(
account, posting_date, in_account_currency=False, ignore_account_permission=True
)

related_warehouses = [
wh
for wh, wh_details in warehouse_account.items()
if wh_details.account == account and not wh_details.is_group
]
account_table = frappe.qb.DocType("Account")
query = (
frappe.qb.from_(account_table)
.select(Count(account_table.name))
.where(
(account_table.account_type == "Stock")
& (account_table.company == company)
& (account_table.is_group == 0)
)
)

no_of_stock_accounts = cint(query.run()[0][0])

related_warehouses = []
if no_of_stock_accounts > 1:
warehouse_account = get_warehouse_account_map(company)

related_warehouses = [
wh
for wh, wh_details in warehouse_account.items()
if wh_details.account == account and not wh_details.is_group
]

total_stock_value = get_stock_value_on(related_warehouses, posting_date)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"oldfieldtype": "Date",
"print_width": "100px",
"read_only": 1,
"search_index": 1,
"width": "100px"
},
{
Expand Down Expand Up @@ -360,7 +361,7 @@
"in_create": 1,
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-03-27 13:10:44.486742",
"modified": "2024-06-27 16:23:18.820049",
"modified_by": "Administrator",
"module": "Stock",
"name": "Stock Ledger Entry",
Expand Down
2 changes: 0 additions & 2 deletions erpnext/stock/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ def get_stock_value_on(
frappe.qb.from_(sle)
.select(IfNull(Sum(sle.stock_value_difference), 0))
.where((sle.posting_date <= posting_date) & (sle.is_cancelled == 0))
.orderby(CombineDatetime(sle.posting_date, sle.posting_time), order=frappe.qb.desc)
.orderby(sle.creation, order=frappe.qb.desc)
)

if warehouses:
Expand Down

0 comments on commit e333f36

Please sign in to comment.