From e64751e3a244e4099223d2bddf32342ea0a2beef Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 13 Oct 2021 16:41:21 +0530 Subject: [PATCH] fix: not authorized to update entries after freezing accounts (backport #27937) * fix: not authorized to update entries after freezing accounts (#27937) * fix: not authorized to update entries after freezing accounts * fix: Add test case * fix(patch): patched to requeue failed reposts(check_freezing_date) * chore: misc fixes Co-authored-by: Deepesh Garg Co-authored-by: Ankush Menat (cherry picked from commit 2bb383b178314e096488764c04182f35fca17d64) # Conflicts: # erpnext/patches.txt * fix: resolve conflict Co-authored-by: Noah Jacob Co-authored-by: Ankush Menat --- .../doctype/sales_invoice/test_sales_invoice.py | 12 ++++++++++++ erpnext/accounts/general_ledger.py | 2 +- erpnext/patches.txt | 1 + erpnext/patches/v13_0/requeue_failed_reposts.py | 13 +++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 erpnext/patches/v13_0/requeue_failed_reposts.py diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 530ba4fb8d6..89fbfc0ea0f 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -2327,6 +2327,18 @@ class TestSalesInvoice(unittest.TestCase): si.reload() self.assertEqual(si.status, "Paid") + def test_sales_invoice_submission_post_account_freezing_date(self): + frappe.db.set_value('Accounts Settings', None, 'acc_frozen_upto', add_days(getdate(), 1)) + si = create_sales_invoice(do_not_save=True) + si.posting_date = add_days(getdate(), 1) + si.save() + + self.assertRaises(frappe.ValidationError, si.submit) + si.posting_date = getdate() + si.submit() + + frappe.db.set_value('Accounts Settings', None, 'acc_frozen_upto', None) + def get_sales_invoice_for_e_invoice(): si = make_sales_invoice_for_ewaybill() si.naming_series = 'INV-2020-.#####' diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 0cee6f5b3aa..0cae16bc51a 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -293,7 +293,7 @@ def check_freezing_date(posting_date, adv_adj=False): if acc_frozen_upto: frozen_accounts_modifier = frappe.db.get_value( 'Accounts Settings', None,'frozen_accounts_modifier') if getdate(posting_date) <= getdate(acc_frozen_upto) \ - and not frozen_accounts_modifier in frappe.get_roles() or frappe.session.user == 'Administrator': + and (frozen_accounts_modifier not in frappe.get_roles() or frappe.session.user == 'Administrator'): frappe.throw(_("You are not authorized to add or update entries before {0}").format(formatdate(acc_frozen_upto))) def set_as_cancel(voucher_type, voucher_no): diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 42aa8c62ef3..f457ceeb2c6 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -323,3 +323,4 @@ erpnext.patches.v13_0.shopping_cart_to_ecommerce erpnext.patches.v13_0.set_status_in_maintenance_schedule_table erpnext.patches.v13_0.add_default_interview_notification_templates erpnext.patches.v13_0.trim_sales_invoice_custom_field_length +erpnext.patches.v13_0.requeue_failed_reposts diff --git a/erpnext/patches/v13_0/requeue_failed_reposts.py b/erpnext/patches/v13_0/requeue_failed_reposts.py new file mode 100644 index 00000000000..213cb9e26e4 --- /dev/null +++ b/erpnext/patches/v13_0/requeue_failed_reposts.py @@ -0,0 +1,13 @@ +import frappe +from frappe.utils import cstr + + +def execute(): + + reposts = frappe.get_all("Repost Item Valuation", + {"status": "Failed", "modified": [">", "2021-10-05"] }, + ["name", "modified", "error_log"]) + + for repost in reposts: + if "check_freezing_date" in cstr(repost.error_log): + frappe.db.set_value("Repost Item Valuation", repost.name, "status", "Queued")