Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: default account head for operating cost (backport #41985) (backport #41987) #41991

Merged
merged 1 commit into from
Jun 22, 2024
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
14 changes: 10 additions & 4 deletions erpnext/manufacturing/doctype/bom/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,12 +1259,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 = []
expenses_included_in_valuation = frappe.get_cached_value(
"Company", work_order.company, "expenses_included_in_valuation"
company_account = frappe.db.get_value(
"Company",
work_order.company,
["expenses_included_in_valuation", "default_operating_cost_account"],
as_dict=1,
)

add_non_stock_items_cost(stock_entry, work_order, expenses_included_in_valuation)
add_operations_cost(stock_entry, work_order, expenses_included_in_valuation)
expense_account = (
company_account.default_operating_cost_account or company_account.expenses_included_in_valuation
)
add_non_stock_items_cost(stock_entry, work_order, expense_account)
add_operations_cost(stock_entry, work_order, expense_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 @@ -1748,6 +1748,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
19 changes: 16 additions & 3 deletions erpnext/setup/doctype/company/company.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
"stock_received_but_not_billed",
"default_provisional_account",
"expenses_included_in_valuation",
"manufacturing_section",
"default_operating_cost_account",
"dashboard_tab"
],
"fields": [
Expand Down Expand Up @@ -773,7 +775,7 @@
{
"fieldname": "stock_tab",
"fieldtype": "Tab Break",
"label": "Stock"
"label": "Stock and Manufacturing"
},
{
"fieldname": "dashboard_tab",
Expand All @@ -788,14 +790,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 Expand Up @@ -862,4 +875,4 @@
"sort_order": "ASC",
"states": [],
"track_changes": 1
}
}
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
Loading