From e43bc38e05349a780e0a4a97812cebea4a90a109 Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Wed, 19 Apr 2023 12:05:17 +0530 Subject: [PATCH 01/40] refactor: rewrite `get_stock_value_on()` queries in `QB` --- erpnext/stock/utils.py | 49 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index b8c5187b2c..d928dca723 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -9,6 +9,7 @@ import frappe from frappe import _ from frappe.query_builder.functions import CombineDatetime from frappe.utils import cstr, flt, get_link_to_form, nowdate, nowtime +from pypika.terms import ExistsCriterion import erpnext from erpnext.stock.valuation import FIFOValuation, LIFOValuation @@ -57,39 +58,39 @@ def get_stock_value_on(warehouse=None, posting_date=None, item_code=None): if not posting_date: posting_date = nowdate() - values, condition = [posting_date], "" + sle = frappe.qb.DocType("Stock Ledger Entry") + query = ( + frappe.qb.from_(sle) + .select( + sle.item_code, + sle.stock_value, + sle.name, + sle.warehouse, + ) + .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 warehouse: - lft, rgt, is_group = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt", "is_group"]) if is_group: - values.extend([lft, rgt]) - condition += "and exists (\ - select name from `tabWarehouse` wh where wh.name = sle.warehouse\ - and wh.lft >= %s and wh.rgt <= %s)" - + wh = frappe.qb.DocType("Warehouse") + query = query.where( + ExistsCriterion( + frappe.qb.from_(wh) + .select(wh.name) + .where((wh.name == sle.warehouse) & (wh.lft >= lft) & (wh.rgt <= rgt)) + ) + ) else: - values.append(warehouse) - condition += " AND warehouse = %s" + query = query.where(sle.warehouse == warehouse) if item_code: - values.append(item_code) - condition += " AND item_code = %s" + query = query.where(sle.item_code == item_code) - stock_ledger_entries = frappe.db.sql( - """ - SELECT item_code, stock_value, name, warehouse - FROM `tabStock Ledger Entry` sle - WHERE posting_date <= %s {0} - and is_cancelled = 0 - ORDER BY timestamp(posting_date, posting_time) DESC, creation DESC - """.format( - condition - ), - values, - as_dict=1, - ) + stock_ledger_entries = query.run(as_dict=True) sle_map = {} for sle in stock_ledger_entries: From 9a37ac6c2563f8f6459c5c47a95ef349a9fc10bf Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Fri, 21 Apr 2023 13:28:14 +0530 Subject: [PATCH 02/40] refactor: sum up SLE value in query --- erpnext/stock/utils.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index d928dca723..9c2e2c805b 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -7,7 +7,7 @@ from typing import Dict, Optional import frappe from frappe import _ -from frappe.query_builder.functions import CombineDatetime +from frappe.query_builder.functions import CombineDatetime, IfNull, Sum from frappe.utils import cstr, flt, get_link_to_form, nowdate, nowtime from pypika.terms import ExistsCriterion @@ -61,12 +61,7 @@ def get_stock_value_on(warehouse=None, posting_date=None, item_code=None): sle = frappe.qb.DocType("Stock Ledger Entry") query = ( frappe.qb.from_(sle) - .select( - sle.item_code, - sle.stock_value, - sle.name, - sle.warehouse, - ) + .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) @@ -90,14 +85,7 @@ def get_stock_value_on(warehouse=None, posting_date=None, item_code=None): if item_code: query = query.where(sle.item_code == item_code) - stock_ledger_entries = query.run(as_dict=True) - - sle_map = {} - for sle in stock_ledger_entries: - if not (sle.item_code, sle.warehouse) in sle_map: - sle_map[(sle.item_code, sle.warehouse)] = flt(sle.stock_value) - - return sum(sle_map.values()) + return query.run(as_list=True)[0][0] @frappe.whitelist() From cb7a99cbaa2caa9746a49dd09c2c2bdea5ba1540 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 21 Apr 2023 12:59:52 +0530 Subject: [PATCH 03/40] Revert "fix: Rate from LDC in TDS reports (#33699)" This reverts commit db9beb3cddc78376ccd30b57efafa35381b482d6. --- .../report/tds_payable_monthly/tds_payable_monthly.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.py b/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.py index bfe2a0fd2b..98838907be 100644 --- a/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.py +++ b/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.py @@ -4,7 +4,6 @@ import frappe from frappe import _ -from frappe.utils import flt def execute(filters=None): @@ -66,12 +65,6 @@ def get_result( else: total_amount_credited += entry.credit - ## Check if ldc is applied and show rate as per ldc - actual_rate = (tds_deducted / total_amount_credited) * 100 - - if flt(actual_rate) < flt(rate): - rate = actual_rate - if tds_deducted: row = { "pan" From 7a63fbef4fcb0f57e5ec38f7900c6905cfe3954b Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Tue, 25 Apr 2023 12:01:26 +0530 Subject: [PATCH 04/40] =?UTF-8?q?Revert=20"fix:=20Incorrect=20difference?= =?UTF-8?q?=20value=20in=20Stock=20and=20Account=20Value=20Comparison?= =?UTF-8?q?=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stock_and_account_value_comparison.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.py b/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.py index 5fb456502e..106e877c4c 100644 --- a/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.py +++ b/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.py @@ -41,7 +41,7 @@ def get_data(report_filters): key = (d.voucher_type, d.voucher_no) gl_data = voucher_wise_gl_data.get(key) or {} d.account_value = gl_data.get("account_value", 0) - d.difference_value = abs(d.stock_value) - abs(d.account_value) + d.difference_value = d.stock_value - d.account_value if abs(d.difference_value) > 0.1: data.append(d) From ca388ed9cdc05a8797b9812989e88d5cdaf1a811 Mon Sep 17 00:00:00 2001 From: Anand Baburajan Date: Tue, 25 Apr 2023 12:45:05 +0530 Subject: [PATCH 05/40] fix: value of depreciable assets not updating after manual depr entry [develop] (#35020) * fix: value of depreciable assets not updating after manual depr entry * chore: add asset depr schedule to jv's ignore_doctypes_on_cancel_all --- .../accounts/doctype/account/test_account.py | 2 +- .../doctype/journal_entry/journal_entry.js | 2 +- .../doctype/journal_entry/journal_entry.py | 72 ++++++++++++------- .../asset_depreciations_and_balances.py | 24 +------ erpnext/assets/doctype/asset/depreciation.py | 1 + erpnext/assets/doctype/asset/test_asset.py | 62 +++++++++++++++- 6 files changed, 108 insertions(+), 55 deletions(-) diff --git a/erpnext/accounts/doctype/account/test_account.py b/erpnext/accounts/doctype/account/test_account.py index f9c9173af0..3a360c48c4 100644 --- a/erpnext/accounts/doctype/account/test_account.py +++ b/erpnext/accounts/doctype/account/test_account.py @@ -297,7 +297,7 @@ def _make_test_records(verbose=None): # fixed asset depreciation ["_Test Fixed Asset", "Current Assets", 0, "Fixed Asset", None], ["_Test Accumulated Depreciations", "Current Assets", 0, "Accumulated Depreciation", None], - ["_Test Depreciations", "Expenses", 0, None, None], + ["_Test Depreciations", "Expenses", 0, "Depreciation", None], ["_Test Gain/Loss on Asset Disposal", "Expenses", 0, None, None], # Receivable / Payable Account ["_Test Receivable", "Current Assets", 0, "Receivable", None], diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index 089f20b467..b31cc3212e 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -8,7 +8,7 @@ frappe.provide("erpnext.journal_entry"); frappe.ui.form.on("Journal Entry", { setup: function(frm) { frm.add_fetch("bank_account", "account", "account"); - frm.ignore_doctypes_on_cancel_all = ['Sales Invoice', 'Purchase Invoice', 'Journal Entry', "Repost Payment Ledger"]; + frm.ignore_doctypes_on_cancel_all = ['Sales Invoice', 'Purchase Invoice', 'Journal Entry', "Repost Payment Ledger", 'Asset Depreciation Schedule']; }, refresh: function(frm) { diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 0f8ae4f37d..34a753f267 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -69,6 +69,7 @@ class JournalEntry(AccountsController): self.validate_empty_accounts_table() self.set_account_and_party_balance() self.validate_inter_company_accounts() + self.validate_depr_entry_voucher_type() if self.docstatus == 0: self.apply_tax_withholding() @@ -130,6 +131,13 @@ class JournalEntry(AccountsController): if self.total_credit != doc.total_debit or self.total_debit != doc.total_credit: frappe.throw(_("Total Credit/ Debit Amount should be same as linked Journal Entry")) + def validate_depr_entry_voucher_type(self): + if ( + any(d.account_type == "Depreciation" for d in self.get("accounts")) + and self.voucher_type != "Depreciation Entry" + ): + frappe.throw(_("Journal Entry type should be set as Depreciation Entry for asset depreciation")) + def validate_stock_accounts(self): stock_accounts = get_stock_accounts(self.company, self.doctype, self.name) for account in stock_accounts: @@ -233,25 +241,30 @@ class JournalEntry(AccountsController): self.remove(d) def update_asset_value(self): - if self.voucher_type != "Depreciation Entry": + if self.flags.planned_depr_entry or self.voucher_type != "Depreciation Entry": return - processed_assets = [] - for d in self.get("accounts"): if ( - d.reference_type == "Asset" and d.reference_name and d.reference_name not in processed_assets + d.reference_type == "Asset" + and d.reference_name + and d.account_type == "Depreciation" + and d.debit ): - processed_assets.append(d.reference_name) - asset = frappe.get_doc("Asset", d.reference_name) if asset.calculate_depreciation: - continue - - depr_value = d.debit or d.credit - - asset.db_set("value_after_depreciation", asset.value_after_depreciation - depr_value) + fb_idx = 1 + if self.finance_book: + for fb_row in asset.get("finance_books"): + if fb_row.finance_book == self.finance_book: + fb_idx = fb_row.idx + break + fb_row = asset.get("finance_books")[fb_idx - 1] + fb_row.value_after_depreciation -= d.debit + fb_row.db_update() + else: + asset.db_set("value_after_depreciation", asset.value_after_depreciation - d.debit) asset.set_status() @@ -316,42 +329,47 @@ class JournalEntry(AccountsController): if self.voucher_type != "Depreciation Entry": return - processed_assets = [] - for d in self.get("accounts"): if ( - d.reference_type == "Asset" and d.reference_name and d.reference_name not in processed_assets + d.reference_type == "Asset" + and d.reference_name + and d.account_type == "Depreciation" + and d.debit ): - processed_assets.append(d.reference_name) - asset = frappe.get_doc("Asset", d.reference_name) if asset.calculate_depreciation: je_found = False - for row in asset.get("finance_books"): + for fb_row in asset.get("finance_books"): if je_found: break - depr_schedule = get_depr_schedule(asset.name, "Active", row.finance_book) + depr_schedule = get_depr_schedule(asset.name, "Active", fb_row.finance_book) for s in depr_schedule or []: if s.journal_entry == self.name: s.db_set("journal_entry", None) - row.value_after_depreciation += s.depreciation_amount - row.db_update() - - asset.set_status() + fb_row.value_after_depreciation += d.debit + fb_row.db_update() je_found = True break + if not je_found: + fb_idx = 1 + if self.finance_book: + for fb_row in asset.get("finance_books"): + if fb_row.finance_book == self.finance_book: + fb_idx = fb_row.idx + break + + fb_row = asset.get("finance_books")[fb_idx - 1] + fb_row.value_after_depreciation += d.debit + fb_row.db_update() else: - depr_value = d.debit or d.credit - - asset.db_set("value_after_depreciation", asset.value_after_depreciation + depr_value) - - asset.set_status() + asset.db_set("value_after_depreciation", asset.value_after_depreciation + d.debit) + asset.set_status() def unlink_inter_company_jv(self): if ( diff --git a/erpnext/accounts/report/asset_depreciations_and_balances/asset_depreciations_and_balances.py b/erpnext/accounts/report/asset_depreciations_and_balances/asset_depreciations_and_balances.py index 5827697023..d67eee3552 100644 --- a/erpnext/accounts/report/asset_depreciations_and_balances/asset_depreciations_and_balances.py +++ b/erpnext/accounts/report/asset_depreciations_and_balances/asset_depreciations_and_balances.py @@ -114,28 +114,6 @@ def get_assets(filters): sum(results.depreciation_eliminated_during_the_period) as depreciation_eliminated_during_the_period, sum(results.depreciation_amount_during_the_period) as depreciation_amount_during_the_period from (SELECT a.asset_category, - ifnull(sum(case when ds.schedule_date < %(from_date)s and (ifnull(a.disposal_date, 0) = 0 or a.disposal_date >= %(from_date)s) then - ds.depreciation_amount - else - 0 - end), 0) as accumulated_depreciation_as_on_from_date, - ifnull(sum(case when ifnull(a.disposal_date, 0) != 0 and a.disposal_date >= %(from_date)s - and a.disposal_date <= %(to_date)s and ds.schedule_date <= a.disposal_date then - ds.depreciation_amount - else - 0 - end), 0) as depreciation_eliminated_during_the_period, - ifnull(sum(case when ds.schedule_date >= %(from_date)s and ds.schedule_date <= %(to_date)s - and (ifnull(a.disposal_date, 0) = 0 or ds.schedule_date <= a.disposal_date) then - ds.depreciation_amount - else - 0 - end), 0) as depreciation_amount_during_the_period - from `tabAsset` a, `tabAsset Depreciation Schedule` ads, `tabDepreciation Schedule` ds - where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s and ads.asset = a.name and ads.docstatus=1 and ads.name = ds.parent and ifnull(ds.journal_entry, '') != '' - group by a.asset_category - union - SELECT a.asset_category, ifnull(sum(case when gle.posting_date < %(from_date)s and (ifnull(a.disposal_date, 0) = 0 or a.disposal_date >= %(from_date)s) then gle.debit else @@ -160,7 +138,7 @@ def get_assets(filters): aca.parent = a.asset_category and aca.company_name = %(company)s join `tabCompany` company on company.name = %(company)s - where a.docstatus=1 and a.company=%(company)s and a.calculate_depreciation=0 and a.purchase_date <= %(to_date)s and gle.debit != 0 and gle.is_cancelled = 0 and gle.account = ifnull(aca.depreciation_expense_account, company.depreciation_expense_account) + where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s and gle.debit != 0 and gle.is_cancelled = 0 and gle.account = ifnull(aca.depreciation_expense_account, company.depreciation_expense_account) group by a.asset_category union SELECT a.asset_category, diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py index 028e3d6268..f23ae2f165 100644 --- a/erpnext/assets/doctype/asset/depreciation.py +++ b/erpnext/assets/doctype/asset/depreciation.py @@ -157,6 +157,7 @@ def make_depreciation_entry(asset_depr_schedule_name, date=None): je.append("accounts", debit_entry) je.flags.ignore_permissions = True + je.flags.planned_depr_entry = True je.save() if not je.meta.get_workflow(): je.submit() diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index cde02809f1..203612ff1b 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -1511,7 +1511,7 @@ class TestDepreciationBasics(AssetSetup): ) self.assertEqual(asset.status, "Submitted") - self.assertEqual(asset.get("value_after_depreciation"), 100000) + self.assertEqual(asset.get_value_after_depreciation(), 100000) jv = make_journal_entry( "_Test Depreciations - _TC", "_Test Accumulated Depreciations - _TC", 100, save=False @@ -1524,12 +1524,68 @@ class TestDepreciationBasics(AssetSetup): jv.submit() asset.reload() - self.assertEqual(asset.get("value_after_depreciation"), 99900) + self.assertEqual(asset.get_value_after_depreciation(), 99900) jv.cancel() asset.reload() - self.assertEqual(asset.get("value_after_depreciation"), 100000) + self.assertEqual(asset.get_value_after_depreciation(), 100000) + + def test_manual_depreciation_for_depreciable_asset(self): + asset = create_asset( + item_code="Macbook Pro", + calculate_depreciation=1, + purchase_date="2020-01-30", + available_for_use_date="2020-01-30", + expected_value_after_useful_life=10000, + total_number_of_depreciations=10, + frequency_of_depreciation=1, + submit=1, + ) + + self.assertEqual(asset.status, "Submitted") + self.assertEqual(asset.get_value_after_depreciation(), 100000) + + jv = make_journal_entry( + "_Test Depreciations - _TC", "_Test Accumulated Depreciations - _TC", 100, save=False + ) + for d in jv.accounts: + d.reference_type = "Asset" + d.reference_name = asset.name + jv.voucher_type = "Depreciation Entry" + jv.insert() + jv.submit() + + asset.reload() + self.assertEqual(asset.get_value_after_depreciation(), 99900) + + jv.cancel() + + asset.reload() + self.assertEqual(asset.get_value_after_depreciation(), 100000) + + def test_manual_depreciation_with_incorrect_jv_voucher_type(self): + asset = create_asset( + item_code="Macbook Pro", + calculate_depreciation=1, + purchase_date="2020-01-30", + available_for_use_date="2020-01-30", + expected_value_after_useful_life=10000, + total_number_of_depreciations=10, + frequency_of_depreciation=1, + submit=1, + ) + + jv = make_journal_entry( + "_Test Depreciations - _TC", "_Test Accumulated Depreciations - _TC", 100, save=False + ) + for d in jv.accounts: + d.reference_type = "Asset" + d.reference_name = asset.name + d.account_type = "Depreciation" + jv.voucher_type = "Journal Entry" + + self.assertRaises(frappe.ValidationError, jv.insert) def create_asset_data(): From e782a054c80656f378da6108bdd91fae99de685e Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Tue, 25 Apr 2023 13:54:36 +0530 Subject: [PATCH 06/40] refactor: `get_stock_value_on()` to get stock value of multiple warehouses at once --- erpnext/accounts/utils.py | 5 +--- .../incorrect_stock_value_report.py | 2 +- erpnext/stock/utils.py | 28 +++++++++---------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 2ab9ef64b3..015bce5547 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -1368,10 +1368,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 = 0.0 - for warehouse in related_warehouses: - value = get_stock_value_on(warehouse, posting_date) - total_stock_value += value + total_stock_value = get_stock_value_on(related_warehouses, posting_date) precision = frappe.get_precision("Journal Entry Account", "debit_in_account_currency") return flt(account_balance, precision), flt(total_stock_value, precision), related_warehouses diff --git a/erpnext/stock/report/incorrect_stock_value_report/incorrect_stock_value_report.py b/erpnext/stock/report/incorrect_stock_value_report/incorrect_stock_value_report.py index df01b14d11..16ff5278e7 100644 --- a/erpnext/stock/report/incorrect_stock_value_report/incorrect_stock_value_report.py +++ b/erpnext/stock/report/incorrect_stock_value_report/incorrect_stock_value_report.py @@ -84,7 +84,7 @@ def get_data(report_filters): closing_date = add_days(from_date, -1) for key, stock_data in voucher_wise_dict.items(): prev_stock_value = get_stock_value_on( - posting_date=closing_date, item_code=key[0], warehouse=key[1] + posting_date=closing_date, item_code=key[0], warehouses=key[1] ) for data in stock_data: expected_stock_value = prev_stock_value + data.stock_value_difference diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index 9c2e2c805b..fb526971ed 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -9,9 +9,9 @@ import frappe from frappe import _ from frappe.query_builder.functions import CombineDatetime, IfNull, Sum from frappe.utils import cstr, flt, get_link_to_form, nowdate, nowtime -from pypika.terms import ExistsCriterion import erpnext +from erpnext.stock.doctype.warehouse.warehouse import get_child_warehouses from erpnext.stock.valuation import FIFOValuation, LIFOValuation BarcodeScanResult = Dict[str, Optional[str]] @@ -54,7 +54,9 @@ def get_stock_value_from_bin(warehouse=None, item_code=None): return stock_value -def get_stock_value_on(warehouse=None, posting_date=None, item_code=None): +def get_stock_value_on( + warehouses: list | str = None, posting_date: str = None, item_code: str = None +) -> float: if not posting_date: posting_date = nowdate() @@ -67,20 +69,16 @@ def get_stock_value_on(warehouse=None, posting_date=None, item_code=None): .orderby(sle.creation, order=frappe.qb.desc) ) - if warehouse: - lft, rgt, is_group = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt", "is_group"]) + if warehouses: + if isinstance(warehouses, str): + warehouses = [warehouses] - if is_group: - wh = frappe.qb.DocType("Warehouse") - query = query.where( - ExistsCriterion( - frappe.qb.from_(wh) - .select(wh.name) - .where((wh.name == sle.warehouse) & (wh.lft >= lft) & (wh.rgt <= rgt)) - ) - ) - else: - query = query.where(sle.warehouse == warehouse) + warehouses = set(warehouses) + for wh in list(warehouses): + if frappe.db.get_value("Warehouse", wh, "is_group"): + warehouses.update(get_child_warehouses(wh)) + + query = query.where(sle.warehouse.isin(warehouses)) if item_code: query = query.where(sle.item_code == item_code) From e08d636bf7979356f60301260177e57213e84fd7 Mon Sep 17 00:00:00 2001 From: Anand Baburajan Date: Tue, 25 Apr 2023 15:16:50 +0530 Subject: [PATCH 07/40] fix: use filter_by_finance_book instead of only_depreciable_assets in fixed asset register (#35031) fix: use filter_by_finance_book instead of only_depreciable_assets --- .../report/fixed_asset_register/fixed_asset_register.js | 6 +++--- .../report/fixed_asset_register/fixed_asset_register.py | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/erpnext/assets/report/fixed_asset_register/fixed_asset_register.js b/erpnext/assets/report/fixed_asset_register/fixed_asset_register.js index 65a4226ebd..4f7b836107 100644 --- a/erpnext/assets/report/fixed_asset_register/fixed_asset_register.js +++ b/erpnext/assets/report/fixed_asset_register/fixed_asset_register.js @@ -94,11 +94,11 @@ frappe.query_reports["Fixed Asset Register"] = { label: __("Finance Book"), fieldtype: "Link", options: "Finance Book", - depends_on: "eval: doc.only_depreciable_assets == 1", + depends_on: "eval: doc.filter_by_finance_book == 1", }, { - fieldname:"only_depreciable_assets", - label: __("Only depreciable assets"), + fieldname:"filter_by_finance_book", + label: __("Filter by Finance Book"), fieldtype: "Check" }, { diff --git a/erpnext/assets/report/fixed_asset_register/fixed_asset_register.py b/erpnext/assets/report/fixed_asset_register/fixed_asset_register.py index 5fbcbe2f7f..984b3fd982 100644 --- a/erpnext/assets/report/fixed_asset_register/fixed_asset_register.py +++ b/erpnext/assets/report/fixed_asset_register/fixed_asset_register.py @@ -45,8 +45,6 @@ def get_conditions(filters): filters.year_end_date = getdate(fiscal_year.year_end_date) conditions[date_field] = ["between", [filters.year_start_date, filters.year_end_date]] - if filters.get("only_depreciable_assets"): - conditions["calculate_depreciation"] = filters.get("only_depreciable_assets") if filters.get("only_existing_assets"): conditions["is_existing_asset"] = filters.get("only_existing_assets") if filters.get("asset_category"): @@ -106,7 +104,7 @@ def get_data(filters): assets_linked_to_fb = None - if filters.only_depreciable_assets: + if filters.filter_by_finance_book: assets_linked_to_fb = frappe.db.get_all( doctype="Asset Finance Book", filters={"finance_book": filters.finance_book or ("is", "not set")}, From 6de71eb15857291295921df984c59d4d871eb9f0 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 25 Apr 2023 18:33:31 +0530 Subject: [PATCH 08/40] fix: pass reference_doctype in link queries (#35038) --- erpnext/controllers/queries.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index b0cf724166..799fed99cc 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -576,7 +576,9 @@ def get_income_account(doctype, txt, searchfield, start, page_len, filters): @frappe.whitelist() @frappe.validate_and_sanitize_search_inputs -def get_filtered_dimensions(doctype, txt, searchfield, start, page_len, filters): +def get_filtered_dimensions( + doctype, txt, searchfield, start, page_len, filters, reference_doctype=None +): from erpnext.accounts.doctype.accounting_dimension_filter.accounting_dimension_filter import ( get_dimension_filter_map, ) @@ -617,7 +619,12 @@ def get_filtered_dimensions(doctype, txt, searchfield, start, page_len, filters) query_filters.append(["name", query_selector, dimensions]) output = frappe.get_list( - doctype, fields=fields, filters=query_filters, or_filters=or_filters, as_list=1 + doctype, + fields=fields, + filters=query_filters, + or_filters=or_filters, + as_list=1, + reference_doctype=reference_doctype, ) return [tuple(d) for d in set(output)] From b545e3def01fb9b9dd6b964478efcb7d764ce386 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 25 Apr 2023 19:07:45 +0530 Subject: [PATCH 09/40] fix: Add company field to lower deduction certificate (#34914) --- .../tax_withholding_category.py | 5 +++-- erpnext/patches.txt | 1 + erpnext/patches/v14_0/update_company_in_ldc.py | 14 ++++++++++++++ .../lower_deduction_certificate.json | 11 ++++++++++- 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 erpnext/patches/v14_0/update_company_in_ldc.py diff --git a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py index f0146ea70e..ad3477ef3d 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py @@ -215,7 +215,7 @@ def get_tax_row_for_tds(tax_details, tax_amount): } -def get_lower_deduction_certificate(tax_details, pan_no): +def get_lower_deduction_certificate(company, tax_details, pan_no): ldc_name = frappe.db.get_value( "Lower Deduction Certificate", { @@ -223,6 +223,7 @@ def get_lower_deduction_certificate(tax_details, pan_no): "tax_withholding_category": tax_details.tax_withholding_category, "valid_from": (">=", tax_details.from_date), "valid_upto": ("<=", tax_details.to_date), + "company": company, }, "name", ) @@ -255,7 +256,7 @@ def get_tax_amount(party_type, parties, inv, tax_details, posting_date, pan_no=N tax_amount = 0 if party_type == "Supplier": - ldc = get_lower_deduction_certificate(tax_details, pan_no) + ldc = get_lower_deduction_certificate(inv.company, tax_details, pan_no) if tax_deducted: net_total = inv.tax_withholding_net_total if ldc: diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 74c8af1f0c..03c7b01856 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -332,3 +332,4 @@ execute:frappe.db.set_single_value("Accounts Settings", "merge_similar_account_h erpnext.patches.v14_0.migrate_gl_to_payment_ledger execute:frappe.delete_doc_if_exists("Report", "Tax Detail") erpnext.patches.v15_0.enable_all_leads +erpnext.patches.v14_0.update_company_in_ldc diff --git a/erpnext/patches/v14_0/update_company_in_ldc.py b/erpnext/patches/v14_0/update_company_in_ldc.py new file mode 100644 index 0000000000..ca95cf2fd7 --- /dev/null +++ b/erpnext/patches/v14_0/update_company_in_ldc.py @@ -0,0 +1,14 @@ +# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors +# License: MIT. See LICENSE + + +import frappe + +from erpnext import get_default_company + + +def execute(): + company = get_default_company() + if company: + for d in frappe.get_all("Lower Deduction Certificate", pluck="name"): + frappe.db.set_value("Lower Deduction Certificate", d, "company", company, update_modified=False) diff --git a/erpnext/regional/doctype/lower_deduction_certificate/lower_deduction_certificate.json b/erpnext/regional/doctype/lower_deduction_certificate/lower_deduction_certificate.json index c32ab6bec2..d332b4e76b 100644 --- a/erpnext/regional/doctype/lower_deduction_certificate/lower_deduction_certificate.json +++ b/erpnext/regional/doctype/lower_deduction_certificate/lower_deduction_certificate.json @@ -10,6 +10,7 @@ "tax_withholding_category", "fiscal_year", "column_break_3", + "company", "certificate_no", "section_break_3", "supplier", @@ -123,11 +124,18 @@ "label": "Tax Withholding Category", "options": "Tax Withholding Category", "reqd": 1 + }, + { + "fieldname": "company", + "fieldtype": "Link", + "label": "Company", + "options": "Company", + "reqd": 1 } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-10-23 18:33:38.962622", + "modified": "2023-04-18 08:25:35.302081", "modified_by": "Administrator", "module": "Regional", "name": "Lower Deduction Certificate", @@ -136,5 +144,6 @@ "permissions": [], "sort_field": "modified", "sort_order": "DESC", + "states": [], "track_changes": 1 } \ No newline at end of file From 22290c2694e626132de692a04e0fce2dba4c29df Mon Sep 17 00:00:00 2001 From: HarryPaulo Date: Tue, 25 Apr 2023 10:43:53 -0300 Subject: [PATCH 10/40] fix: respect title_field from doctype to bulk transactions (#34928) --- erpnext/utilities/bulk_transaction.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/utilities/bulk_transaction.py b/erpnext/utilities/bulk_transaction.py index c1579b3cbc..7fc1d9734c 100644 --- a/erpnext/utilities/bulk_transaction.py +++ b/erpnext/utilities/bulk_transaction.py @@ -104,6 +104,7 @@ def task(doc_name, from_doctype, to_doctype): obj = mapper[from_doctype][to_doctype](doc_name) obj.flags.ignore_validate = True + obj.set_title_field() obj.insert(ignore_mandatory=True) From f1acc5fabb27999dbae2f56885c8922a4b683139 Mon Sep 17 00:00:00 2001 From: Solufy Solution <34390782+Solufyin@users.noreply.github.com> Date: Tue, 25 Apr 2023 19:16:30 +0530 Subject: [PATCH 11/40] fix: Bulk Payment Entry from PO/SO (#34942) Co-authored-by: Nihantra Patel --- .../buying/doctype/purchase_order/purchase_order_list.js | 2 +- erpnext/selling/doctype/sales_order/sales_order_list.js | 2 +- erpnext/utilities/bulk_transaction.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/erpnext/buying/doctype/purchase_order/purchase_order_list.js b/erpnext/buying/doctype/purchase_order/purchase_order_list.js index d7907e4274..6594746cfc 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order_list.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order_list.js @@ -43,7 +43,7 @@ frappe.listview_settings['Purchase Order'] = { }); listview.page.add_action_item(__("Advance Payment"), ()=>{ - erpnext.bulk_transaction_processing.create(listview, "Purchase Order", "Advance Payment"); + erpnext.bulk_transaction_processing.create(listview, "Purchase Order", "Payment Entry"); }); } diff --git a/erpnext/selling/doctype/sales_order/sales_order_list.js b/erpnext/selling/doctype/sales_order/sales_order_list.js index 4691190d2a..64c58ef5d7 100644 --- a/erpnext/selling/doctype/sales_order/sales_order_list.js +++ b/erpnext/selling/doctype/sales_order/sales_order_list.js @@ -57,7 +57,7 @@ frappe.listview_settings['Sales Order'] = { }); listview.page.add_action_item(__("Advance Payment"), ()=>{ - erpnext.bulk_transaction_processing.create(listview, "Sales Order", "Advance Payment"); + erpnext.bulk_transaction_processing.create(listview, "Sales Order", "Payment Entry"); }); } diff --git a/erpnext/utilities/bulk_transaction.py b/erpnext/utilities/bulk_transaction.py index 7fc1d9734c..5e57b31793 100644 --- a/erpnext/utilities/bulk_transaction.py +++ b/erpnext/utilities/bulk_transaction.py @@ -69,7 +69,7 @@ def task(doc_name, from_doctype, to_doctype): "Sales Order": { "Sales Invoice": sales_order.make_sales_invoice, "Delivery Note": sales_order.make_delivery_note, - "Advance Payment": payment_entry.get_payment_entry, + "Payment Entry": payment_entry.get_payment_entry, }, "Sales Invoice": { "Delivery Note": sales_invoice.make_delivery_note, @@ -86,11 +86,11 @@ def task(doc_name, from_doctype, to_doctype): "Supplier Quotation": { "Purchase Order": supplier_quotation.make_purchase_order, "Purchase Invoice": supplier_quotation.make_purchase_invoice, - "Advance Payment": payment_entry.get_payment_entry, }, "Purchase Order": { "Purchase Invoice": purchase_order.make_purchase_invoice, "Purchase Receipt": purchase_order.make_purchase_receipt, + "Payment Entry": payment_entry.get_payment_entry, }, "Purchase Invoice": { "Purchase Receipt": purchase_invoice.make_purchase_receipt, @@ -98,7 +98,7 @@ def task(doc_name, from_doctype, to_doctype): }, "Purchase Receipt": {"Purchase Invoice": purchase_receipt.make_purchase_invoice}, } - if to_doctype in ["Advance Payment", "Payment Entry"]: + if to_doctype in ["Payment Entry"]: obj = mapper[from_doctype][to_doctype](from_doctype, doc_name) else: obj = mapper[from_doctype][to_doctype](doc_name) From ecea9b44a339fcfb261696118add5873a4d625fb Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 25 Apr 2023 19:17:13 +0530 Subject: [PATCH 12/40] fix: Payment entry with TDS in bank reco statement (#34961) --- erpnext/accounts/doctype/bank_clearance/bank_clearance.py | 2 +- .../report/bank_clearance_summary/bank_clearance_summary.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/bank_clearance/bank_clearance.py b/erpnext/accounts/doctype/bank_clearance/bank_clearance.py index 081718726b..8ad0bd17b4 100644 --- a/erpnext/accounts/doctype/bank_clearance/bank_clearance.py +++ b/erpnext/accounts/doctype/bank_clearance/bank_clearance.py @@ -56,7 +56,7 @@ class BankClearance(Document): select "Payment Entry" as payment_document, name as payment_entry, reference_no as cheque_number, reference_date as cheque_date, - if(paid_from=%(account)s, paid_amount, 0) as credit, + if(paid_from=%(account)s, paid_amount + total_taxes_and_charges, 0) as credit, if(paid_from=%(account)s, 0, received_amount) as debit, posting_date, ifnull(party,if(paid_from=%(account)s,paid_to,paid_from)) as against_account, clearance_date, if(paid_to=%(account)s, paid_to_account_currency, paid_from_account_currency) as account_currency diff --git a/erpnext/accounts/report/bank_clearance_summary/bank_clearance_summary.py b/erpnext/accounts/report/bank_clearance_summary/bank_clearance_summary.py index 306af722ba..2d68bb70b8 100644 --- a/erpnext/accounts/report/bank_clearance_summary/bank_clearance_summary.py +++ b/erpnext/accounts/report/bank_clearance_summary/bank_clearance_summary.py @@ -80,7 +80,7 @@ def get_entries(filters): payment_entries = frappe.db.sql( """SELECT "Payment Entry", name, posting_date, reference_no, clearance_date, party, - if(paid_from=%(account)s, paid_amount * -1, received_amount) + if(paid_from=%(account)s, ((paid_amount * -1) - total_taxes_and_charges) , received_amount) FROM `tabPayment Entry` WHERE From 72b5c1f70a51f18cda48c8e71602ee2d620e582b Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 25 Apr 2023 19:18:08 +0530 Subject: [PATCH 13/40] fix: Use set instead of db_set as it is called from validate (#34967) --- erpnext/crm/doctype/opportunity/opportunity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 6a5fead0f8..2a8d65f486 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -59,7 +59,7 @@ class Opportunity(TransactionBase, CRMNote): if not self.get(field) and frappe.db.field_exists(self.opportunity_from, field): try: value = frappe.db.get_value(self.opportunity_from, self.party_name, field) - self.db_set(field, value) + self.set(field, value) except Exception: continue From f7b50f2adef11b9f2bd843d6bca3f2b6cf7be19b Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 25 Apr 2023 19:18:45 +0530 Subject: [PATCH 14/40] fix: Unable to allocate advance against invoice (#35007) --- erpnext/controllers/accounts_controller.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 642d51c325..6982f716bf 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1662,7 +1662,10 @@ class AccountsController(TransactionBase): ) self.append("payment_schedule", data) - if not automatically_fetch_payment_terms: + if not ( + automatically_fetch_payment_terms + and self.linked_order_has_payment_terms(po_or_so, fieldname, doctype) + ): for d in self.get("payment_schedule"): if d.invoice_portion: d.payment_amount = flt( From 74fb2bec3a5055d6bb76be0d5e3fd80899c642d1 Mon Sep 17 00:00:00 2001 From: Nandhinidevi123 Date: Tue, 25 Apr 2023 20:08:35 +0530 Subject: [PATCH 15/40] add if condition for workstation filter --- erpnext/manufacturing/doctype/bom/bom.js | 2 +- erpnext/manufacturing/doctype/routing/routing.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js index 7cdcef9c7a..ad9aafe066 100644 --- a/erpnext/manufacturing/doctype/bom/bom.js +++ b/erpnext/manufacturing/doctype/bom/bom.js @@ -652,7 +652,7 @@ frappe.ui.form.on("BOM Operation", "operation", function(frm, cdt, cdn) { frappe.ui.form.on("BOM Operation", "workstation", function(frm, cdt, cdn) { var d = locals[cdt][cdn]; - + if(!d.workstation) return; frappe.call({ "method": "frappe.client.get", args: { diff --git a/erpnext/manufacturing/doctype/routing/routing.js b/erpnext/manufacturing/doctype/routing/routing.js index b480c70ad5..784e83a4c0 100644 --- a/erpnext/manufacturing/doctype/routing/routing.js +++ b/erpnext/manufacturing/doctype/routing/routing.js @@ -50,7 +50,7 @@ frappe.ui.form.on('BOM Operation', { workstation: function(frm, cdt, cdn) { const d = locals[cdt][cdn]; - + if(!d.workstation) return; frappe.call({ "method": "frappe.client.get", args: { From d6bc8bba8b7ed748483bf61b03c8c87eb54f8ab0 Mon Sep 17 00:00:00 2001 From: Raffael Meyer <14891507+barredterra@users.noreply.github.com> Date: Tue, 25 Apr 2023 17:21:11 +0200 Subject: [PATCH 16/40] fix: per_billed condition for Payment Entry (#34969) --- erpnext/accounts/doctype/payment_entry/payment_entry.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index ee4d4d29e2..082128ac1e 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1693,7 +1693,10 @@ def get_payment_entry( ): reference_doc = None doc = frappe.get_doc(dt, dn) - if dt in ("Sales Order", "Purchase Order") and flt(doc.per_billed, 2) >= 99.99: + over_billing_allowance = frappe.db.get_single_value("Accounts Settings", "over_billing_allowance") + if dt in ("Sales Order", "Purchase Order") and flt(doc.per_billed, 2) >= ( + 100.0 + over_billing_allowance + ): frappe.throw(_("Can only make payment against unbilled {0}").format(dt)) if not party_type: From f88431a79a6bda662352ec38b8fe650c7f07fdd3 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 25 Apr 2023 20:54:22 +0530 Subject: [PATCH 17/40] fix: Common party JV cost center (#35008) --- erpnext/controllers/accounts_controller.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 6982f716bf..d0ec654162 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1904,12 +1904,14 @@ class AccountsController(TransactionBase): reconcilation_entry.party = secondary_party reconcilation_entry.reference_type = self.doctype reconcilation_entry.reference_name = self.name - reconcilation_entry.cost_center = self.cost_center + reconcilation_entry.cost_center = self.cost_center or erpnext.get_default_cost_center( + self.company + ) advance_entry.account = primary_account advance_entry.party_type = primary_party_type advance_entry.party = primary_party - advance_entry.cost_center = self.cost_center + advance_entry.cost_center = self.cost_center or erpnext.get_default_cost_center(self.company) advance_entry.is_advance = "Yes" if self.doctype == "Sales Invoice": From c4512d552e3262276df907148fafa57319bdebb1 Mon Sep 17 00:00:00 2001 From: Ernesto Ruiz Date: Tue, 25 Apr 2023 09:26:53 -0600 Subject: [PATCH 18/40] chore: Add translate function to Depreciation Journal Entry Remark (#35022) chore: Add translate function to Depreciation Journal Entry Remark --- erpnext/assets/doctype/asset/asset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 6001254762..42f531189a 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -783,7 +783,7 @@ def make_journal_entry(asset_name): je.voucher_type = "Depreciation Entry" je.naming_series = depreciation_series je.company = asset.company - je.remark = "Depreciation Entry against asset {0}".format(asset_name) + je.remark = _("Depreciation Entry against asset {0}").format(asset_name) je.append( "accounts", From 3d90b970d19ee0f41582dada6dbcdc4999fde10a Mon Sep 17 00:00:00 2001 From: tundebabzy Date: Tue, 25 Apr 2023 16:27:59 +0100 Subject: [PATCH 19/40] fix: click handler should not attempt indexed access of empty array (#35013) fix: click handler should not attempt indexed access of empty array --- erpnext/public/js/projects/timer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/public/js/projects/timer.js b/erpnext/public/js/projects/timer.js index 9dae7118d9..0209f4c232 100644 --- a/erpnext/public/js/projects/timer.js +++ b/erpnext/public/js/projects/timer.js @@ -68,7 +68,7 @@ erpnext.timesheet.control_timer = function(frm, dialog, row, timestamp=0) { // New activity if no activities found var args = dialog.get_values(); if(!args) return; - if (frm.doc.time_logs.length <= 1 && !frm.doc.time_logs[0].activity_type && !frm.doc.time_logs[0].from_time) { + if (frm.doc.time_logs.length == 1 && !frm.doc.time_logs[0].activity_type && !frm.doc.time_logs[0].from_time) { frm.doc.time_logs = []; } row = frappe.model.add_child(frm.doc, "Timesheet Detail", "time_logs"); From ab0f7794b77a1cc6ff312331fd84e1541cfe2ac8 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 25 Apr 2023 21:08:50 +0530 Subject: [PATCH 20/40] fix: wrong qty of remaining work orders to be created when using "Create" > "Work Order" (#34726) fix: wrong qty of remaining work orders to be created when using "Create" > "Work Order" (#34726) * fix: convert asynchronous field update to synchronous * fix: wrong qty of remaining work orders to be created when using "Create" > "Work Order" (cherry picked from commit 189b020d228bdb1c0c589697162cf91718b2fa27) Co-authored-by: danjeremynavarro <46537526+danjeremynavarro@users.noreply.github.com> --- erpnext/selling/doctype/sales_order/sales_order.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index ee9161bee4..d995517af8 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -1340,8 +1340,9 @@ def get_work_order_items(sales_order, for_raw_material_request=0): .select(Sum(wo.qty)) .where( (wo.production_item == i.item_code) - & (wo.sales_order == so.name) * (wo.sales_order_item == i.name) - & (wo.docstatus.lte(2)) + & (wo.sales_order == so.name) + & (wo.sales_order_item == i.name) + & (wo.docstatus.lt(2)) ) .run()[0][0] ) From c36dc3dc57629c4f77e492508beb09b705a2f25b Mon Sep 17 00:00:00 2001 From: "Kitti U. @ Ecosoft" Date: Tue, 25 Apr 2023 23:04:28 +0700 Subject: [PATCH 21/40] fix: v14, Bank Reconcile Tools not cover case JV debit bank (#35000) --- .../doctype/bank_transaction/bank_transaction.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py index fcbaf329f5..b441af9660 100644 --- a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py +++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py @@ -281,10 +281,13 @@ def get_paid_amount(payment_entry, currency, gl_bank_account): ) elif payment_entry.payment_document == "Journal Entry": - return frappe.db.get_value( - "Journal Entry Account", - {"parent": payment_entry.payment_entry, "account": gl_bank_account}, - "sum(credit_in_account_currency)", + return abs( + frappe.db.get_value( + "Journal Entry Account", + {"parent": payment_entry.payment_entry, "account": gl_bank_account}, + "sum(debit_in_account_currency-credit_in_account_currency)", + ) + or 0 ) elif payment_entry.payment_document == "Expense Claim": From 3be1ab9b8dbf339e23138e5e518c950b2e7a1b97 Mon Sep 17 00:00:00 2001 From: HarryPaulo Date: Tue, 25 Apr 2023 13:24:41 -0300 Subject: [PATCH 22/40] fix: allow submit delivery note when the sales order was billed... (#34910) --- erpnext/stock/doctype/delivery_note/delivery_note.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index 9f9f5cbe2a..9f6dd24fa6 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -271,6 +271,9 @@ class DeliveryNote(SellingController): def check_credit_limit(self): from erpnext.selling.doctype.customer.customer import check_credit_limit + if self.per_billed == 100: + return + extra_amount = 0 validate_against_credit_limit = False bypass_credit_limit_check_at_sales_order = cint( From 1e2deee57933792e612c4f2c63cae147d8242194 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 26 Apr 2023 20:30:53 +0530 Subject: [PATCH 23/40] fix: don't create material request from sales order against the delivered items --- .../doctype/sales_order/sales_order.py | 4 +-- .../doctype/sales_order/test_sales_order.py | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index ee9161bee4..67971d10b6 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -547,7 +547,7 @@ def make_material_request(source_name, target_doc=None): # qty is for packed items, because packed items don't have stock_qty field qty = source.get("qty") target.project = source_parent.project - target.qty = qty - requested_item_qty.get(source.name, 0) + target.qty = qty - requested_item_qty.get(source.name, 0) - source.delivered_qty target.stock_qty = flt(target.qty) * flt(target.conversion_factor) args = target.as_dict().copy() @@ -581,7 +581,7 @@ def make_material_request(source_name, target_doc=None): "doctype": "Material Request Item", "field_map": {"name": "sales_order_item", "parent": "sales_order"}, "condition": lambda doc: not frappe.db.exists("Product Bundle", doc.item_code) - and doc.stock_qty > requested_item_qty.get(doc.name, 0), + and (doc.stock_qty - doc.delivered_qty) > requested_item_qty.get(doc.name, 0), "postprocess": update_item, }, }, diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py index 627914f0c7..ba8bbc2185 100644 --- a/erpnext/selling/doctype/sales_order/test_sales_order.py +++ b/erpnext/selling/doctype/sales_order/test_sales_order.py @@ -1878,6 +1878,37 @@ class TestSalesOrder(FrappeTestCase): self.assertEqual(pe.references[1].reference_name, so.name) self.assertEqual(pe.references[1].allocated_amount, 300) + def test_delivered_item_material_request(self): + "SO -> MR (Manufacture) -> WO. Test if WO Qty is updated in SO." + from erpnext.manufacturing.doctype.work_order.work_order import ( + make_stock_entry as make_se_from_wo, + ) + from erpnext.stock.doctype.material_request.material_request import raise_work_orders + + so = make_sales_order( + item_list=[ + {"item_code": "_Test FG Item", "qty": 10, "rate": 100, "warehouse": "Work In Progress - _TC"} + ] + ) + + make_stock_entry( + item_code="_Test FG Item", target="Work In Progress - _TC", qty=4, basic_rate=100 + ) + + dn = make_delivery_note(so.name) + dn.items[0].qty = 4 + dn.submit() + + so.load_from_db() + self.assertEqual(so.items[0].delivered_qty, 4) + + mr = make_material_request(so.name) + mr.material_request_type = "Purchase" + mr.schedule_date = today() + mr.save() + + self.assertEqual(mr.items[0].qty, 6) + def automatically_fetch_payment_terms(enable=1): accounts_settings = frappe.get_doc("Accounts Settings") From 6dfca79af31e4aa39a48a323f23c7b326b229504 Mon Sep 17 00:00:00 2001 From: Nihantra Patel Date: Thu, 27 Apr 2023 15:04:50 +0530 Subject: [PATCH 24/40] fix: Report link, option, and added a link for Sales Person in GP --- erpnext/accounts/report/gross_profit/gross_profit.js | 2 +- erpnext/accounts/report/gross_profit/gross_profit.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/report/gross_profit/gross_profit.js b/erpnext/accounts/report/gross_profit/gross_profit.js index e89d42977b..53921dc66e 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.js +++ b/erpnext/accounts/report/gross_profit/gross_profit.js @@ -73,7 +73,7 @@ frappe.query_reports["Gross Profit"] = { if (column.fieldname == "sales_invoice" && column.options == "Item" && data && data.indent == 0) { column._options = "Sales Invoice"; } else { - column._options = "Item"; + column._options = ""; } value = default_formatter(value, row, column, data); diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py index 01fee281b0..81f5928628 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.py +++ b/erpnext/accounts/report/gross_profit/gross_profit.py @@ -250,7 +250,7 @@ def get_columns(group_wise_columns, filters): "label": _("Warehouse"), "fieldname": "warehouse", "fieldtype": "Link", - "options": "warehouse", + "options": "Warehouse", "width": 100, }, "qty": {"label": _("Qty"), "fieldname": "qty", "fieldtype": "Float", "width": 80}, @@ -305,7 +305,8 @@ def get_columns(group_wise_columns, filters): "sales_person": { "label": _("Sales Person"), "fieldname": "sales_person", - "fieldtype": "Data", + "fieldtype": "Link", + "options": "Sales Person", "width": 100, }, "allocated_amount": { @@ -326,14 +327,14 @@ def get_columns(group_wise_columns, filters): "label": _("Customer Group"), "fieldname": "customer_group", "fieldtype": "Link", - "options": "customer", + "options": "Customer Group", "width": 100, }, "territory": { "label": _("Territory"), "fieldname": "territory", "fieldtype": "Link", - "options": "territory", + "options": "Territory", "width": 100, }, "monthly": { From 72dd7884a89b7dcce342410c8bc3f3da56bf99e8 Mon Sep 17 00:00:00 2001 From: Nihantra Patel Date: Thu, 27 Apr 2023 17:04:39 +0530 Subject: [PATCH 25/40] fix: Hyperlink in Quality Inspection Summary --- .../quality_inspection_summary/quality_inspection_summary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/manufacturing/report/quality_inspection_summary/quality_inspection_summary.py b/erpnext/manufacturing/report/quality_inspection_summary/quality_inspection_summary.py index de96a6c032..38e05852ee 100644 --- a/erpnext/manufacturing/report/quality_inspection_summary/quality_inspection_summary.py +++ b/erpnext/manufacturing/report/quality_inspection_summary/quality_inspection_summary.py @@ -69,7 +69,7 @@ def get_columns(filters): "label": _("Id"), "fieldname": "name", "fieldtype": "Link", - "options": "Work Order", + "options": "Quality Inspection", "width": 100, }, {"label": _("Report Date"), "fieldname": "report_date", "fieldtype": "Date", "width": 150}, From b44331c981974cae72175fa10c8d10f0378129b9 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 28 Apr 2023 14:06:04 +0530 Subject: [PATCH 26/40] refactor: checkbox in purchase invoice --- .../doctype/purchase_invoice/purchase_invoice.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json index b4d369e6c6..f76dfff0f8 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json @@ -89,6 +89,7 @@ "column_break8", "grand_total", "rounding_adjustment", + "use_company_roundoff_cost_center", "rounded_total", "in_words", "total_advance", @@ -1559,13 +1560,19 @@ "fieldname": "only_include_allocated_payments", "fieldtype": "Check", "label": "Only Include Allocated Payments" + }, + { + "default": "0", + "fieldname": "use_company_roundoff_cost_center", + "fieldtype": "Check", + "label": "Use Company Default Round Off Cost Center" } ], "icon": "fa fa-file-text", "idx": 204, "is_submittable": 1, "links": [], - "modified": "2023-04-03 22:57:14.074982", + "modified": "2023-04-28 12:57:50.832598", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice", From ebe67875103e4b2aecad8cc5cd20a896cfe5ebd9 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 28 Apr 2023 14:07:28 +0530 Subject: [PATCH 27/40] refactor: checkbox to toggle parent doc cost center preference --- .../doctype/purchase_invoice/purchase_invoice.py | 12 ++++++++---- erpnext/accounts/general_ledger.py | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index a617447856..868a150edf 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -978,7 +978,7 @@ class PurchaseInvoice(BuyingController): def make_precision_loss_gl_entry(self, gl_entries): round_off_account, round_off_cost_center = get_round_off_account_and_cost_center( - self.company, "Purchase Invoice", self.name + self.company, "Purchase Invoice", self.name, self.use_company_roundoff_cost_center ) precision_loss = self.get("base_net_total") - flt( @@ -992,7 +992,9 @@ class PurchaseInvoice(BuyingController): "account": round_off_account, "against": self.supplier, "credit": precision_loss, - "cost_center": self.cost_center or round_off_cost_center, + "cost_center": round_off_cost_center + if self.use_company_roundoff_cost_center + else self.cost_center or round_off_cost_center, "remarks": _("Net total calculation precision loss"), } ) @@ -1386,7 +1388,7 @@ class PurchaseInvoice(BuyingController): not self.is_internal_transfer() and self.rounding_adjustment and self.base_rounding_adjustment ): round_off_account, round_off_cost_center = get_round_off_account_and_cost_center( - self.company, "Purchase Invoice", self.name + self.company, "Purchase Invoice", self.name, self.use_company_roundoff_cost_center ) gl_entries.append( @@ -1396,7 +1398,9 @@ class PurchaseInvoice(BuyingController): "against": self.supplier, "debit_in_account_currency": self.rounding_adjustment, "debit": self.base_rounding_adjustment, - "cost_center": self.cost_center or round_off_cost_center, + "cost_center": round_off_cost_center + if self.use_company_roundoff_cost_center + else (self.cost_center or round_off_cost_center), }, item=self, ) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 6b2546e820..a929ff17b0 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -475,7 +475,9 @@ def update_accounting_dimensions(round_off_gle): round_off_gle[dimension] = dimension_values.get(dimension) -def get_round_off_account_and_cost_center(company, voucher_type, voucher_no): +def get_round_off_account_and_cost_center( + company, voucher_type, voucher_no, use_company_default=False +): round_off_account, round_off_cost_center = frappe.get_cached_value( "Company", company, ["round_off_account", "round_off_cost_center"] ) or [None, None] @@ -483,7 +485,7 @@ def get_round_off_account_and_cost_center(company, voucher_type, voucher_no): meta = frappe.get_meta(voucher_type) # Give first preference to parent cost center for round off GLE - if meta.has_field("cost_center"): + if not use_company_default and meta.has_field("cost_center"): parent_cost_center = frappe.db.get_value(voucher_type, voucher_no, "cost_center") if parent_cost_center: round_off_cost_center = parent_cost_center From 0f3b06cc8aa36e8f3695d32b3f4a0b915744814b Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 28 Apr 2023 14:18:08 +0530 Subject: [PATCH 28/40] refactor: checkbox in Sales Invoice --- .../accounts/doctype/sales_invoice/sales_invoice.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index a41e13c8ea..6a65b30ceb 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -79,6 +79,7 @@ "column_break5", "grand_total", "rounding_adjustment", + "use_company_roundoff_cost_center", "rounded_total", "in_words", "total_advance", @@ -2135,6 +2136,12 @@ "fieldname": "only_include_allocated_payments", "fieldtype": "Check", "label": "Only Include Allocated Payments" + }, + { + "default": "0", + "fieldname": "use_company_roundoff_cost_center", + "fieldtype": "Check", + "label": "Use Company default Cost Center for Round off" } ], "icon": "fa fa-file-text", @@ -2147,7 +2154,7 @@ "link_fieldname": "consolidated_invoice" } ], - "modified": "2023-04-03 22:55:14.206473", + "modified": "2023-04-28 14:15:59.901154", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", From 4ccce933941d9caab29ac1c551f55777b7da8e0b Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 28 Apr 2023 14:20:06 +0530 Subject: [PATCH 29/40] refactor: checkbox to toggle parent doc cost center preference --- erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index db619950e1..e16b1b1195 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1464,7 +1464,7 @@ class SalesInvoice(SellingController): and not self.is_internal_transfer() ): round_off_account, round_off_cost_center = get_round_off_account_and_cost_center( - self.company, "Sales Invoice", self.name + self.company, "Sales Invoice", self.name, self.use_company_roundoff_cost_center ) gl_entries.append( @@ -1476,7 +1476,9 @@ class SalesInvoice(SellingController): self.rounding_adjustment, self.precision("rounding_adjustment") ), "credit": flt(self.base_rounding_adjustment, self.precision("base_rounding_adjustment")), - "cost_center": self.cost_center or round_off_cost_center, + "cost_center": round_off_cost_center + if self.use_company_roundoff_cost_center + else (self.cost_center or round_off_cost_center), }, item=self, ) From bdf2f7416a012576561e4911e89088c80bc6af6e Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 28 Apr 2023 15:16:02 +0530 Subject: [PATCH 30/40] fix: not able to create delivery note from sales order --- erpnext/stock/get_item_details.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index ce85702f48..f3adefb3e7 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -1508,11 +1508,15 @@ def get_so_reservation_for_item(args): elif args.get("against_sales_invoice"): sales_order = frappe.db.get_all( "Sales Invoice Item", - filters={"parent": args.get("against_sales_invoice"), "item_code": args.get("item_code")}, + filters={ + "parent": args.get("against_sales_invoice"), + "item_code": args.get("item_code"), + "docstatus": 1, + }, fields="sales_order", ) if sales_order and sales_order[0]: - if get_reserved_qty_for_so(sales_order[0][0], args.get("item_code")): + if get_reserved_qty_for_so(sales_order[0].sales_order, args.get("item_code")): reserved_so = sales_order[0] elif args.get("sales_order"): if get_reserved_qty_for_so(args.get("sales_order"), args.get("item_code")): From 123355392b58f9a383632a995ba17e47d4281283 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 27 Apr 2023 12:56:27 +0530 Subject: [PATCH 31/40] fix: incorrect paid_amount and exchange rate in PE If Company master has no default cash or bank account set but Party has default company bank account set. In this case, paid_amount and conversion rate are not calculated correctly --- .../doctype/payment_entry/payment_entry.py | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index ee4d4d29e2..6e9a48e03f 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1712,6 +1712,13 @@ def get_payment_entry( # bank or cash bank = get_bank_cash_account(doc, bank_account) + # if default bank or cash account is not set in company master and party has default company bank account, fetch it + if party_type in ["Customer", "Supplier"] and not bank: + party_bank_account = get_party_bank_account(party_type, doc.get(scrub(party_type))) + if party_bank_account: + account = frappe.db.get_value("Bank Account", party_bank_account, "account") + bank = get_bank_cash_account(doc, account) + paid_amount, received_amount = set_paid_amount_and_received_amount( dt, party_account_currency, bank, outstanding_amount, payment_type, bank_amount, doc ) @@ -1928,19 +1935,27 @@ def set_paid_amount_and_received_amount( paid_amount = received_amount = 0 if party_account_currency == bank.account_currency: paid_amount = received_amount = abs(outstanding_amount) - elif payment_type == "Receive": - paid_amount = abs(outstanding_amount) - if bank_amount: - received_amount = bank_amount - else: - received_amount = paid_amount * doc.get("conversion_rate", 1) else: - received_amount = abs(outstanding_amount) - if bank_amount: - paid_amount = bank_amount + company_currency = frappe.get_cached_value("Company", doc.get("company"), "default_currency") + if payment_type == "Receive": + paid_amount = abs(outstanding_amount) + if bank_amount: + received_amount = bank_amount + else: + if company_currency != bank.account_currency: + received_amount = paid_amount / doc.get("conversion_rate", 1) + else: + received_amount = paid_amount * doc.get("conversion_rate", 1) else: - # if party account currency and bank currency is different then populate paid amount as well - paid_amount = received_amount * doc.get("conversion_rate", 1) + received_amount = abs(outstanding_amount) + if bank_amount: + paid_amount = bank_amount + else: + if company_currency != bank.account_currency: + paid_amount = received_amount / doc.get("conversion_rate", 1) + else: + # if party account currency and bank currency is different then populate paid amount as well + paid_amount = received_amount * doc.get("conversion_rate", 1) return paid_amount, received_amount From f3b3dabb9a6e5f8cd34c4a07ed54738b28f2b69a Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 1 May 2023 10:50:51 +0530 Subject: [PATCH 32/40] fix: Naming series error in Journal Entry template (#35084) --- .../journal_entry_template.js | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js index 88f1c9069c..5ebdf61db2 100644 --- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js @@ -2,6 +2,21 @@ // For license information, please see license.txt frappe.ui.form.on("Journal Entry Template", { + onload: function(frm) { + if(frm.is_new()) { + frappe.call({ + type: "GET", + method: "erpnext.accounts.doctype.journal_entry_template.journal_entry_template.get_naming_series", + callback: function(r){ + if(r.message) { + frm.set_df_property("naming_series", "options", r.message.split("\n")); + frm.set_value("naming_series", r.message.split("\n")[0]); + frm.refresh_field("naming_series"); + } + } + }); + } + }, refresh: function(frm) { frappe.model.set_default_values(frm.doc); @@ -19,18 +34,6 @@ frappe.ui.form.on("Journal Entry Template", { return { filters: filters }; }); - - frappe.call({ - type: "GET", - method: "erpnext.accounts.doctype.journal_entry_template.journal_entry_template.get_naming_series", - callback: function(r){ - if(r.message){ - frm.set_df_property("naming_series", "options", r.message.split("\n")); - frm.set_value("naming_series", r.message.split("\n")[0]); - frm.refresh_field("naming_series"); - } - } - }); }, voucher_type: function(frm) { var add_accounts = function(doc, r) { From 64be694087292f99c81d8550ee5987696ef615c4 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 1 May 2023 10:56:46 +0530 Subject: [PATCH 33/40] fix: Patch for posting closing balances (#35037) --- erpnext/patches/v14_0/update_closing_balances.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/erpnext/patches/v14_0/update_closing_balances.py b/erpnext/patches/v14_0/update_closing_balances.py index 40a18516cb..f47e730fd2 100644 --- a/erpnext/patches/v14_0/update_closing_balances.py +++ b/erpnext/patches/v14_0/update_closing_balances.py @@ -26,7 +26,15 @@ def execute(): pcv_doc.year_start_date = get_fiscal_year( pcv.posting_date, pcv.fiscal_year, company=pcv.company )[1] - gl_entries = pcv_doc.get_gl_entries() + + gl_entries = frappe.db.get_all( + "GL Entry", filters={"voucher_no": pcv.name, "is_cancelled": 0}, fields=["*"] + ) + for entry in gl_entries: + entry["is_period_closing_voucher_entry"] = 1 + entry["closing_date"] = pcv_doc.posting_date + entry["period_closing_voucher"] = pcv_doc.name + closing_entries = pcv_doc.get_grouped_gl_entries(get_opening_entries=get_opening_entries) make_closing_entries(gl_entries + closing_entries, voucher_name=pcv.name) company_wise_order[pcv.company].append(pcv.posting_date) From ea0b03ae9e481dc1048fb5d3fbffc3a948c07573 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 1 May 2023 13:09:47 +0530 Subject: [PATCH 34/40] fix: Updates in process statement of Accounts (#35064) --- .../process_statement_of_accounts.html | 7 ++++++- .../process_statement_of_accounts.json | 14 +++++++++++++- .../process_statement_of_accounts.py | 2 +- .../process_statement_of_accounts_customer.json | 4 ++-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html index b9680dfb3b..03abc93e0b 100644 --- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html +++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html @@ -15,7 +15,12 @@

{{ _("STATEMENTS OF ACCOUNTS") }}

-
{{ _("Customer: ") }} {{filters.party_name[0] }}
+ {% if filters.party[0] == filters.party_name[0] %} +
{{ _("Customer: ") }} {{ filters.party_name[0] }}
+ {% else %} +
{{ _("Customer: ") }} {{ filters.party[0] }}
+
{{ _("Customer Name: ") }} {{filters.party_name[0] }}
+ {% endif %}
{{ _("Date: ") }} {{ frappe.format(filters.from_date, 'Date')}} diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json index 16602d317a..e23620fd4e 100644 --- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json +++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json @@ -36,6 +36,8 @@ "terms_and_conditions", "section_break_1", "enable_auto_email", + "column_break_ocfq", + "sender", "section_break_18", "frequency", "filter_duration", @@ -298,10 +300,20 @@ "fieldname": "show_net_values_in_party_account", "fieldtype": "Check", "label": "Show Net Values in Party Account" + }, + { + "fieldname": "sender", + "fieldtype": "Link", + "label": "Sender", + "options": "Email Account" + }, + { + "fieldname": "column_break_ocfq", + "fieldtype": "Column Break" } ], "links": [], - "modified": "2022-11-10 17:44:17.165991", + "modified": "2023-04-26 12:46:43.645455", "modified_by": "Administrator", "module": "Accounts", "name": "Process Statement Of Accounts", diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py index a482931a8e..b36f33be3b 100644 --- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py +++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py @@ -334,7 +334,7 @@ def send_emails(document_name, from_scheduler=False): queue="short", method=frappe.sendmail, recipients=recipients, - sender=frappe.session.user, + sender=doc.sender or frappe.session.user, cc=cc, subject=subject, message=message, diff --git a/erpnext/accounts/doctype/process_statement_of_accounts_customer/process_statement_of_accounts_customer.json b/erpnext/accounts/doctype/process_statement_of_accounts_customer/process_statement_of_accounts_customer.json index 8bffd6a93b..1749d72e16 100644 --- a/erpnext/accounts/doctype/process_statement_of_accounts_customer/process_statement_of_accounts_customer.json +++ b/erpnext/accounts/doctype/process_statement_of_accounts_customer/process_statement_of_accounts_customer.json @@ -27,7 +27,7 @@ }, { "fieldname": "billing_email", - "fieldtype": "Read Only", + "fieldtype": "Data", "in_list_view": 1, "label": "Billing Email" }, @@ -41,7 +41,7 @@ ], "istable": 1, "links": [], - "modified": "2023-03-13 00:12:34.508086", + "modified": "2023-04-26 13:02:41.964499", "modified_by": "Administrator", "module": "Accounts", "name": "Process Statement Of Accounts Customer", From effb34bbfa4144590ab4075cfcb603c50ca5c561 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 25 Apr 2023 20:26:50 +0530 Subject: [PATCH 35/40] refactor: don't book exch gain/loss for sales/purchase orders --- .../doctype/payment_entry/payment_entry.py | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index ee4d4d29e2..59641e58e1 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -654,6 +654,28 @@ class PaymentEntry(AccountsController): self.precision("base_received_amount"), ) + def calculate_base_allocated_amount_for_reference(self, d) -> float: + base_allocated_amount = 0 + if d.reference_doctype in frappe.get_hooks("advance_payment_doctypes"): + # When referencing Sales/Purchase Order, use the source/target exchange rate depending on payment type. + # This is so there are no Exchange Gain/Loss generated for such doctypes + + exchange_rate = 1 + if self.payment_type == "Receive": + exchange_rate = self.source_exchange_rate + elif self.payment_type == "Pay": + exchange_rate = self.target_exchange_rate + + base_allocated_amount += flt( + flt(d.allocated_amount) * flt(exchange_rate), self.precision("base_paid_amount") + ) + else: + base_allocated_amount += flt( + flt(d.allocated_amount) * flt(d.exchange_rate), self.precision("base_paid_amount") + ) + + return base_allocated_amount + def set_total_allocated_amount(self): if self.payment_type == "Internal Transfer": return @@ -662,9 +684,7 @@ class PaymentEntry(AccountsController): for d in self.get("references"): if d.allocated_amount: total_allocated_amount += flt(d.allocated_amount) - base_total_allocated_amount += flt( - flt(d.allocated_amount) * flt(d.exchange_rate), self.precision("base_paid_amount") - ) + base_total_allocated_amount += self.calculate_base_allocated_amount_for_reference(d) self.total_allocated_amount = abs(total_allocated_amount) self.base_total_allocated_amount = abs(base_total_allocated_amount) @@ -881,9 +901,7 @@ class PaymentEntry(AccountsController): } ) - allocated_amount_in_company_currency = flt( - flt(d.allocated_amount) * flt(d.exchange_rate), self.precision("paid_amount") - ) + allocated_amount_in_company_currency = self.calculate_base_allocated_amount_for_reference(d) gle.update( { From ce4e18c8d232bbf19fea74e6e6133b773d21f3d5 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 1 May 2023 13:54:15 +0530 Subject: [PATCH 36/40] test: Sales/Purchase Orders will not book Exchange gain/loss --- .../payment_entry/test_payment_entry.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py index 67049c47ad..68f333dc29 100644 --- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py @@ -51,6 +51,38 @@ class TestPaymentEntry(FrappeTestCase): so_advance_paid = frappe.db.get_value("Sales Order", so.name, "advance_paid") self.assertEqual(so_advance_paid, 0) + def test_payment_against_sales_order_usd_to_inr(self): + so = make_sales_order( + customer="_Test Customer USD", currency="USD", qty=1, rate=100, do_not_submit=True + ) + so.conversion_rate = 50 + so.submit() + pe = get_payment_entry("Sales Order", so.name) + pe.source_exchange_rate = 55 + pe.received_amount = 5500 + pe.insert() + pe.submit() + + # there should be no difference amount + pe.reload() + self.assertEqual(pe.difference_amount, 0) + self.assertEqual(pe.deductions, []) + + expected_gle = dict( + (d[0], d) + for d in [["_Test Receivable USD - _TC", 0, 5500, so.name], ["Cash - _TC", 5500.0, 0, None]] + ) + + self.validate_gl_entries(pe.name, expected_gle) + + so_advance_paid = frappe.db.get_value("Sales Order", so.name, "advance_paid") + self.assertEqual(so_advance_paid, 100) + + pe.cancel() + + so_advance_paid = frappe.db.get_value("Sales Order", so.name, "advance_paid") + self.assertEqual(so_advance_paid, 0) + def test_payment_entry_for_blocked_supplier_invoice(self): supplier = frappe.get_doc("Supplier", "_Test Supplier") supplier.on_hold = 1 From f751727149392cfa304e20b2d50a7cbeef17d388 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 1 May 2023 18:47:25 +0530 Subject: [PATCH 37/40] fix: don't allow to make reposting for the closed period --- .../test_period_closing_voucher.py | 20 ++++++++++++- .../repost_item_valuation.py | 29 ++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py index 62ae8572e4..5d08e8d1c2 100644 --- a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py +++ b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py @@ -205,7 +205,7 @@ class TestPeriodClosingVoucher(unittest.TestCase): self.assertRaises(frappe.ValidationError, jv1.submit) - def test_closing_balance_with_dimensions(self): + def test_closing_balance_with_dimensions_and_test_reposting_entry(self): frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'") frappe.db.sql("delete from `tabPeriod Closing Voucher` where company='Test PCV Company'") frappe.db.sql("delete from `tabAccount Closing Balance` where company='Test PCV Company'") @@ -299,6 +299,24 @@ class TestPeriodClosingVoucher(unittest.TestCase): self.assertEqual(cc2_closing_balance.credit, 500) self.assertEqual(cc2_closing_balance.credit_in_account_currency, 500) + warehouse = frappe.db.get_value("Warehouse", {"company": company}, "name") + + repost_doc = frappe.get_doc( + { + "doctype": "Repost Item Valuation", + "company": company, + "posting_date": "2020-03-15", + "based_on": "Item and Warehouse", + "item_code": "Test Item 1", + "warehouse": warehouse, + } + ) + + self.assertRaises(frappe.ValidationError, repost_doc.save) + + repost_doc.posting_date = today() + repost_doc.save() + def make_period_closing_voucher(self, posting_date=None, submit=True): surplus_account = create_account() cost_center = create_cost_center("Test Cost Center 1") diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py index bbed099da9..aabc6fcfe3 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -6,7 +6,7 @@ from frappe import _ from frappe.exceptions import QueryDeadlockError, QueryTimeoutError from frappe.model.document import Document from frappe.query_builder import DocType, Interval -from frappe.query_builder.functions import Now +from frappe.query_builder.functions import Max, Now from frappe.utils import cint, get_link_to_form, get_weekday, getdate, now, nowtime from frappe.utils.user import get_users_with_role from rq.timeouts import JobTimeoutException @@ -36,11 +36,38 @@ class RepostItemValuation(Document): ) def validate(self): + self.validate_period_closing_voucher() self.set_status(write=False) self.reset_field_values() self.set_company() self.validate_accounts_freeze() + def validate_period_closing_voucher(self): + year_end_date = self.get_max_year_end_date(self.company) + if year_end_date and getdate(self.posting_date) <= getdate(year_end_date): + msg = f"Due to period closing, you cannot repost item valuation before {year_end_date}" + frappe.throw(_(msg)) + + @staticmethod + def get_max_year_end_date(company): + data = frappe.get_all( + "Period Closing Voucher", fields=["fiscal_year"], filters={"docstatus": 1, "company": company} + ) + + if not data: + return + + fiscal_years = [d.fiscal_year for d in data] + table = frappe.qb.DocType("Fiscal Year") + + query = ( + frappe.qb.from_(table) + .select(Max(table.year_end_date)) + .where((table.name.isin(fiscal_years)) & (table.disabled == 0)) + ).run() + + return query[0][0] if query else None + def validate_accounts_freeze(self): acc_settings = frappe.db.get_value( "Accounts Settings", From 49674585a534974208d67687c6aad8c1a601da99 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 1 May 2023 19:59:58 +0530 Subject: [PATCH 38/40] fix: handle expected_value_after_useful_life properly in asset value adjustment (backport #35117) (#35119) fix: handle expected_value_after_useful_life properly in asset value adjustment (#35117) (cherry picked from commit 80230fec3ef079b75825447a61836f8a9ce64f57) Co-authored-by: Anand Baburajan --- .../doctype/asset_value_adjustment/asset_value_adjustment.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py index 021332883d..8426ed43ff 100644 --- a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py +++ b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py @@ -150,7 +150,9 @@ class AssetValueAdjustment(Document): if d.depreciation_method in ("Straight Line", "Manual"): end_date = max(s.schedule_date for s in depr_schedule) total_days = date_diff(end_date, self.date) - rate_per_day = flt(d.value_after_depreciation) / flt(total_days) + rate_per_day = flt(d.value_after_depreciation - d.expected_value_after_useful_life) / flt( + total_days + ) from_date = self.date else: no_of_depreciations = len([s.name for s in depr_schedule if not s.journal_entry]) From 2d5ccc07b1f277ebeddc9033af19ba1878fdb734 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 1 May 2023 21:17:18 +0530 Subject: [PATCH 39/40] fix: timeout error while submitting delivery note --- erpnext/controllers/stock_controller.py | 16 +++++++--------- .../stock/doctype/delivery_note/delivery_note.py | 4 ++-- .../delivery_note_item/delivery_note_item.json | 8 +++++--- erpnext/stock/stock_ledger.py | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 479fef72c6..a27e34819d 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -329,9 +329,10 @@ class StockController(AccountsController): """Create batches if required. Called before submit""" for d in self.items: if d.get(warehouse_field) and not d.batch_no: - has_batch_no, create_new_batch = frappe.db.get_value( + has_batch_no, create_new_batch = frappe.get_cached_value( "Item", d.item_code, ["has_batch_no", "create_new_batch"] ) + if has_batch_no and create_new_batch: d.batch_no = ( frappe.get_doc( @@ -414,7 +415,7 @@ class StockController(AccountsController): "voucher_no": self.name, "voucher_detail_no": d.name, "actual_qty": (self.docstatus == 1 and 1 or -1) * flt(d.get("stock_qty")), - "stock_uom": frappe.db.get_value( + "stock_uom": frappe.get_cached_value( "Item", args.get("item_code") or d.get("item_code"), "stock_uom" ), "incoming_rate": 0, @@ -609,7 +610,7 @@ class StockController(AccountsController): def validate_customer_provided_item(self): for d in self.get("items"): # Customer Provided parts will have zero valuation rate - if frappe.db.get_value("Item", d.item_code, "is_customer_provided_item"): + if frappe.get_cached_value("Item", d.item_code, "is_customer_provided_item"): d.allow_zero_valuation_rate = 1 def set_rate_of_stock_uom(self): @@ -722,7 +723,7 @@ class StockController(AccountsController): message += _("Please adjust the qty or edit {0} to proceed.").format(rule_link) return message - def repost_future_sle_and_gle(self): + def repost_future_sle_and_gle(self, force=False): args = frappe._dict( { "posting_date": self.posting_date, @@ -733,7 +734,7 @@ class StockController(AccountsController): } ) - if future_sle_exists(args) or repost_required_for_queue(self): + if force or future_sle_exists(args) or repost_required_for_queue(self): item_based_reposting = cint( frappe.db.get_single_value("Stock Reposting Settings", "item_based_reposting") ) @@ -894,9 +895,6 @@ def future_sle_exists(args, sl_entries=None): ) for d in data: - if key not in frappe.local.future_sle: - frappe.local.future_sle[key] = frappe._dict({}) - frappe.local.future_sle[key][(d.item_code, d.warehouse)] = d.total_row return len(data) @@ -919,7 +917,7 @@ def validate_future_sle_not_exists(args, key, sl_entries=None): def get_cached_data(args, key): if key not in frappe.local.future_sle: - return False + frappe.local.future_sle[key] = frappe._dict({}) if args.get("item_code"): item_key = (args.get("item_code"), args.get("warehouse")) diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index 9f6dd24fa6..c18e851500 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -118,7 +118,7 @@ class DeliveryNote(SellingController): def so_required(self): """check in manage account if sales order required or not""" - if frappe.db.get_value("Selling Settings", None, "so_required") == "Yes": + if frappe.db.get_single_value("Selling Settings", "so_required") == "Yes": for d in self.get("items"): if not d.against_sales_order: frappe.throw(_("Sales Order required for Item {0}").format(d.item_code)) @@ -205,7 +205,7 @@ class DeliveryNote(SellingController): super(DeliveryNote, self).validate_warehouse() for d in self.get_item_list(): - if not d["warehouse"] and frappe.db.get_value("Item", d["item_code"], "is_stock_item") == 1: + if not d["warehouse"] and frappe.get_cached_value("Item", d["item_code"], "is_stock_item") == 1: frappe.throw(_("Warehouse required for stock Item {0}").format(d["item_code"])) def update_current_stock(self): diff --git a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json index 180adee0cb..e46cab0576 100644 --- a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json +++ b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json @@ -629,7 +629,8 @@ "no_copy": 1, "options": "Sales Order", "print_hide": 1, - "read_only": 1 + "read_only": 1, + "search_index": 1 }, { "fieldname": "against_sales_invoice", @@ -662,7 +663,8 @@ "label": "Against Sales Invoice Item", "no_copy": 1, "print_hide": 1, - "read_only": 1 + "read_only": 1, + "search_index": 1 }, { "fieldname": "installed_qty", @@ -854,7 +856,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2023-04-06 09:28:29.182053", + "modified": "2023-05-01 21:05:14.175640", "modified_by": "Administrator", "module": "Stock", "name": "Delivery Note Item", diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 82fc0df8de..8b517bf1e0 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -1392,7 +1392,7 @@ def regenerate_sle_for_batch_stock_reco(detail): if not frappe.db.exists( "Repost Item Valuation", {"voucher_no": doc.name, "status": "Queued", "docstatus": "1"} ): - doc.repost_future_sle_and_gle() + doc.repost_future_sle_and_gle(force=True) def get_stock_reco_qty_shift(args): From 6864b11f83a56efd8d5202d91d6f5e7080afc114 Mon Sep 17 00:00:00 2001 From: Anand Baburajan Date: Tue, 2 May 2023 20:58:22 +0530 Subject: [PATCH 40/40] fix: handle finance book properly in trial balance and general ledger (#35085) * fix: get default fb properly and handle different fb and default fb case * chore: minor UX improvement * fix: handle FBs properly in general ledger --- .../accounts/report/financial_statements.py | 11 ++++++++-- .../report/general_ledger/general_ledger.js | 3 ++- .../report/general_ledger/general_ledger.py | 22 ++++++++++++++----- .../report/trial_balance/trial_balance.py | 11 ++++++++-- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index debe655f81..76a01db714 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -538,13 +538,20 @@ def apply_additional_conditions(doctype, query, from_date, ignore_closing_entrie query = query.where(gl_entry.cost_center.isin(filters.cost_center)) if filters.get("include_default_book_entries"): + company_fb = frappe.get_cached_value("Company", filters.company, "default_finance_book") + + if filters.finance_book and company_fb and cstr(filters.finance_book) != cstr(company_fb): + frappe.throw( + _("To use a different finance book, please uncheck 'Include Default Book Entries'") + ) + query = query.where( - (gl_entry.finance_book.isin([cstr(filters.finance_book), cstr(filters.company_fb), ""])) + (gl_entry.finance_book.isin([cstr(filters.finance_book), cstr(company_fb)])) | (gl_entry.finance_book.isnull()) ) else: query = query.where( - (gl_entry.finance_book.isin([cstr(filters.company_fb), ""])) | (gl_entry.finance_book.isnull()) + (gl_entry.finance_book.isin([cstr(filters.finance_book)])) | (gl_entry.finance_book.isnull()) ) if accounting_dimensions: diff --git a/erpnext/accounts/report/general_ledger/general_ledger.js b/erpnext/accounts/report/general_ledger/general_ledger.js index 2100f26c1e..57a9091cf9 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.js +++ b/erpnext/accounts/report/general_ledger/general_ledger.js @@ -176,7 +176,8 @@ frappe.query_reports["General Ledger"] = { { "fieldname": "include_default_book_entries", "label": __("Include Default Book Entries"), - "fieldtype": "Check" + "fieldtype": "Check", + "default": 1 }, { "fieldname": "show_cancelled_entries", diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py index 27b84c4e77..0b05c11668 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.py +++ b/erpnext/accounts/report/general_ledger/general_ledger.py @@ -244,13 +244,23 @@ def get_conditions(filters): if filters.get("project"): conditions.append("project in %(project)s") - if filters.get("finance_book"): - if filters.get("include_default_book_entries"): - conditions.append( - "(finance_book in (%(finance_book)s, %(company_fb)s, '') OR finance_book IS NULL)" - ) + if filters.get("include_default_book_entries"): + if filters.get("finance_book"): + if filters.get("company_fb") and cstr(filters.get("finance_book")) != cstr( + filters.get("company_fb") + ): + frappe.throw( + _("To use a different finance book, please uncheck 'Include Default Book Entries'") + ) + else: + conditions.append("(finance_book in (%(finance_book)s) OR finance_book IS NULL)") else: - conditions.append("finance_book in (%(finance_book)s)") + conditions.append("(finance_book in (%(company_fb)s) OR finance_book IS NULL)") + else: + if filters.get("finance_book"): + conditions.append("(finance_book in (%(finance_book)s) OR finance_book IS NULL)") + else: + conditions.append("(finance_book IS NULL)") if not filters.get("show_cancelled_entries"): conditions.append("is_cancelled = 0") diff --git a/erpnext/accounts/report/trial_balance/trial_balance.py b/erpnext/accounts/report/trial_balance/trial_balance.py index 53611ab919..57dac2af49 100644 --- a/erpnext/accounts/report/trial_balance/trial_balance.py +++ b/erpnext/accounts/report/trial_balance/trial_balance.py @@ -248,13 +248,20 @@ def get_opening_balance( opening_balance = opening_balance.where(closing_balance.project == filters.project) if filters.get("include_default_book_entries"): + company_fb = frappe.get_cached_value("Company", filters.company, "default_finance_book") + + if filters.finance_book and company_fb and cstr(filters.finance_book) != cstr(company_fb): + frappe.throw( + _("To use a different finance book, please uncheck 'Include Default Book Entries'") + ) + opening_balance = opening_balance.where( - (closing_balance.finance_book.isin([cstr(filters.finance_book), cstr(filters.company_fb), ""])) + (closing_balance.finance_book.isin([cstr(filters.finance_book), cstr(company_fb)])) | (closing_balance.finance_book.isnull()) ) else: opening_balance = opening_balance.where( - (closing_balance.finance_book.isin([cstr(filters.finance_book), ""])) + (closing_balance.finance_book.isin([cstr(filters.finance_book)])) | (closing_balance.finance_book.isnull()) )