Skip to content

Commit

Permalink
fix: process only SLEs against actual voucher
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed May 6, 2022
1 parent ee7a7eb commit 1f5be88
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,42 @@ def ordered_qty_after_transaction():
backdated.cancel()
self.assertEqual([1], ordered_qty_after_transaction())

def test_timestamp_clash(self):

item = make_item().name
warehouse = "_Test Warehouse - _TC"

reciept = make_stock_entry(
item_code=item,
to_warehouse=warehouse,
qty=100,
rate=10,
posting_date="2021-01-01",
posting_time="01:00:00",
)

consumption = make_stock_entry(
item_code=item,
from_warehouse=warehouse,
qty=50,
posting_date="2021-01-01",
posting_time="02:00:00.1234", # ms are possible when submitted without editing posting time
)

backdated_receipt = make_stock_entry(
item_code=item,
to_warehouse=warehouse,
qty=100,
posting_date="2021-01-01",
rate=10,
posting_time="02:00:00", # same posting time as consumption but ms part stripped
)

try:
backdated_receipt.cancel()
except Exception as e:
self.fail("Double processing of qty for clashing timestamp.")


def create_repack_entry(**args):
args = frappe._dict(args)
Expand Down
2 changes: 2 additions & 0 deletions erpnext/stock/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ def get_sle_against_current_voucher(self):
where
item_code = %(item_code)s
and warehouse = %(warehouse)s
and voucher_no = %(voucher_no)s
and voucher_type = %(voucher_type)s
and is_cancelled = 0
and timestamp(posting_date, time_format(posting_time, %(time_format)s)) = timestamp(%(posting_date)s, time_format(%(posting_time)s, %(time_format)s))
Expand Down

0 comments on commit 1f5be88

Please sign in to comment.