mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 00:44:45 +00:00
test(stock): add test to create pr for asset item without checking the stock account
This commit is contained in:
@@ -2062,7 +2062,7 @@ def create_asset_category(enable_cwip=1):
|
|||||||
asset_category.insert()
|
asset_category.insert()
|
||||||
|
|
||||||
|
|
||||||
def create_fixed_asset_item(item_code=None, auto_create_assets=1, is_grouped_asset=0):
|
def create_fixed_asset_item(item_code=None, auto_create_assets=1, is_grouped_asset=0, asset_category=None):
|
||||||
meta = frappe.get_meta("Asset")
|
meta = frappe.get_meta("Asset")
|
||||||
naming_series = meta.get_field("naming_series").options.splitlines()[0] or "ACC-ASS-.YYYY.-"
|
naming_series = meta.get_field("naming_series").options.splitlines()[0] or "ACC-ASS-.YYYY.-"
|
||||||
try:
|
try:
|
||||||
@@ -2072,7 +2072,7 @@ def create_fixed_asset_item(item_code=None, auto_create_assets=1, is_grouped_ass
|
|||||||
"item_code": item_code or "Macbook Pro",
|
"item_code": item_code or "Macbook Pro",
|
||||||
"item_name": "Macbook Pro",
|
"item_name": "Macbook Pro",
|
||||||
"description": "Macbook Pro Retina Display",
|
"description": "Macbook Pro Retina Display",
|
||||||
"asset_category": "Computers",
|
"asset_category": asset_category or "Computers",
|
||||||
"item_group": "All Item Groups",
|
"item_group": "All Item Groups",
|
||||||
"stock_uom": "Nos",
|
"stock_uom": "Nos",
|
||||||
"is_stock_item": 0,
|
"is_stock_item": 0,
|
||||||
|
|||||||
@@ -5510,6 +5510,147 @@ class TestPurchaseReceipt(ERPNextTestSuite):
|
|||||||
"Buying Settings", "set_landed_cost_based_on_purchase_invoice_rate", original_value
|
"Buying Settings", "set_landed_cost_based_on_purchase_invoice_rate", original_value
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_purchase_receipt_gl_entries_for_asset_item(self):
|
||||||
|
from erpnext.assets.doctype.asset.test_asset import create_fixed_asset_item
|
||||||
|
|
||||||
|
# Create a Company without Stock Accounts Linked.
|
||||||
|
company = frappe.get_doc(
|
||||||
|
{
|
||||||
|
"doctype": "Company",
|
||||||
|
"company_name": "Asset Company",
|
||||||
|
"country": "India",
|
||||||
|
"default_currency": "INR",
|
||||||
|
}
|
||||||
|
).insert()
|
||||||
|
|
||||||
|
stock_accounts = (
|
||||||
|
company.default_inventory_account,
|
||||||
|
company.stock_adjustment_account,
|
||||||
|
company.stock_received_but_not_billed,
|
||||||
|
)
|
||||||
|
|
||||||
|
company.update(
|
||||||
|
{"stock_in_hand_account": "", "stock_adjustment_account": "", "stock_received_but_not_billed": ""}
|
||||||
|
).save()
|
||||||
|
|
||||||
|
for account in stock_accounts:
|
||||||
|
frappe.db.delete("Account", account)
|
||||||
|
|
||||||
|
asset_category = create_asset_category_for_pr_test()
|
||||||
|
asset_item = create_fixed_asset_item(
|
||||||
|
item_code="Test Fixed Asset Item for PR GL Test", asset_category=asset_category.name
|
||||||
|
)
|
||||||
|
arnb_account = frappe.db.get_value("Company", company.name, "asset_received_but_not_billed")
|
||||||
|
|
||||||
|
# Purchase Receipt should be able to create even without any stock accounts linked to company
|
||||||
|
pr = make_purchase_receipt(
|
||||||
|
item_code=asset_item.name, warehouse="Stores - AC", qty=1, rate=10000, company=company.name
|
||||||
|
)
|
||||||
|
|
||||||
|
gl_entries = get_gl_entries("Purchase Receipt", pr.name)
|
||||||
|
|
||||||
|
self.assertTrue(gl_entries)
|
||||||
|
gl_accounts = [d.account for d in gl_entries]
|
||||||
|
|
||||||
|
# The fixed asset account set on the item row must be debited
|
||||||
|
asset_expense_account = pr.items[0].expense_account
|
||||||
|
self.assertIn(asset_expense_account, gl_accounts)
|
||||||
|
|
||||||
|
# Asset Received But Not Billed must be credited
|
||||||
|
self.assertIn(arnb_account, gl_accounts)
|
||||||
|
|
||||||
|
# No Stock-type account should appear — the inventory account map is not
|
||||||
|
# needed and must not be consulted for an asset-only receipt
|
||||||
|
for entry in gl_entries:
|
||||||
|
account_type = frappe.db.get_value("Account", entry.account, "account_type")
|
||||||
|
self.assertNotEqual(account_type, "Stock")
|
||||||
|
|
||||||
|
pr.cancel()
|
||||||
|
|
||||||
|
def test_purchase_receipt_gl_entries_with_mixed_asset_and_stock_items(self):
|
||||||
|
from erpnext.assets.doctype.asset.test_asset import create_fixed_asset_item
|
||||||
|
|
||||||
|
company = frappe.get_doc(
|
||||||
|
{
|
||||||
|
"doctype": "Company",
|
||||||
|
"company_name": "Asset Company",
|
||||||
|
"country": "India",
|
||||||
|
"default_currency": "INR",
|
||||||
|
}
|
||||||
|
).insert()
|
||||||
|
|
||||||
|
asset_category = create_asset_category_for_pr_test()
|
||||||
|
asset_item = create_fixed_asset_item(
|
||||||
|
item_code="Test Fixed Asset Item for PR GL Test", asset_category=asset_category.name
|
||||||
|
)
|
||||||
|
arnb_account = frappe.db.get_value("Company", company.name, "asset_received_but_not_billed")
|
||||||
|
|
||||||
|
pr = make_purchase_receipt(
|
||||||
|
item_code=asset_item.name,
|
||||||
|
qty=1,
|
||||||
|
rate=10000,
|
||||||
|
warehouse="Stores - AC",
|
||||||
|
do_not_save=True,
|
||||||
|
company=company.name,
|
||||||
|
)
|
||||||
|
pr.append(
|
||||||
|
"items",
|
||||||
|
{
|
||||||
|
"item_code": "_Test Item",
|
||||||
|
"warehouse": "Stores - AC",
|
||||||
|
"qty": 5,
|
||||||
|
"received_qty": 5,
|
||||||
|
"rejected_qty": 0,
|
||||||
|
"rate": 50,
|
||||||
|
"uom": "_Test UOM",
|
||||||
|
"stock_uom": "_Test UOM",
|
||||||
|
"conversion_factor": 1.0,
|
||||||
|
"cost_center": frappe.get_cached_value("Company", pr.company, "cost_center"),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
pr.insert()
|
||||||
|
pr.submit()
|
||||||
|
|
||||||
|
gl_entries = get_gl_entries("Purchase Receipt", pr.name)
|
||||||
|
self.assertTrue(gl_entries)
|
||||||
|
|
||||||
|
gl_accounts = [d.account for d in gl_entries]
|
||||||
|
self.assertIn(arnb_account, gl_accounts)
|
||||||
|
|
||||||
|
# The fixed asset account set on the item row must be debited
|
||||||
|
asset_expense_account = pr.items[0].expense_account
|
||||||
|
self.assertIn(asset_expense_account, gl_accounts)
|
||||||
|
|
||||||
|
# Asset Received But Not Billed must be credited
|
||||||
|
self.assertIn(asset_category.accounts[0].fixed_asset_account, gl_accounts)
|
||||||
|
|
||||||
|
# Stock Accounts should be used for Stock Items
|
||||||
|
self.assertIn(company.stock_received_but_not_billed, gl_accounts)
|
||||||
|
self.assertIn(company.default_inventory_account, gl_accounts)
|
||||||
|
pr.cancel()
|
||||||
|
|
||||||
|
|
||||||
|
def create_asset_category_for_pr_test():
|
||||||
|
category_name = "Test Asset Category for PR"
|
||||||
|
|
||||||
|
asset_category = frappe.get_doc(
|
||||||
|
{
|
||||||
|
"doctype": "Asset Category",
|
||||||
|
"asset_category_name": category_name,
|
||||||
|
"enable_cwip_accounting": 0,
|
||||||
|
"depreciation_method": "Straight Line",
|
||||||
|
"total_number_of_depreciations": 12,
|
||||||
|
"frequency_of_depreciation": 1,
|
||||||
|
"accounts": [
|
||||||
|
{
|
||||||
|
"company_name": "Asset Company",
|
||||||
|
"fixed_asset_account": "Electronic Equipment - AC",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
).insert()
|
||||||
|
return asset_category
|
||||||
|
|
||||||
|
|
||||||
def prepare_data_for_internal_transfer():
|
def prepare_data_for_internal_transfer():
|
||||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
|
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
|
||||||
|
|||||||
Reference in New Issue
Block a user