Skip to content

Commit

Permalink
refactor: Remove expense included in valuation accounts (#37632)
Browse files Browse the repository at this point in the history
* refactor: Remove expense included in valuation accounts

* test: Deprecate tests

* test: Depricate tests

* test: Depricate tests
  • Loading branch information
deepeshgarg007 authored Oct 23, 2023
1 parent 2b64e1c commit 3bfb7b7
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 248 deletions.
39 changes: 2 additions & 37 deletions erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,12 @@ def make_gl_entries(self, gl_entries=None, from_repost=False):

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 = []
Expand Down Expand Up @@ -913,40 +912,6 @@ def make_item_gl_entries(self, gl_entries):
)
)

# 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}
Expand Down
36 changes: 0 additions & 36 deletions erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2500,12 +2500,6 @@ def test_inter_company_transaction_without_default_warehouse(self):
"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(
Expand Down Expand Up @@ -2545,36 +2539,6 @@ def test_inter_company_transaction_without_default_warehouse(self):
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",
Expand Down
8 changes: 4 additions & 4 deletions erpnext/manufacturing/doctype/bom/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions erpnext/setup/doctype/company/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]}],
Expand All @@ -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",
Expand Down
20 changes: 2 additions & 18 deletions erpnext/setup/doctype/company/company.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [
Expand Down Expand Up @@ -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",
Expand All @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions erpnext/setup/doctype/company/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def validate_default_accounts(self):
["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:
Expand Down Expand Up @@ -384,7 +383,6 @@ def set_default_accounts(self):
"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",
}

Expand All @@ -394,7 +392,6 @@ def set_default_accounts(self):
"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",
}
)

Expand Down
14 changes: 4 additions & 10 deletions erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ def make_divisional_loss_gl_entry(item, outgoing_amount):
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)
Expand All @@ -505,13 +504,10 @@ def make_divisional_loss_gl_entry(item, outgoing_amount):
)

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"
Expand Down Expand Up @@ -684,10 +680,8 @@ def make_tax_gl_entries(self, gl_entries):

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
Expand Down
82 changes: 0 additions & 82 deletions erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,88 +957,6 @@ def test_make_purchase_invoice_from_pr_with_returned_qty_duplicate_items(self):
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
Expand Down
Loading

0 comments on commit 3bfb7b7

Please sign in to comment.