refactor: added condition which checks for corrective operation setting
(cherry picked from commit 063a205e5a)
This commit is contained in:
@@ -1408,7 +1408,15 @@ def add_operations_cost(stock_entry, work_order=None, expense_account=None):
|
||||
)
|
||||
return query.run(as_dict=True)[0].amount or 0
|
||||
|
||||
if work_order and work_order.corrective_operation_cost:
|
||||
if (
|
||||
work_order
|
||||
and work_order.corrective_operation_cost
|
||||
and cint(
|
||||
frappe.db.get_single_value(
|
||||
"Manufacturing Settings", "add_corrective_operation_cost_in_finished_good_valuation"
|
||||
)
|
||||
)
|
||||
):
|
||||
max_qty = get_max_op_qty() - work_order.produced_qty
|
||||
remaining_cc = work_order.corrective_operation_cost - get_utilised_cc()
|
||||
stock_entry.append(
|
||||
|
||||
@@ -428,10 +428,18 @@ class TestJobCard(FrappeTestCase):
|
||||
"Manufacturing Settings", {"add_corrective_operation_cost_in_finished_good_valuation": 1}
|
||||
)
|
||||
def test_if_corrective_jc_ops_cost_is_added_to_manufacture_stock_entry(self):
|
||||
job_card = frappe.get_last_doc("Job Card", {"work_order": self.work_order.name})
|
||||
wo = make_wo_order_test_record(
|
||||
item="_Test FG Item 2",
|
||||
qty=10,
|
||||
transfer_material_against=self.transfer_material_against,
|
||||
source_warehouse=self.source_warehouse,
|
||||
)
|
||||
self.generate_required_stock(wo)
|
||||
job_card = frappe.get_last_doc("Job Card", {"work_order": wo.name})
|
||||
job_card.update({"for_quantity": 4})
|
||||
job_card.append(
|
||||
"time_logs",
|
||||
{"from_time": now(), "to_time": add_to_date(now(), hours=1), "completed_qty": 2},
|
||||
{"from_time": now(), "to_time": add_to_date(now(), hours=1), "completed_qty": 4},
|
||||
)
|
||||
job_card.submit()
|
||||
|
||||
@@ -449,20 +457,56 @@ class TestJobCard(FrappeTestCase):
|
||||
{
|
||||
"from_time": add_to_date(now(), hours=2),
|
||||
"to_time": add_to_date(now(), hours=2, minutes=30),
|
||||
"completed_qty": 2,
|
||||
"completed_qty": 4,
|
||||
},
|
||||
)
|
||||
corrective_job_card.submit()
|
||||
self.work_order.reload()
|
||||
wo.reload()
|
||||
|
||||
from erpnext.manufacturing.doctype.work_order.work_order import (
|
||||
make_stock_entry as make_stock_entry_for_wo,
|
||||
)
|
||||
|
||||
stock_entry = make_stock_entry_for_wo(self.work_order.name, "Manufacture")
|
||||
self.assertEqual(stock_entry.additional_costs[1].description, "Corrective Operation Cost")
|
||||
self.assertEqual(stock_entry.additional_costs[1].amount, 50)
|
||||
self.assertEqual(stock_entry["items"][-1].additional_cost, 6050)
|
||||
stock_entry = make_stock_entry_for_wo(wo.name, "Manufacture", qty=3)
|
||||
self.assertEqual(stock_entry.additional_costs[1].amount, 37.5)
|
||||
frappe.get_doc(stock_entry).submit()
|
||||
|
||||
from erpnext.manufacturing.doctype.work_order.work_order import make_job_card
|
||||
|
||||
make_job_card(
|
||||
wo.name,
|
||||
[{"name": wo.operations[0].name, "operation": "_Test Operation 1", "qty": 3, "pending_qty": 3}],
|
||||
)
|
||||
job_card = frappe.get_last_doc("Job Card", {"work_order": wo.name})
|
||||
job_card.update({"for_quantity": 3})
|
||||
job_card.append(
|
||||
"time_logs",
|
||||
{
|
||||
"from_time": add_to_date(now(), hours=3),
|
||||
"to_time": add_to_date(now(), hours=4),
|
||||
"completed_qty": 3,
|
||||
},
|
||||
)
|
||||
job_card.submit()
|
||||
|
||||
corrective_job_card = make_corrective_job_card(
|
||||
job_card.name, operation=corrective_action.name, for_operation=job_card.operation
|
||||
)
|
||||
corrective_job_card.hour_rate = 80
|
||||
corrective_job_card.insert()
|
||||
corrective_job_card.append(
|
||||
"time_logs",
|
||||
{
|
||||
"from_time": add_to_date(now(), hours=4),
|
||||
"to_time": add_to_date(now(), hours=4, minutes=30),
|
||||
"completed_qty": 3,
|
||||
},
|
||||
)
|
||||
corrective_job_card.submit()
|
||||
wo.reload()
|
||||
|
||||
stock_entry = make_stock_entry_for_wo(wo.name, "Manufacture", qty=4)
|
||||
self.assertEqual(stock_entry.additional_costs[1].amount, 52.5)
|
||||
|
||||
def test_job_card_statuses(self):
|
||||
def assertStatus(status):
|
||||
|
||||
@@ -2868,17 +2868,6 @@ def get_operating_cost_per_unit(work_order=None, bom_no=None):
|
||||
if bom.quantity:
|
||||
operating_cost_per_unit = flt(bom.operating_cost) / flt(bom.quantity)
|
||||
|
||||
if (
|
||||
work_order
|
||||
and work_order.produced_qty
|
||||
and cint(
|
||||
frappe.db.get_single_value(
|
||||
"Manufacturing Settings", "add_corrective_operation_cost_in_finished_good_valuation"
|
||||
)
|
||||
)
|
||||
):
|
||||
operating_cost_per_unit += flt(work_order.corrective_operation_cost) / flt(work_order.produced_qty)
|
||||
|
||||
return operating_cost_per_unit
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user