mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-23 06:59:20 +00:00
test: Stock Ageing FIFO Slot generation
This commit is contained in:
@@ -292,7 +292,7 @@ class FIFOSlots:
|
|||||||
fifo_queue[0][0] += flt(row.actual_qty)
|
fifo_queue[0][0] += flt(row.actual_qty)
|
||||||
fifo_queue[0][1] = row.posting_date
|
fifo_queue[0][1] = row.posting_date
|
||||||
else:
|
else:
|
||||||
fifo_queue.append([row.actual_qty, row.posting_date])
|
fifo_queue.append([flt(row.actual_qty), row.posting_date])
|
||||||
return
|
return
|
||||||
|
|
||||||
for serial_no in serial_nos:
|
for serial_no in serial_nos:
|
||||||
@@ -395,10 +395,10 @@ class FIFOSlots:
|
|||||||
|
|
||||||
warehouse_results = (
|
warehouse_results = (
|
||||||
frappe.qb.from_(warehouse)
|
frappe.qb.from_(warehouse)
|
||||||
.select("name").where(
|
.select("name").where(
|
||||||
(warehouse.lft >= lft)
|
(warehouse.lft >= lft)
|
||||||
& (warehouse.rgt <= rgt)
|
& (warehouse.rgt <= rgt)
|
||||||
).run()
|
).run()
|
||||||
)
|
)
|
||||||
warehouse_results = [x[0] for x in warehouse_results]
|
warehouse_results = [x[0] for x in warehouse_results]
|
||||||
|
|
||||||
|
|||||||
125
erpnext/stock/report/stock_ageing/test_stock_ageing.py
Normal file
125
erpnext/stock/report/stock_ageing/test_stock_ageing.py
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
|
# See license.txt
|
||||||
|
|
||||||
|
import frappe
|
||||||
|
|
||||||
|
from erpnext.stock.report.stock_ageing.stock_ageing import FIFOSlots
|
||||||
|
from erpnext.tests.utils import ERPNextTestCase
|
||||||
|
|
||||||
|
class TestStockAgeing(ERPNextTestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.filters = frappe._dict(
|
||||||
|
company="_Test Company",
|
||||||
|
to_date="2021-12-10"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_normal_inward_outward_queue(self):
|
||||||
|
"Reference: Case 1 in stock_ageing_fifo_logic.md"
|
||||||
|
sle = [
|
||||||
|
frappe._dict(
|
||||||
|
name="Flask Item",
|
||||||
|
actual_qty=30, qty_after_transaction=30,
|
||||||
|
posting_date="2021-12-01", voucher_type="Stock Entry",
|
||||||
|
voucher_no="001",
|
||||||
|
has_serial_no=False, serial_no=None
|
||||||
|
),
|
||||||
|
frappe._dict(
|
||||||
|
name="Flask Item",
|
||||||
|
actual_qty=20, qty_after_transaction=50,
|
||||||
|
posting_date="2021-12-02", voucher_type="Stock Entry",
|
||||||
|
voucher_no="002",
|
||||||
|
has_serial_no=False, serial_no=None
|
||||||
|
),
|
||||||
|
frappe._dict(
|
||||||
|
name="Flask Item",
|
||||||
|
actual_qty=(-10), qty_after_transaction=40,
|
||||||
|
posting_date="2021-12-03", voucher_type="Stock Entry",
|
||||||
|
voucher_no="003",
|
||||||
|
has_serial_no=False, serial_no=None
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
slots = FIFOSlots(self.filters, sle).generate()
|
||||||
|
|
||||||
|
self.assertTrue(slots["Flask Item"]["fifo_queue"])
|
||||||
|
result = slots["Flask Item"]
|
||||||
|
queue = result["fifo_queue"]
|
||||||
|
|
||||||
|
self.assertEqual(result["qty_after_transaction"], result["total_qty"])
|
||||||
|
self.assertEqual(queue[0][0], 20.0)
|
||||||
|
|
||||||
|
def test_insufficient_balance(self):
|
||||||
|
"Reference: Case 3 in stock_ageing_fifo_logic.md"
|
||||||
|
sle = [
|
||||||
|
frappe._dict(
|
||||||
|
name="Flask Item",
|
||||||
|
actual_qty=(-30), qty_after_transaction=(-30),
|
||||||
|
posting_date="2021-12-01", voucher_type="Stock Entry",
|
||||||
|
voucher_no="001",
|
||||||
|
has_serial_no=False, serial_no=None
|
||||||
|
),
|
||||||
|
frappe._dict(
|
||||||
|
name="Flask Item",
|
||||||
|
actual_qty=20, qty_after_transaction=(-10),
|
||||||
|
posting_date="2021-12-02", voucher_type="Stock Entry",
|
||||||
|
voucher_no="002",
|
||||||
|
has_serial_no=False, serial_no=None
|
||||||
|
),
|
||||||
|
frappe._dict(
|
||||||
|
name="Flask Item",
|
||||||
|
actual_qty=20, qty_after_transaction=10,
|
||||||
|
posting_date="2021-12-03", voucher_type="Stock Entry",
|
||||||
|
voucher_no="003",
|
||||||
|
has_serial_no=False, serial_no=None
|
||||||
|
),
|
||||||
|
frappe._dict(
|
||||||
|
name="Flask Item",
|
||||||
|
actual_qty=10, qty_after_transaction=20,
|
||||||
|
posting_date="2021-12-03", voucher_type="Stock Entry",
|
||||||
|
voucher_no="004",
|
||||||
|
has_serial_no=False, serial_no=None
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
slots = FIFOSlots(self.filters, sle).generate()
|
||||||
|
|
||||||
|
result = slots["Flask Item"]
|
||||||
|
queue = result["fifo_queue"]
|
||||||
|
|
||||||
|
self.assertEqual(result["qty_after_transaction"], result["total_qty"])
|
||||||
|
self.assertEqual(queue[0][0], 10.0)
|
||||||
|
self.assertEqual(queue[1][0], 10.0)
|
||||||
|
|
||||||
|
def test_stock_reconciliation(self):
|
||||||
|
sle = [
|
||||||
|
frappe._dict(
|
||||||
|
name="Flask Item",
|
||||||
|
actual_qty=30, qty_after_transaction=30,
|
||||||
|
posting_date="2021-12-01", voucher_type="Stock Entry",
|
||||||
|
voucher_no="001",
|
||||||
|
has_serial_no=False, serial_no=None
|
||||||
|
),
|
||||||
|
frappe._dict(
|
||||||
|
name="Flask Item",
|
||||||
|
actual_qty=0, qty_after_transaction=50,
|
||||||
|
posting_date="2021-12-02", voucher_type="Stock Reconciliation",
|
||||||
|
voucher_no="002",
|
||||||
|
has_serial_no=False, serial_no=None
|
||||||
|
),
|
||||||
|
frappe._dict(
|
||||||
|
name="Flask Item",
|
||||||
|
actual_qty=(-10), qty_after_transaction=40,
|
||||||
|
posting_date="2021-12-03", voucher_type="Stock Entry",
|
||||||
|
voucher_no="003",
|
||||||
|
has_serial_no=False, serial_no=None
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
slots = FIFOSlots(self.filters, sle).generate()
|
||||||
|
|
||||||
|
result = slots["Flask Item"]
|
||||||
|
queue = result["fifo_queue"]
|
||||||
|
|
||||||
|
self.assertEqual(result["qty_after_transaction"], result["total_qty"])
|
||||||
|
self.assertEqual(queue[0][0], 20.0)
|
||||||
|
self.assertEqual(queue[1][0], 20.0)
|
||||||
Reference in New Issue
Block a user