feat: Immutable ledger (#18740)
* fix: Reverse GL entry on cancellation of document
* fix: Removed set posting time field for multiple docs
* fix: Stop future reposting and reverse entry for purchase receipt and delivery note
* fix: Change is_cancelled field from select to check
* Revert "fix: Removed set posting time field for multiple docs"
This reverts commit 81fb808db7.
* fix: Multiple fixes in GL Entry
* fix: Remove future reporting from doctypes
* fix: Canceled entry filters in Stock Ledger and General Ledger Report
* fix: Remove print statement
* fix: Validation for back dated entries
* fix: Codacy fixes
* fix: Add ignore links to multiple doctypes
* fix: Codacy Fixes
* fix: Ignore GL Entry and Stock Ledger entry while cancel
* fix: Test case fixes
* fix: Patch
* fix: Codacy
* fix: Budget Test Cases
* fix: Patch
* fix: Patch
* fix: Multiple test cases
* fix: changes in make_reverse_entry function
* fix: Update patch
* fix: Test Cases
* fix: Test Case fixes
* fix: Move patch upward in patches.txt
* fix: Budget Test Cases
* fix: Test Case and codacy
* fix: Patch
* fix: Minor label and UX fixes
* fix: Move freezing date check
* fix: Test Cases
* fix: Test cases
* fix: Test Cases
* fix: Test Case
* fix: Remove update_gl_entries_after function
* fix: Remove update_gl_entries_after function
* fix: Test Cases
* fix: Fiscal Year wise backdated entry
* fix: Update entries only for current SLE
* fix: Remove is_cancelled
* fix: Test Cases
* fix: Test cases
* fix: Test Cases
* fix: Uncomment account and stock balance sync logic
* fix: Stock balance and Account balance out of sync fixes
* fix: Test Cases
* fix: Test cases for POS, Stock Reco and Purchase Receipt
* fix: Stock Reco tests
* fix: Test stock reco precision
* fix: Test stock reco for fifo precision
* fix: Test stock reco for fifo precision
* fix: Stock Entry test case
Co-authored-by: Nabin Hait <nabinhait@gmail.com>
This commit is contained in:
@@ -5,8 +5,9 @@ from __future__ import unicode_literals
|
||||
import frappe
|
||||
import frappe.share
|
||||
from frappe import _
|
||||
from frappe.utils import cstr, now_datetime, cint, flt, get_time, get_link_to_form
|
||||
from frappe.utils import cstr, now_datetime, cint, flt, get_time, get_datetime, get_link_to_form
|
||||
from erpnext.controllers.status_updater import StatusUpdater
|
||||
from erpnext.accounts.utils import get_fiscal_year
|
||||
|
||||
from six import string_types
|
||||
|
||||
@@ -28,6 +29,8 @@ class TransactionBase(StatusUpdater):
|
||||
except ValueError:
|
||||
frappe.throw(_('Invalid Posting Time'))
|
||||
|
||||
self.validate_with_last_transaction_posting_time()
|
||||
|
||||
def add_calendar_event(self, opts, force=False):
|
||||
if cstr(self.contact_by) != cstr(self._prev.contact_by) or \
|
||||
cstr(self.contact_date) != cstr(self._prev.contact_date) or force or \
|
||||
@@ -148,6 +151,30 @@ class TransactionBase(StatusUpdater):
|
||||
|
||||
return ret
|
||||
|
||||
def validate_with_last_transaction_posting_time(self):
|
||||
|
||||
if self.doctype not in ["Sales Invoice", "Purchase Invoice", "Stock Entry", "Stock Reconciliation",
|
||||
"Delivery Note", "Purchase Receipt", "Fees"]:
|
||||
return
|
||||
|
||||
if self.doctype in ["Sales Invoice", "Purchase Invoice"]:
|
||||
if not (self.get("update_stock") or self.get("is_pos")):
|
||||
return
|
||||
|
||||
fiscal_year = get_fiscal_year(self.get('posting_date'), as_dict=True).name
|
||||
|
||||
last_transaction_time = frappe.db.sql("""
|
||||
select MAX(timestamp(posting_date, posting_time)) as posting_time
|
||||
from `tabStock Ledger Entry`
|
||||
where docstatus = 1 and fiscal_year = %s""", (fiscal_year))[0][0]
|
||||
|
||||
cur_doc_posting_datetime = "%s %s" % (self.posting_date, self.get("posting_time") or "00:00:00")
|
||||
|
||||
if last_transaction_time and get_datetime(cur_doc_posting_datetime) < get_datetime(last_transaction_time):
|
||||
frappe.throw(_("""Posting timestamp of current transaction
|
||||
must be after last Stock transaction's timestamp which is {0}""").format(frappe.bold(last_transaction_time)),
|
||||
title=_("Backdated Stock Entry"))
|
||||
|
||||
def delete_events(ref_type, ref_name):
|
||||
events = frappe.db.sql_list(""" SELECT
|
||||
distinct `tabEvent`.name
|
||||
|
||||
Reference in New Issue
Block a user