test: Add test case for opening stock entry gle
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry_utils.py b/erpnext/stock/doctype/stock_entry/stock_entry_utils.py
index 49a3095..b78c6be 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry_utils.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry_utils.py
@@ -89,10 +89,11 @@
s.purchase_receipt_no = args.purchase_receipt_no
s.delivery_note_no = args.delivery_note_no
s.sales_invoice_no = args.sales_invoice_no
+ s.is_opening = args.is_opening or "No"
if not args.cost_center:
args.cost_center = frappe.get_value('Company', s.company, 'cost_center')
- if not args.expense_account:
+ if not args.expense_account and s.is_opening == "No":
args.expense_account = frappe.get_value('Company', s.company, 'stock_adjustment_account')
# We can find out the serial number using the batch source document
diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py
index d7808c2..3fa815d 100644
--- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py
@@ -6,8 +6,7 @@
import frappe.defaults
from frappe.utils import flt, nowdate, nowtime
from erpnext.stock.doctype.serial_no.serial_no import *
-from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt \
- import set_perpetual_inventory
+from erpnext import set_perpetual_inventory
from erpnext.stock.doctype.stock_ledger_entry.stock_ledger_entry import StockFreezeError
from erpnext.stock.stock_ledger import get_previous_sle
from frappe.permissions import add_user_permission, remove_user_permission
@@ -16,6 +15,7 @@
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
from erpnext.accounts.doctype.account.test_account import get_inventory_account
from erpnext.stock.doctype.stock_entry.stock_entry import move_sample_to_retention_warehouse, make_stock_in_entry
+from erpnext.stock.doctype.stock_reconciliation.stock_reconciliation import OpeningEntryAccountError
from six import iteritems
@@ -772,6 +772,22 @@
doc = frappe.get_doc('Stock Entry', outward_entry.name)
self.assertEqual(doc.per_transferred, 100)
+ def test_gle_for_opening_stock_entry(self):
+ set_perpetual_inventory(1)
+
+ mr = make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC",
+ qty=50, basic_rate=100, expense_account="Stock Adjustment - _TC", is_opening="Yes", do_not_save=True)
+
+ self.assertRaises(OpeningEntryAccountError, mr.save)
+
+ mr.items[0].expense_account = "Temporary Opening - _TC"
+ mr.save()
+ mr.submit()
+
+ is_opening = frappe.db.get_value("GL Entry",
+ filters={"voucher_type": "Stock Entry", "voucher_no": mr.name}, fieldname="is_opening")
+ self.assertEqual(is_opening, "Yes")
+
def make_serialized_item(item_code=None, serial_no=None, target_warehouse=None):
se = frappe.copy_doc(test_records[0])
se.get("items")[0].item_code = item_code or "_Test Serialized Item With Series"