Test case for delivery to target warehouse
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index 20c734c..fc8ca63 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -8,6 +8,8 @@
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry, get_qty_after_transaction
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory
from erpnext.exceptions import InvalidAccountCurrency, InvalidCurrency
+from erpnext.stock.doctype.serial_no.serial_no import SerialNoWarehouseError
+from frappe.model.naming import make_autoname
class TestSalesInvoice(unittest.TestCase):
def make(self):
@@ -706,27 +708,22 @@
"delivery_document_no"))
def test_serialize_status(self):
- from erpnext.stock.doctype.serial_no.serial_no import SerialNoWarehouseError, get_serial_nos, SerialNoDuplicateError
- from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_item
-
- se = make_serialized_item()
- serial_nos = get_serial_nos(se.get("items")[0].serial_no)
-
- sr = frappe.get_doc("Serial No", serial_nos[0])
- sr.save()
+ serial_no = frappe.get_doc({
+ "doctype": "Serial No",
+ "item_code": "_Test Serialized Item With Series",
+ "serial_no": make_autoname("SR", "Serial No")
+ })
+ serial_no.save()
si = frappe.copy_doc(test_records[0])
si.update_stock = 1
si.get("items")[0].item_code = "_Test Serialized Item With Series"
si.get("items")[0].qty = 1
- si.get("items")[0].serial_no = serial_nos[0]
+ si.get("items")[0].serial_no = serial_no.name
si.insert()
self.assertRaises(SerialNoWarehouseError, si.submit)
- # hack! because stock ledger entires are already inserted and are not rolled back!
- self.assertRaises(SerialNoDuplicateError, si.cancel)
-
def test_invoice_due_date_against_customers_credit_days(self):
# set customer's credit days
frappe.db.set_value("Customer", "_Test Customer", "credit_days_based_on", "Fixed Days")
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index 75be4d6..b087b8a 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -186,7 +186,7 @@
'batch_no': cstr(d.get("batch_no")).strip(),
'serial_no': cstr(d.get("serial_no")).strip(),
'name': d.name,
- 'target_warehouse': p.target_warehouse
+ 'target_warehouse': d.target_warehouse
}))
return il
diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.py b/erpnext/stock/doctype/delivery_note/test_delivery_note.py
index d233d6b..af52c7a 100644
--- a/erpnext/stock/doctype/delivery_note/test_delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.py
@@ -164,11 +164,16 @@
})
def test_serialize_status(self):
- se = make_serialized_item()
- serial_no = get_serial_nos(se.get("items")[0].serial_no)[0]
+ from frappe.model.naming import make_autoname
+ serial_no = frappe.get_doc({
+ "doctype": "Serial No",
+ "item_code": "_Test Serialized Item With Series",
+ "serial_no": make_autoname("SR", "Serial No")
+ })
+ serial_no.save()
dn = create_delivery_note(item_code="_Test Serialized Item With Series",
- serial_no=serial_no, do_not_submit=True)
+ serial_no=serial_no.name, do_not_submit=True)
self.assertRaises(SerialNoWarehouseError, dn.submit)
@@ -318,7 +323,54 @@
"delivery_document_no": "",
"purchase_document_no": se.name
})
+
+ def test_delivery_of_bundled_items_to_target_warehouse(self):
+ set_perpetual_inventory()
+
+ create_stock_reconciliation(item_code="_Test Item", target="_Test Warehouse - _TC", qty=50, rate=100)
+ create_stock_reconciliation(item_code="_Test Item Home Desktop 100", target="_Test Warehouse - _TC",
+ qty=50, rate=100)
+
+ opening_qty_test_warehouse_1 = get_qty_after_transaction(warehouse="_Test Warehouse 1 - _TC")
+
+ dn = create_delivery_note(item_code="_Test Product Bundle Item",
+ qty=5, rate=500, target_warehouse="_Test Warehouse 1 - _TC")
+
+ # qty after delivery
+ actual_qty = get_qty_after_transaction(warehouse="_Test Warehouse - _TC")
+ self.assertEquals(actual_qty, 25)
+
+ actual_qty = get_qty_after_transaction(warehouse="_Test Warehouse 1 - _TC")
+ self.assertEquals(actual_qty, opening_qty_test_warehouse_1 + 25)
+
+ # stock value diff for source warehouse
+ stock_value_difference = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Delivery Note",
+ "voucher_no": dn.name, "item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC"},
+ "stock_value_difference")
+
+ # stock value diff for target warehouse
+ stock_value_difference1 = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Delivery Note",
+ "voucher_no": dn.name, "item_code": "_Test Item", "warehouse": "_Test Warehouse 1 - _TC"},
+ "stock_value_difference")
+ self.assertEquals(abs(stock_value_difference), stock_value_difference1)
+ # Check gl entries
+ gl_entries = get_gl_entries("Delivery Note", dn.name)
+ self.assertTrue(gl_entries)
+
+ stock_value_difference = abs(frappe.db.sql("""select sum(stock_value_difference)
+ from `tabStock Ledger Entry` where voucher_type='Delivery Note' and voucher_no=%s
+ and warehouse='_Test Warehouse - _TC'""", dn.name)[0][0])
+
+ expected_values = {
+ "_Test Warehouse - _TC": [0.0, stock_value_difference],
+ "_Test Warehouse 1 - _TC": [stock_value_difference, 0.0]
+ }
+ for i, gle in enumerate(gl_entries):
+ self.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account))
+
+ set_perpetual_inventory(0)
+
def create_delivery_note(**args):
dn = frappe.new_doc("Delivery Note")
args = frappe._dict(args)
@@ -341,7 +393,8 @@
"conversion_factor": 1.0,
"expense_account": "Cost of Goods Sold - _TC",
"cost_center": "_Test Cost Center - _TC",
- "serial_no": args.serial_no
+ "serial_no": args.serial_no,
+ "target_warehouse": args.target_warehouse
})
if not args.do_not_save:
diff --git a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py
index af569f8..89f3ad5 100644
--- a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py
+++ b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py
@@ -65,9 +65,8 @@
self.submit_landed_cost_voucher(pr)
serial_no = frappe.db.get_value("Serial No", "SN001",
- ["status", "warehouse", "purchase_rate"], as_dict=1)
+ ["warehouse", "purchase_rate"], as_dict=1)
- self.assertEquals(serial_no.status, "Available")
self.assertEquals(serial_no.purchase_rate - serial_no_rate, 5.0)
self.assertEquals(serial_no.warehouse, "_Test Warehouse - _TC")