Skip to content

Commit

Permalink
feat: default account head for operating cost (#41985)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure authored Jun 21, 2024
1 parent 4f92ab0 commit fd7666a
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 6 deletions.
14 changes: 10 additions & 4 deletions erpnext/manufacturing/doctype/bom/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,12 +1321,18 @@ 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 = []
default_expense_account = frappe.get_cached_value(
"Company", work_order.company, "default_expense_account"
company_account = frappe.db.get_value(
"Company",
work_order.company,
["default_expense_account", "default_operating_cost_account"],
as_dict=1,
)

add_non_stock_items_cost(stock_entry, work_order, default_expense_account)
add_operations_cost(stock_entry, work_order, default_expense_account)
expecnse_account = (
company_account.default_operating_cost_account or company_account.default_expense_account
)
add_non_stock_items_cost(stock_entry, work_order, expecnse_account)
add_operations_cost(stock_entry, work_order, expecnse_account)


def add_non_stock_items_cost(stock_entry, work_order, expense_account):
Expand Down
75 changes: 75 additions & 0 deletions erpnext/manufacturing/doctype/work_order/test_work_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,81 @@ def test_job_card_extra_qty(self):
job_card2.time_logs = []
job_card2.save()

def test_operating_cost_account(self):
operating_cost_account = "Test Operating Cost Account - _TC"
company = "_Test Company"
if not frappe.db.exists("Account", operating_cost_account):
frappe.get_doc(
{
"doctype": "Account",
"account_name": "Test Operating Cost Account",
"account_type": "Expense Account",
"company": company,
"parent_account": "Expenses - _TC",
"root_type": "Expense",
}
).insert()

frappe.db.set_value("Company", company, "default_operating_cost_account", operating_cost_account)

for item in ["TEST RM OP COST Item 1", "TEST FG OP COST Item"]:
if not frappe.db.exists("Item", item):
make_item(item_code=item, properties={"is_stock_item": 1})

fg_item = "TEST FG OP COST Item"
bom_doc = make_bom(
item=fg_item,
raw_materials=["TEST RM OP COST Item 1"],
rate=150,
with_operations=1,
do_not_save=True,
)

workstation = "Test Workstation For Capacity Planning 1"
if not frappe.db.exists("Workstation", workstation):
make_workstation(workstation=workstation, production_capacity=1)

operation = "Test Operation For Capacity Planning 1"
if not frappe.db.exists("Operation", operation):
make_operation(operation=operation, workstation=workstation)

bom_doc.append(
"operations",
{"operation": operation, "time_in_mins": 60, "hour_rate": 100, "workstation": workstation},
)

bom_doc.save()
bom_doc.submit()

wo = make_wo_order_test_record(
production_item=fg_item,
bom_no=bom_doc.name,
qty=1,
skip_transfer=1,
)

job_cards = frappe.get_all("Job Card", filters={"work_order": wo.name})
for job_card in job_cards:
job_card_doc = frappe.get_doc("Job Card", job_card.name)
job_card_doc.time_logs = []
job_card_doc.append(
"time_logs",
{
"from_time": now(),
"to_time": add_to_date(now(), minutes=60),
"time_in_mins": 60,
"completed_qty": 1,
},
)

job_card_doc.submit()

se_doc = frappe.get_doc(make_stock_entry(wo.name, "Manufacture", 1))
se_doc.save()

for row in se_doc.additional_costs:
self.assertEqual(row.expense_account, operating_cost_account)

def test_op_cost_and_scrap_based_on_sub_assemblies(self):
# Make Sub Assembly BOM 1

Expand Down
6 changes: 6 additions & 0 deletions erpnext/setup/doctype/company/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ frappe.ui.form.on("Company", {
};
});

frm.set_query("default_operating_cost_account", function (doc) {
return {
filters: { company: doc.name, root_type: "Expense" },
};
});

frm.set_query("default_selling_terms", function () {
return { filters: { selling: 1 } };
});
Expand Down
17 changes: 15 additions & 2 deletions erpnext/setup/doctype/company/company.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
"stock_received_but_not_billed",
"default_provisional_account",
"default_in_transit_warehouse",
"manufacturing_section",
"default_operating_cost_account",
"dashboard_tab"
],
"fields": [
Expand Down Expand Up @@ -757,7 +759,7 @@
{
"fieldname": "stock_tab",
"fieldtype": "Tab Break",
"label": "Stock"
"label": "Stock and Manufacturing"
},
{
"fieldname": "dashboard_tab",
Expand All @@ -772,14 +774,25 @@
"fieldname": "reconcile_on_advance_payment_date",
"fieldtype": "Check",
"label": "Reconcile on Advance Payment Date"
},
{
"fieldname": "manufacturing_section",
"fieldtype": "Section Break",
"label": "Manufacturing"
},
{
"fieldname": "default_operating_cost_account",
"fieldtype": "Link",
"label": "Default Operating Cost Account",
"options": "Account"
}
],
"icon": "fa fa-building",
"idx": 1,
"image_field": "company_logo",
"is_tree": 1,
"links": [],
"modified": "2024-05-27 17:32:49.057386",
"modified": "2024-06-21 17:46:25.567565",
"modified_by": "Administrator",
"module": "Setup",
"name": "Company",
Expand Down
1 change: 1 addition & 0 deletions erpnext/setup/doctype/company/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Company(NestedSet):
default_income_account: DF.Link | None
default_inventory_account: DF.Link | None
default_letter_head: DF.Link | None
default_operating_cost_account: DF.Link | None
default_payable_account: DF.Link | None
default_provisional_account: DF.Link | None
default_receivable_account: DF.Link | None
Expand Down

0 comments on commit fd7666a

Please sign in to comment.