Skip to content

Commit

Permalink
fix: get incoming rate instead of BOM rate (backport #36496) (#36506)
Browse files Browse the repository at this point in the history
* fix: get incoming rate instead of BOM rate (#36496)

* fix: get incoming rate instead of BOM rate

* test: add test case for SCR rm rate

(cherry picked from commit 758b31d)

# Conflicts:
#	erpnext/controllers/subcontracting_controller.py

* chore: `conflicts`

---------

Co-authored-by: s-aga-r <sagarsharma.s312@gmail.com>
  • Loading branch information
mergify[bot] and s-aga-r authored Aug 6, 2023
1 parent a234b89 commit bdfbccd
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion erpnext/controllers/subcontracting_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def __add_supplied_item(self, item_row, bom_item, qty):
"allow_zero_valuation": 1,
}
)
rm_obj.rate = bom_item.rate if self.backflush_based_on == "BOM" else get_incoming_rate(args)
rm_obj.rate = get_incoming_rate(args)

if self.doctype == self.subcontract_data.order_doctype:
rm_obj.required_qty = qty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,67 @@ def test_supplied_items_cost_after_reposting(self):
self.assertNotEqual(scr.supplied_items[0].rate, prev_cost)
self.assertEqual(scr.supplied_items[0].rate, sr.items[0].valuation_rate)

def test_subcontracting_receipt_raw_material_rate(self):
from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom

# Step - 1: Set Backflush Based On as "BOM"
set_backflush_based_on("BOM")

# Step - 2: Create FG and RM Items
fg_item = make_item(properties={"is_stock_item": 1, "is_sub_contracted_item": 1}).name
rm_item1 = make_item(properties={"is_stock_item": 1}).name
rm_item2 = make_item(properties={"is_stock_item": 1}).name

# Step - 3: Create BOM for FG Item
bom = make_bom(item=fg_item, raw_materials=[rm_item1, rm_item2])
for rm_item in bom.items:
self.assertEqual(rm_item.rate, 0)
self.assertEqual(rm_item.amount, 0)
bom = bom.name

# Step - 4: Create PO and SCO
service_items = [
{
"warehouse": "_Test Warehouse - _TC",
"item_code": "Subcontracted Service Item 1",
"qty": 100,
"rate": 100,
"fg_item": fg_item,
"fg_item_qty": 100,
},
]
sco = get_subcontracting_order(service_items=service_items)
for rm_item in sco.supplied_items:
self.assertEqual(rm_item.rate, 0)
self.assertEqual(rm_item.amount, 0)

# Step - 5: Inward Raw Materials
rm_items = get_rm_items(sco.supplied_items)
for rm_item in rm_items:
rm_item["rate"] = 100
itemwise_details = make_stock_in_entry(rm_items=rm_items)

# Step - 6: Transfer RM's to Subcontractor
se = make_stock_transfer_entry(
sco_no=sco.name,
rm_items=rm_items,
itemwise_details=copy.deepcopy(itemwise_details),
)
for item in se.items:
self.assertEqual(item.qty, 100)
self.assertEqual(item.basic_rate, 100)
self.assertEqual(item.amount, item.qty * item.basic_rate)

# Step - 7: Create Subcontracting Receipt
scr = make_subcontracting_receipt(sco.name)
scr.save()
scr.submit()
scr.load_from_db()
for rm_item in scr.supplied_items:
self.assertEqual(rm_item.consumed_qty, 100)
self.assertEqual(rm_item.rate, 100)
self.assertEqual(rm_item.amount, rm_item.consumed_qty * rm_item.rate)


def make_return_subcontracting_receipt(**args):
args = frappe._dict(args)
Expand Down

0 comments on commit bdfbccd

Please sign in to comment.