Skip to content

Commit

Permalink
feat: validate repost item valuation against accounts freeze date
Browse files Browse the repository at this point in the history
(cherry picked from commit 61f0513)
  • Loading branch information
rtdany10 authored and mergify[bot] committed Nov 29, 2022
1 parent e093c32 commit 04f50ea
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Expand Up @@ -5,7 +5,7 @@
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

Expand All @@ -25,6 +25,21 @@ def validate(self):
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 acc_settings.frozen_accounts_modifier and self.owner in get_users_with_role(acc_settings.frozen_accounts_modifier):
return
if getdate(self.posting_date) <= getdate(acc_settings.acc_frozen_upto):
frappe.throw(_("You cannot repost item valuation before {}").format(acc_settings.acc_frozen_upto))

def reset_field_values(self):
if self.based_on == "Transaction":
Expand Down Expand Up @@ -240,7 +255,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 = (
Expand Down
Expand Up @@ -327,3 +327,26 @@ def test_duplicate_ple_on_repost(self):
# 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()

0 comments on commit 04f50ea

Please sign in to comment.