fix: unsupported operand type(s) for serial and batch bundle in POS Invoice (#37721)
This commit is contained in:
parent
d99a56bc27
commit
fd78f868e1
@ -771,19 +771,28 @@ class TestPOSInvoice(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
create_batch_item_with_batch("_BATCH ITEM Test For Reserve", "TestBatch-RS 02")
|
create_batch_item_with_batch("_BATCH ITEM Test For Reserve", "TestBatch-RS 02")
|
||||||
make_stock_entry(
|
se = make_stock_entry(
|
||||||
target="_Test Warehouse - _TC",
|
target="_Test Warehouse - _TC",
|
||||||
item_code="_BATCH ITEM Test For Reserve",
|
item_code="_BATCH ITEM Test For Reserve",
|
||||||
qty=20,
|
qty=30,
|
||||||
basic_rate=100,
|
basic_rate=100,
|
||||||
batch_no="TestBatch-RS 02",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
se.reload()
|
||||||
|
|
||||||
|
batch_no = get_batch_from_bundle(se.items[0].serial_and_batch_bundle)
|
||||||
|
|
||||||
|
# POS Invoice 1, for the batch without bundle
|
||||||
pos_inv1 = create_pos_invoice(
|
pos_inv1 = create_pos_invoice(
|
||||||
item="_BATCH ITEM Test For Reserve", rate=300, qty=15, batch_no="TestBatch-RS 02"
|
item="_BATCH ITEM Test For Reserve", rate=300, qty=15, do_not_save=1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
pos_inv1.items[0].batch_no = batch_no
|
||||||
pos_inv1.save()
|
pos_inv1.save()
|
||||||
pos_inv1.submit()
|
pos_inv1.submit()
|
||||||
|
pos_inv1.reload()
|
||||||
|
|
||||||
|
self.assertFalse(pos_inv1.items[0].serial_and_batch_bundle)
|
||||||
|
|
||||||
batches = get_auto_batch_nos(
|
batches = get_auto_batch_nos(
|
||||||
frappe._dict(
|
frappe._dict(
|
||||||
@ -792,7 +801,24 @@ class TestPOSInvoice(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for batch in batches:
|
for batch in batches:
|
||||||
if batch.batch_no == "TestBatch-RS 02" and batch.warehouse == "_Test Warehouse - _TC":
|
if batch.batch_no == batch_no and batch.warehouse == "_Test Warehouse - _TC":
|
||||||
|
self.assertEqual(batch.qty, 15)
|
||||||
|
|
||||||
|
# POS Invoice 2, for the batch with bundle
|
||||||
|
pos_inv2 = create_pos_invoice(
|
||||||
|
item="_BATCH ITEM Test For Reserve", rate=300, qty=10, batch_no=batch_no
|
||||||
|
)
|
||||||
|
pos_inv2.reload()
|
||||||
|
self.assertTrue(pos_inv2.items[0].serial_and_batch_bundle)
|
||||||
|
|
||||||
|
batches = get_auto_batch_nos(
|
||||||
|
frappe._dict(
|
||||||
|
{"item_code": "_BATCH ITEM Test For Reserve", "warehouse": "_Test Warehouse - _TC"}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
for batch in batches:
|
||||||
|
if batch.batch_no == batch_no and batch.warehouse == "_Test Warehouse - _TC":
|
||||||
self.assertEqual(batch.qty, 5)
|
self.assertEqual(batch.qty, 5)
|
||||||
|
|
||||||
def test_pos_batch_item_qty_validation(self):
|
def test_pos_batch_item_qty_validation(self):
|
||||||
|
@ -1301,6 +1301,7 @@ def get_reserved_batches_for_pos(kwargs) -> dict:
|
|||||||
"POS Invoice",
|
"POS Invoice",
|
||||||
fields=[
|
fields=[
|
||||||
"`tabPOS Invoice Item`.batch_no",
|
"`tabPOS Invoice Item`.batch_no",
|
||||||
|
"`tabPOS Invoice Item`.qty",
|
||||||
"`tabPOS Invoice`.is_return",
|
"`tabPOS Invoice`.is_return",
|
||||||
"`tabPOS Invoice Item`.warehouse",
|
"`tabPOS Invoice Item`.warehouse",
|
||||||
"`tabPOS Invoice Item`.name as child_docname",
|
"`tabPOS Invoice Item`.name as child_docname",
|
||||||
@ -1321,9 +1322,6 @@ def get_reserved_batches_for_pos(kwargs) -> dict:
|
|||||||
if pos_invoice.serial_and_batch_bundle
|
if pos_invoice.serial_and_batch_bundle
|
||||||
]
|
]
|
||||||
|
|
||||||
if not ids:
|
|
||||||
return {}
|
|
||||||
|
|
||||||
if ids:
|
if ids:
|
||||||
for d in get_serial_batch_ledgers(kwargs.item_code, docstatus=1, name=ids):
|
for d in get_serial_batch_ledgers(kwargs.item_code, docstatus=1, name=ids):
|
||||||
key = (d.batch_no, d.warehouse)
|
key = (d.batch_no, d.warehouse)
|
||||||
@ -1337,6 +1335,7 @@ def get_reserved_batches_for_pos(kwargs) -> dict:
|
|||||||
else:
|
else:
|
||||||
pos_batches[key].qty += d.qty
|
pos_batches[key].qty += d.qty
|
||||||
|
|
||||||
|
# POS invoices having batch without bundle (to handle old POS invoices)
|
||||||
for row in pos_invoices:
|
for row in pos_invoices:
|
||||||
if not row.batch_no:
|
if not row.batch_no:
|
||||||
continue
|
continue
|
||||||
@ -1346,11 +1345,11 @@ def get_reserved_batches_for_pos(kwargs) -> dict:
|
|||||||
|
|
||||||
key = (row.batch_no, row.warehouse)
|
key = (row.batch_no, row.warehouse)
|
||||||
if key in pos_batches:
|
if key in pos_batches:
|
||||||
pos_batches[key] -= row.qty * -1 if row.is_return else row.qty
|
pos_batches[key]["qty"] -= row.qty * -1 if row.is_return else row.qty
|
||||||
else:
|
else:
|
||||||
pos_batches[key] = frappe._dict(
|
pos_batches[key] = frappe._dict(
|
||||||
{
|
{
|
||||||
"qty": (row.qty * -1 if row.is_return else row.qty),
|
"qty": (row.qty * -1 if not row.is_return else row.qty),
|
||||||
"warehouse": row.warehouse,
|
"warehouse": row.warehouse,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user