parent
afc6aa88f0
commit
d6a43a39ae
@ -2,12 +2,12 @@
|
|||||||
# See license.txt
|
# See license.txt
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from datetime import timedelta
|
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.core.page.permission_manager.permission_manager import reset
|
from frappe.core.page.permission_manager.permission_manager import reset
|
||||||
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
|
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
|
||||||
|
from frappe.query_builder.functions import CombineDatetime
|
||||||
from frappe.tests.utils import FrappeTestCase
|
from frappe.tests.utils import FrappeTestCase
|
||||||
from frappe.utils import add_days, today
|
from frappe.utils import add_days, today
|
||||||
from frappe.utils.data import add_to_date
|
from frappe.utils.data import add_to_date
|
||||||
@ -1126,6 +1126,63 @@ class TestStockLedgerEntry(FrappeTestCase):
|
|||||||
# original amount
|
# original amount
|
||||||
self.assertEqual(50, _get_stock_credit(final_consumption))
|
self.assertEqual(50, _get_stock_credit(final_consumption))
|
||||||
|
|
||||||
|
def test_tie_breaking(self):
|
||||||
|
frappe.flags.dont_execute_stock_reposts = True
|
||||||
|
self.addCleanup(frappe.flags.pop, "dont_execute_stock_reposts")
|
||||||
|
|
||||||
|
item = make_item().name
|
||||||
|
warehouse = "_Test Warehouse - _TC"
|
||||||
|
|
||||||
|
posting_date = "2022-01-01"
|
||||||
|
posting_time = "00:00:01"
|
||||||
|
sle = frappe.qb.DocType("Stock Ledger Entry")
|
||||||
|
|
||||||
|
def ordered_qty_after_transaction():
|
||||||
|
return (
|
||||||
|
frappe.qb.from_(sle)
|
||||||
|
.select("qty_after_transaction")
|
||||||
|
.where((sle.item_code == item) & (sle.warehouse == warehouse) & (sle.is_cancelled == 0))
|
||||||
|
.orderby(CombineDatetime(sle.posting_date, sle.posting_time))
|
||||||
|
.orderby(sle.creation)
|
||||||
|
).run(pluck=True)
|
||||||
|
|
||||||
|
first = make_stock_entry(
|
||||||
|
item_code=item,
|
||||||
|
to_warehouse=warehouse,
|
||||||
|
qty=10,
|
||||||
|
posting_time=posting_time,
|
||||||
|
posting_date=posting_date,
|
||||||
|
do_not_submit=True,
|
||||||
|
)
|
||||||
|
second = make_stock_entry(
|
||||||
|
item_code=item,
|
||||||
|
to_warehouse=warehouse,
|
||||||
|
qty=1,
|
||||||
|
posting_date=posting_date,
|
||||||
|
posting_time=posting_time,
|
||||||
|
do_not_submit=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
first.submit()
|
||||||
|
second.submit()
|
||||||
|
|
||||||
|
self.assertEqual([10, 11], ordered_qty_after_transaction())
|
||||||
|
|
||||||
|
first.cancel()
|
||||||
|
self.assertEqual([1], ordered_qty_after_transaction())
|
||||||
|
|
||||||
|
backdated = make_stock_entry(
|
||||||
|
item_code=item,
|
||||||
|
to_warehouse=warehouse,
|
||||||
|
qty=1,
|
||||||
|
posting_date="2021-01-01",
|
||||||
|
posting_time=posting_time,
|
||||||
|
)
|
||||||
|
self.assertEqual([1, 2], ordered_qty_after_transaction())
|
||||||
|
|
||||||
|
backdated.cancel()
|
||||||
|
self.assertEqual([1], ordered_qty_after_transaction())
|
||||||
|
|
||||||
|
|
||||||
def create_repack_entry(**args):
|
def create_repack_entry(**args):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user