refactor: Remove expense included in valuation accounts (#37632)
* refactor: Remove expense included in valuation accounts * test: Deprecate tests * test: Depricate tests * test: Depricate tests
This commit is contained in:
parent
2b64e1ca8b
commit
3bfb7b79f2
@ -585,13 +585,12 @@ class PurchaseInvoice(BuyingController):
|
||||
|
||||
def get_gl_entries(self, warehouse_account=None):
|
||||
self.auto_accounting_for_stock = erpnext.is_perpetual_inventory_enabled(self.company)
|
||||
self.asset_received_but_not_billed = self.get_company_default("asset_received_but_not_billed")
|
||||
|
||||
if self.auto_accounting_for_stock:
|
||||
self.stock_received_but_not_billed = self.get_company_default("stock_received_but_not_billed")
|
||||
self.expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation")
|
||||
self.asset_received_but_not_billed = self.get_company_default("asset_received_but_not_billed")
|
||||
else:
|
||||
self.stock_received_but_not_billed = None
|
||||
self.expenses_included_in_valuation = None
|
||||
|
||||
self.negative_expense_to_be_booked = 0.0
|
||||
gl_entries = []
|
||||
@ -913,40 +912,6 @@ class PurchaseInvoice(BuyingController):
|
||||
)
|
||||
)
|
||||
|
||||
# If asset is bought through this document and not linked to PR
|
||||
if self.update_stock and item.landed_cost_voucher_amount:
|
||||
expenses_included_in_asset_valuation = self.get_company_default(
|
||||
"expenses_included_in_asset_valuation"
|
||||
)
|
||||
# Amount added through landed-cost-voucher
|
||||
gl_entries.append(
|
||||
self.get_gl_dict(
|
||||
{
|
||||
"account": expenses_included_in_asset_valuation,
|
||||
"against": expense_account,
|
||||
"cost_center": item.cost_center,
|
||||
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
||||
"credit": flt(item.landed_cost_voucher_amount),
|
||||
"project": item.project or self.project,
|
||||
},
|
||||
item=item,
|
||||
)
|
||||
)
|
||||
|
||||
gl_entries.append(
|
||||
self.get_gl_dict(
|
||||
{
|
||||
"account": expense_account,
|
||||
"against": expenses_included_in_asset_valuation,
|
||||
"cost_center": item.cost_center,
|
||||
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
||||
"debit": flt(item.landed_cost_voucher_amount),
|
||||
"project": item.project or self.project,
|
||||
},
|
||||
item=item,
|
||||
)
|
||||
)
|
||||
|
||||
# update gross amount of asset bought through this document
|
||||
assets = frappe.db.get_all(
|
||||
"Asset", filters={"purchase_invoice": self.name, "item_code": item.item_code}
|
||||
|
@ -2500,12 +2500,6 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
"stock_received_but_not_billed",
|
||||
"Stock Received But Not Billed - _TC1",
|
||||
)
|
||||
frappe.db.set_value(
|
||||
"Company",
|
||||
"_Test Company 1",
|
||||
"expenses_included_in_valuation",
|
||||
"Expenses Included In Valuation - _TC1",
|
||||
)
|
||||
|
||||
# begin test
|
||||
si = create_sales_invoice(
|
||||
@ -2545,36 +2539,6 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
frappe.local.enable_perpetual_inventory["_Test Company 1"] = old_perpetual_inventory
|
||||
frappe.db.set_single_value("Stock Settings", "allow_negative_stock", old_negative_stock)
|
||||
|
||||
def test_sle_for_target_warehouse(self):
|
||||
se = make_stock_entry(
|
||||
item_code="138-CMS Shoe",
|
||||
target="Finished Goods - _TC",
|
||||
company="_Test Company",
|
||||
qty=1,
|
||||
basic_rate=500,
|
||||
)
|
||||
|
||||
si = frappe.copy_doc(test_records[0])
|
||||
si.update_stock = 1
|
||||
si.set_warehouse = "Finished Goods - _TC"
|
||||
si.set_target_warehouse = "Stores - _TC"
|
||||
si.get("items")[0].warehouse = "Finished Goods - _TC"
|
||||
si.get("items")[0].target_warehouse = "Stores - _TC"
|
||||
si.insert()
|
||||
si.submit()
|
||||
|
||||
sles = frappe.get_all(
|
||||
"Stock Ledger Entry", filters={"voucher_no": si.name}, fields=["name", "actual_qty"]
|
||||
)
|
||||
|
||||
# check if both SLEs are created
|
||||
self.assertEqual(len(sles), 2)
|
||||
self.assertEqual(sum(d.actual_qty for d in sles), 0.0)
|
||||
|
||||
# tear down
|
||||
si.cancel()
|
||||
se.cancel()
|
||||
|
||||
def test_internal_transfer_gl_entry(self):
|
||||
si = create_sales_invoice(
|
||||
company="_Test Company with perpetual inventory",
|
||||
|
@ -1196,12 +1196,12 @@ def get_children(parent=None, is_root=False, **filters):
|
||||
def add_additional_cost(stock_entry, work_order):
|
||||
# Add non stock items cost in the additional cost
|
||||
stock_entry.additional_costs = []
|
||||
expenses_included_in_valuation = frappe.get_cached_value(
|
||||
"Company", work_order.company, "expenses_included_in_valuation"
|
||||
default_expense_account = frappe.get_cached_value(
|
||||
"Company", work_order.company, "default_expense_account"
|
||||
)
|
||||
|
||||
add_non_stock_items_cost(stock_entry, work_order, expenses_included_in_valuation)
|
||||
add_operations_cost(stock_entry, work_order, expenses_included_in_valuation)
|
||||
add_non_stock_items_cost(stock_entry, work_order, default_expense_account)
|
||||
add_operations_cost(stock_entry, work_order, default_expense_account)
|
||||
|
||||
|
||||
def add_non_stock_items_cost(stock_entry, work_order, expense_account):
|
||||
|
@ -1,42 +0,0 @@
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
frappe.reload_doctype("Landed Cost Taxes and Charges")
|
||||
|
||||
company_account_map = frappe._dict(
|
||||
frappe.db.sql(
|
||||
"""
|
||||
SELECT name, expenses_included_in_valuation from `tabCompany`
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
for company, account in company_account_map.items():
|
||||
frappe.db.sql(
|
||||
"""
|
||||
UPDATE
|
||||
`tabLanded Cost Taxes and Charges` t, `tabLanded Cost Voucher` l
|
||||
SET
|
||||
t.expense_account = %s
|
||||
WHERE
|
||||
l.docstatus = 1
|
||||
AND l.company = %s
|
||||
AND t.parent = l.name
|
||||
""",
|
||||
(account, company),
|
||||
)
|
||||
|
||||
frappe.db.sql(
|
||||
"""
|
||||
UPDATE
|
||||
`tabLanded Cost Taxes and Charges` t, `tabStock Entry` s
|
||||
SET
|
||||
t.expense_account = %s
|
||||
WHERE
|
||||
s.docstatus = 1
|
||||
AND s.company = %s
|
||||
AND t.parent = s.name
|
||||
""",
|
||||
(account, company),
|
||||
)
|
@ -221,7 +221,6 @@ erpnext.company.setup_queries = function(frm) {
|
||||
["cost_center", {}],
|
||||
["round_off_cost_center", {}],
|
||||
["depreciation_cost_center", {}],
|
||||
["expenses_included_in_asset_valuation", {"account_type": "Expenses Included In Asset Valuation"}],
|
||||
["capital_work_in_progress_account", {"account_type": "Capital Work in Progress"}],
|
||||
["asset_received_but_not_billed", {"account_type": "Asset Received But Not Billed"}],
|
||||
["unrealized_profit_loss_account", {"root_type": ["in", ["Liability", "Asset"]]}],
|
||||
@ -236,8 +235,6 @@ erpnext.company.setup_queries = function(frm) {
|
||||
$.each([
|
||||
["stock_adjustment_account",
|
||||
{"root_type": "Expense", "account_type": "Stock Adjustment"}],
|
||||
["expenses_included_in_valuation",
|
||||
{"root_type": "Expense", "account_type": "Expenses Included in Valuation"}],
|
||||
["stock_received_but_not_billed",
|
||||
{"root_type": "Liability", "account_type": "Stock Received But Not Billed"}],
|
||||
["service_received_but_not_billed",
|
||||
|
@ -80,7 +80,6 @@
|
||||
"accumulated_depreciation_account",
|
||||
"depreciation_expense_account",
|
||||
"series_for_depreciation_entry",
|
||||
"expenses_included_in_asset_valuation",
|
||||
"column_break_40",
|
||||
"disposal_account",
|
||||
"depreciation_cost_center",
|
||||
@ -103,11 +102,10 @@
|
||||
"enable_provisional_accounting_for_non_stock_items",
|
||||
"default_inventory_account",
|
||||
"stock_adjustment_account",
|
||||
"default_in_transit_warehouse",
|
||||
"column_break_32",
|
||||
"stock_received_but_not_billed",
|
||||
"default_provisional_account",
|
||||
"expenses_included_in_valuation",
|
||||
"default_in_transit_warehouse",
|
||||
"dashboard_tab"
|
||||
],
|
||||
"fields": [
|
||||
@ -469,14 +467,6 @@
|
||||
"no_copy": 1,
|
||||
"options": "Account"
|
||||
},
|
||||
{
|
||||
"fieldname": "expenses_included_in_valuation",
|
||||
"fieldtype": "Link",
|
||||
"ignore_user_permissions": 1,
|
||||
"label": "Expenses Included In Valuation",
|
||||
"no_copy": 1,
|
||||
"options": "Account"
|
||||
},
|
||||
{
|
||||
"fieldname": "accumulated_depreciation_account",
|
||||
"fieldtype": "Link",
|
||||
@ -496,12 +486,6 @@
|
||||
"fieldtype": "Data",
|
||||
"label": "Series for Asset Depreciation Entry (Journal Entry)"
|
||||
},
|
||||
{
|
||||
"fieldname": "expenses_included_in_asset_valuation",
|
||||
"fieldtype": "Link",
|
||||
"label": "Expenses Included In Asset Valuation",
|
||||
"options": "Account"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_40",
|
||||
"fieldtype": "Column Break"
|
||||
@ -782,7 +766,7 @@
|
||||
"image_field": "company_logo",
|
||||
"is_tree": 1,
|
||||
"links": [],
|
||||
"modified": "2023-09-10 21:53:13.860791",
|
||||
"modified": "2023-10-23 10:19:24.322898",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"name": "Company",
|
||||
|
@ -92,7 +92,6 @@ class Company(NestedSet):
|
||||
["Default Income Account", "default_income_account"],
|
||||
["Stock Received But Not Billed Account", "stock_received_but_not_billed"],
|
||||
["Stock Adjustment Account", "stock_adjustment_account"],
|
||||
["Expense Included In Valuation Account", "expenses_included_in_valuation"],
|
||||
]
|
||||
|
||||
for account in accounts:
|
||||
@ -384,7 +383,6 @@ class Company(NestedSet):
|
||||
"depreciation_expense_account": "Depreciation",
|
||||
"capital_work_in_progress_account": "Capital Work in Progress",
|
||||
"asset_received_but_not_billed": "Asset Received But Not Billed",
|
||||
"expenses_included_in_asset_valuation": "Expenses Included In Asset Valuation",
|
||||
"default_expense_account": "Cost of Goods Sold",
|
||||
}
|
||||
|
||||
@ -394,7 +392,6 @@ class Company(NestedSet):
|
||||
"stock_received_but_not_billed": "Stock Received But Not Billed",
|
||||
"default_inventory_account": "Stock",
|
||||
"stock_adjustment_account": "Stock Adjustment",
|
||||
"expenses_included_in_valuation": "Expenses Included In Valuation",
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -491,7 +491,6 @@ class PurchaseReceipt(BuyingController):
|
||||
return
|
||||
|
||||
# divisional loss adjustment
|
||||
expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation")
|
||||
valuation_amount_as_per_doc = (
|
||||
flt(outgoing_amount, d.precision("base_net_amount"))
|
||||
+ flt(item.landed_cost_voucher_amount)
|
||||
@ -505,13 +504,10 @@ class PurchaseReceipt(BuyingController):
|
||||
)
|
||||
|
||||
if divisional_loss:
|
||||
if self.is_return or flt(item.item_tax_amount):
|
||||
loss_account = expenses_included_in_valuation
|
||||
else:
|
||||
loss_account = (
|
||||
self.get_company_default("default_expense_account", ignore_validation=True)
|
||||
or stock_asset_rbnb
|
||||
)
|
||||
loss_account = (
|
||||
self.get_company_default("default_expense_account", ignore_validation=True)
|
||||
or stock_asset_rbnb
|
||||
)
|
||||
|
||||
cost_center = item.cost_center or frappe.get_cached_value(
|
||||
"Company", self.company, "cost_center"
|
||||
@ -684,10 +680,8 @@ class PurchaseReceipt(BuyingController):
|
||||
|
||||
if negative_expense_to_be_booked and valuation_tax:
|
||||
# Backward compatibility:
|
||||
# If expenses_included_in_valuation account has been credited in against PI
|
||||
# and charges added via Landed Cost Voucher,
|
||||
# post valuation related charges on "Stock Received But Not Billed"
|
||||
# introduced in 2014 for backward compatibility of expenses already booked in expenses_included_in_valuation account
|
||||
against_account = ", ".join([d.account for d in gl_entries if flt(d.debit) > 0])
|
||||
total_valuation_amount = sum(valuation_tax.values())
|
||||
amount_including_divisional_loss = negative_expense_to_be_booked
|
||||
|
@ -957,88 +957,6 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
pr1.reload()
|
||||
pr1.cancel()
|
||||
|
||||
def test_stock_transfer_from_purchase_receipt(self):
|
||||
pr1 = make_purchase_receipt(
|
||||
warehouse="Work In Progress - TCP1", company="_Test Company with perpetual inventory"
|
||||
)
|
||||
|
||||
pr = make_purchase_receipt(
|
||||
company="_Test Company with perpetual inventory", warehouse="Stores - TCP1", do_not_save=1
|
||||
)
|
||||
|
||||
pr.supplier_warehouse = ""
|
||||
pr.items[0].from_warehouse = "Work In Progress - TCP1"
|
||||
|
||||
pr.submit()
|
||||
|
||||
gl_entries = get_gl_entries("Purchase Receipt", pr.name)
|
||||
sl_entries = get_sl_entries("Purchase Receipt", pr.name)
|
||||
|
||||
self.assertFalse(gl_entries)
|
||||
|
||||
expected_sle = {"Work In Progress - TCP1": -5, "Stores - TCP1": 5}
|
||||
|
||||
for sle in sl_entries:
|
||||
self.assertEqual(expected_sle[sle.warehouse], sle.actual_qty)
|
||||
|
||||
pr.cancel()
|
||||
pr1.cancel()
|
||||
|
||||
def test_stock_transfer_from_purchase_receipt_with_valuation(self):
|
||||
create_warehouse(
|
||||
"_Test Warehouse for Valuation",
|
||||
company="_Test Company with perpetual inventory",
|
||||
properties={"account": "_Test Account Stock In Hand - TCP1"},
|
||||
)
|
||||
|
||||
pr1 = make_purchase_receipt(
|
||||
warehouse="_Test Warehouse for Valuation - TCP1",
|
||||
company="_Test Company with perpetual inventory",
|
||||
)
|
||||
|
||||
pr = make_purchase_receipt(
|
||||
company="_Test Company with perpetual inventory", warehouse="Stores - TCP1", do_not_save=1
|
||||
)
|
||||
|
||||
pr.items[0].from_warehouse = "_Test Warehouse for Valuation - TCP1"
|
||||
pr.supplier_warehouse = ""
|
||||
|
||||
pr.append(
|
||||
"taxes",
|
||||
{
|
||||
"charge_type": "On Net Total",
|
||||
"account_head": "_Test Account Shipping Charges - TCP1",
|
||||
"category": "Valuation and Total",
|
||||
"cost_center": "Main - TCP1",
|
||||
"description": "Test",
|
||||
"rate": 9,
|
||||
},
|
||||
)
|
||||
|
||||
pr.submit()
|
||||
|
||||
gl_entries = get_gl_entries("Purchase Receipt", pr.name)
|
||||
sl_entries = get_sl_entries("Purchase Receipt", pr.name)
|
||||
|
||||
expected_gle = [
|
||||
["Stock In Hand - TCP1", 272.5, 0.0],
|
||||
["_Test Account Stock In Hand - TCP1", 0.0, 250.0],
|
||||
["_Test Account Shipping Charges - TCP1", 0.0, 22.5],
|
||||
]
|
||||
|
||||
expected_sle = {"_Test Warehouse for Valuation - TCP1": -5, "Stores - TCP1": 5}
|
||||
|
||||
for sle in sl_entries:
|
||||
self.assertEqual(expected_sle[sle.warehouse], sle.actual_qty)
|
||||
|
||||
for i, gle in enumerate(gl_entries):
|
||||
self.assertEqual(gle.account, expected_gle[i][0])
|
||||
self.assertEqual(gle.debit, expected_gle[i][1])
|
||||
self.assertEqual(gle.credit, expected_gle[i][2])
|
||||
|
||||
pr.cancel()
|
||||
pr1.cancel()
|
||||
|
||||
def test_po_to_pi_and_po_to_pr_worflow_full(self):
|
||||
"""Test following behaviour:
|
||||
- Create PO
|
||||
|
@ -449,9 +449,7 @@ class TestStockEntry(FrappeTestCase):
|
||||
repack.posting_date = nowdate()
|
||||
repack.posting_time = nowtime()
|
||||
|
||||
expenses_included_in_valuation = frappe.get_value(
|
||||
"Company", company, "expenses_included_in_valuation"
|
||||
)
|
||||
default_expense_account = frappe.get_value("Company", company, "default_expense_account")
|
||||
|
||||
items = get_multiple_items()
|
||||
repack.items = []
|
||||
@ -462,12 +460,12 @@ class TestStockEntry(FrappeTestCase):
|
||||
"additional_costs",
|
||||
[
|
||||
{
|
||||
"expense_account": expenses_included_in_valuation,
|
||||
"expense_account": default_expense_account,
|
||||
"description": "Actual Operating Cost",
|
||||
"amount": 1000,
|
||||
},
|
||||
{
|
||||
"expense_account": expenses_included_in_valuation,
|
||||
"expense_account": default_expense_account,
|
||||
"description": "Additional Operating Cost",
|
||||
"amount": 200,
|
||||
},
|
||||
@ -506,9 +504,7 @@ class TestStockEntry(FrappeTestCase):
|
||||
self.check_gl_entries(
|
||||
"Stock Entry",
|
||||
repack.name,
|
||||
sorted(
|
||||
[[stock_in_hand_account, 1200, 0.0], ["Expenses Included In Valuation - TCP1", 0.0, 1200.0]]
|
||||
),
|
||||
sorted([[stock_in_hand_account, 1200, 0.0], ["Cost of Goods Sold - TCP1", 0.0, 1200.0]]),
|
||||
)
|
||||
|
||||
def check_stock_ledger_entries(self, voucher_type, voucher_no, expected_sle):
|
||||
|
@ -410,7 +410,6 @@ class SubcontractingReceipt(SubcontractingController):
|
||||
|
||||
def make_item_gl_entries(self, gl_entries, warehouse_account=None):
|
||||
stock_rbnb = self.get_company_default("stock_received_but_not_billed")
|
||||
expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation")
|
||||
|
||||
warehouse_with_no_account = []
|
||||
|
||||
@ -482,10 +481,7 @@ class SubcontractingReceipt(SubcontractingController):
|
||||
divisional_loss = flt(item.amount - stock_value_diff, item.precision("amount"))
|
||||
|
||||
if divisional_loss:
|
||||
if self.is_return:
|
||||
loss_account = expenses_included_in_valuation
|
||||
else:
|
||||
loss_account = item.expense_account
|
||||
loss_account = item.expense_account
|
||||
|
||||
self.add_gl_entry(
|
||||
gl_entries=gl_entries,
|
||||
|
Loading…
x
Reference in New Issue
Block a user