Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3207,12 +3207,15 @@ def test_inter_company_transaction_without_default_warehouse(self):

old_perpetual_inventory = erpnext.is_perpetual_inventory_enabled("_Test Company 1")
frappe.local.enable_perpetual_inventory["_Test Company 1"] = 1
old_inventory_account = frappe.db.get_value("Company", "_Test Company 1", "default_inventory_account")

frappe.db.set_value(
"Company",
"_Test Company 1",
"stock_received_but_not_billed",
"Stock Received But Not Billed - _TC1",
{
"stock_received_but_not_billed": "Stock Received But Not Billed - _TC1",
"default_inventory_account": "Stock In Hand - _TC1",
},
)

# companies are created with their Stores warehouse as Default Warehouse; clear it so the
Expand Down Expand Up @@ -3255,6 +3258,7 @@ def test_inter_company_transaction_without_default_warehouse(self):

# tear down
frappe.local.enable_perpetual_inventory["_Test Company 1"] = old_perpetual_inventory
frappe.db.set_value("Company", "_Test Company 1", "default_inventory_account", old_inventory_account)
frappe.db.set_single_value("Stock Settings", "allow_negative_stock", old_negative_stock)

def test_sle_for_target_warehouse(self):
Expand Down
7 changes: 5 additions & 2 deletions erpnext/stock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ def get_warehouse_account(warehouse, warehouse_account=None):
account = get_company_default_inventory_account(warehouse.company)

if not account and warehouse.company:
account = frappe.db.get_value(
"Account", {"account_type": "Stock", "is_group": 0, "company": warehouse.company}, "name"
inventory_accounts = frappe.get_all(
"Account", {"account_type": "Stock", "is_group": 0, "company": warehouse.company}, pluck="name"
)

if len(inventory_accounts) == 1:
account = inventory_accounts[0]
Comment thread
rohitwaghchaure marked this conversation as resolved.

if not account and warehouse.company and not warehouse.is_group:
frappe.throw(
_("Please set Account in Warehouse {0} or Default Inventory Account in Company {1}").format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,10 @@ def test_lcv_validates_company(self):

epi = is_perpetual_inventory_enabled(company_a)
company_doc = frappe.get_doc("Company", company_a)
old_inventory_account = company_doc.default_inventory_account
company_doc.enable_perpetual_inventory = 1
company_doc.stock_received_but_not_billed = srbnb
company_doc.default_inventory_account = "Stock In Hand - _TC"
company_doc.save()

pr = make_purchase_receipt(
Expand Down Expand Up @@ -250,7 +252,11 @@ def test_lcv_validates_company(self):
distribute_landed_cost_on_items(lcv)
lcv.submit()

frappe.db.set_value("Company", company_a, "enable_perpetual_inventory", epi)
frappe.db.set_value(
"Company",
company_a,
{"enable_perpetual_inventory": epi, "default_inventory_account": old_inventory_account},
)
frappe.local.enable_perpetual_inventory = {}

def test_landed_cost_voucher_for_zero_purchase_rate(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3079,11 +3079,14 @@ def test_valuation_taxes_lcv_repost_after_billing(self):

old_perpetual_inventory = erpnext.is_perpetual_inventory_enabled("_Test Company")
frappe.local.enable_perpetual_inventory["_Test Company"] = 1
old_inventory_account = frappe.db.get_value("Company", "_Test Company", "default_inventory_account")
frappe.db.set_value(
"Company",
"_Test Company",
"stock_received_but_not_billed",
"Stock Received But Not Billed - _TC",
{
"stock_received_but_not_billed": "Stock Received But Not Billed - _TC",
"default_inventory_account": "Stock In Hand - _TC",
},
)

pr = make_purchase_receipt(qty=10, rate=1000, do_not_submit=1)
Expand Down Expand Up @@ -3119,6 +3122,7 @@ def test_valuation_taxes_lcv_repost_after_billing(self):
)
self.assertCountEqual(expected_gle, gl_entries)
frappe.local.enable_perpetual_inventory["_Test Company"] = old_perpetual_inventory
frappe.db.set_value("Company", "_Test Company", "default_inventory_account", old_inventory_account)

def test_purchase_receipt_with_use_serial_batch_field_for_rejected_qty(self):
batch_item = make_item(
Expand Down
38 changes: 38 additions & 0 deletions erpnext/stock/doctype/warehouse/test_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,44 @@ def test_get_children(self):
children = get_children("Warehouse", parent=company, company=company, is_root=True)
self.assertTrue(any(wh["value"] == "_Test Warehouse - _TC" for wh in children))

def test_inventory_account_fallback_with_multiple_stock_accounts(self):
from erpnext.stock import get_warehouse_account

company = create_inventory_fallback_company()
frappe.db.set_value("Company", company, "default_inventory_account", None)
if frappe.db.exists("Account", "Extra Inventory Account - _TCIF"):
frappe.delete_doc("Account", "Extra Inventory Account - _TCIF")

warehouse = frappe.get_doc("Warehouse", {"company": company, "is_group": 0})
single_account = frappe.db.get_value(
"Account", {"account_type": "Stock", "is_group": 0, "company": company}, "name"
)
self.assertEqual(get_warehouse_account(warehouse), single_account)

create_account(
account_name="Extra Inventory Account",
parent_account=frappe.db.get_value("Account", single_account, "parent_account"),
account_type="Stock",
company=company,
)
self.assertRaises(frappe.ValidationError, get_warehouse_account, warehouse)


def create_inventory_fallback_company():
company = "_Test Company Inventory Fallback"
if not frappe.db.exists("Company", company):
frappe.get_doc(
{
"doctype": "Company",
"company_name": company,
"abbr": "_TCIF",
"default_currency": "INR",
"enable_perpetual_inventory": 0,
"country": "India",
}
).insert(ignore_permissions=True)
return company


def create_warehouse(warehouse_name, properties=None, company=None):
if not company:
Expand Down
Loading