Merge pull request #33013 from rtdany10/riv-validation

fix: validate repost item valuation against accounts freeze date
This commit is contained in:
rohitwaghchaure 2022-11-29 10:40:48 +05:30 committed by GitHub
commit 6dd84cb977
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 2 deletions

View File

@ -5,7 +5,7 @@ import frappe
from frappe import _
from frappe.exceptions import QueryDeadlockError, QueryTimeoutError
from frappe.model.document import Document
from frappe.utils import cint, get_link_to_form, get_weekday, now, nowtime
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
@ -25,6 +25,27 @@ class RepostItemValuation(Document):
self.set_status(write=False)
self.reset_field_values()
self.set_company()
self.validate_accounts_freeze()
def validate_accounts_freeze(self):
acc_settings = frappe.db.get_value(
"Accounts Settings",
"Accounts Settings",
["acc_frozen_upto", "frozen_accounts_modifier"],
as_dict=1,
)
if not acc_settings.acc_frozen_upto:
return
if getdate(self.posting_date) <= getdate(acc_settings.acc_frozen_upto):
if (
acc_settings.frozen_accounts_modifier
and frappe.session.user in get_users_with_role(acc_settings.frozen_accounts_modifier)
):
frappe.msgprint(_("Caution: This might alter frozen accounts."))
return
frappe.throw(
_("You cannot repost item valuation before {}").format(acc_settings.acc_frozen_upto)
)
def reset_field_values(self):
if self.based_on == "Transaction":
@ -240,7 +261,7 @@ def _get_directly_dependent_vouchers(doc):
def notify_error_to_stock_managers(doc, traceback):
recipients = get_users_with_role("Stock Manager")
if not recipients:
get_users_with_role("System Manager")
recipients = get_users_with_role("System Manager")
subject = _("Error while reposting item valuation")
message = (

View File

@ -327,3 +327,26 @@ class TestRepostItemValuation(FrappeTestCase, StockTestMixin):
# outstanding should not be affected
sinv.reload()
self.assertEqual(sinv.outstanding_amount, 100)
def test_account_freeze_validation(self):
today = nowdate()
riv = frappe.get_doc(
doctype="Repost Item Valuation",
item_code="_Test Item",
warehouse="_Test Warehouse - _TC",
based_on="Item and Warehouse",
posting_date=today,
posting_time="00:01:00",
)
riv.flags.dont_run_in_test = True # keep it queued
accounts_settings = frappe.get_doc("Accounts Settings")
accounts_settings.acc_frozen_upto = today
accounts_settings.frozen_accounts_modifier = ""
accounts_settings.save()
self.assertRaises(frappe.ValidationError, riv.save)
accounts_settings.acc_frozen_upto = ""
accounts_settings.save()