Skip to content

Commit

Permalink
fix: allow to set rate manually for service item in BOM (backport #38880
Browse files Browse the repository at this point in the history
) (#38882)

fix: allow to set rate manually for service item in BOM (#38880)

(cherry picked from commit c2f692a)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
  • Loading branch information
mergify[bot] and rohitwaghchaure authored Dec 20, 2023
1 parent ae35339 commit a6ab532
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
3 changes: 3 additions & 0 deletions erpnext/manufacturing/doctype/bom/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,9 @@ def calculate_rm_cost(self, save=False):
base_total_rm_cost = 0

for d in self.get("items"):
if not d.is_stock_item and self.rm_cost_as_per == "Valuation Rate":
continue

old_rate = d.rate
if self.rm_cost_as_per != "Manual":
d.rate = self.get_rm_rate(
Expand Down
29 changes: 29 additions & 0 deletions erpnext/manufacturing/doctype/bom/test_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,35 @@ def test_bom_cost_update_flag(self):
bom.update_cost()
self.assertFalse(bom.flags.cost_updated)

def test_bom_with_service_item_cost(self):
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry

rm_item = make_item(properties={"is_stock_item": 1, "valuation_rate": 1000.0}).name

service_item = make_item(properties={"is_stock_item": 0}).name

fg_item = make_item(properties={"is_stock_item": 1}).name

from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom

bom = make_bom(item=fg_item, raw_materials=[rm_item, service_item], do_not_save=True)
bom.rm_cost_as_per = "Valuation Rate"

for row in bom.items:
if row.item_code == service_item:
row.rate = 566.00
else:
row.rate = 800.00

bom.save()

for row in bom.items:
if row.item_code == service_item:
self.assertEqual(row.is_stock_item, 0)
self.assertEqual(row.rate, 566.00)
else:
self.assertEqual(row.is_stock_item, 1)

def test_do_not_include_manufacturing_and_fixed_items(self):
from erpnext.manufacturing.doctype.bom.bom import item_query

Expand Down
13 changes: 11 additions & 2 deletions erpnext/manufacturing/doctype/bom_item/bom_item.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"bom_no",
"source_warehouse",
"allow_alternative_item",
"is_stock_item",
"section_break_5",
"description",
"col_break1",
Expand Down Expand Up @@ -185,7 +186,7 @@
"in_list_view": 1,
"label": "Rate",
"options": "currency",
"read_only": 1,
"read_only_depends_on": "eval:doc.is_stock_item == 1",
"reqd": 1
},
{
Expand Down Expand Up @@ -284,13 +285,21 @@
"fieldname": "do_not_explode",
"fieldtype": "Check",
"label": "Do Not Explode"
},
{
"default": "0",
"fetch_from": "item_code.is_stock_item",
"fieldname": "is_stock_item",
"fieldtype": "Check",
"label": "Is Stock Item",
"read_only": 1
}
],
"idx": 1,
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-11-14 18:35:51.378513",
"modified": "2023-12-20 16:21:55.477883",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "BOM Item",
Expand Down
1 change: 1 addition & 0 deletions erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,4 @@ execute:frappe.db.set_default("date_format", frappe.db.get_single_value("System
# below migration patch should always run last
erpnext.patches.v14_0.migrate_gl_to_payment_ledger
erpnext.stock.doctype.delivery_note.patches.drop_unused_return_against_index
erpnext.patches.v14_0.set_maintain_stock_for_bom_item
19 changes: 19 additions & 0 deletions erpnext/patches/v14_0/set_maintain_stock_for_bom_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import frappe


def execute():
if not frappe.db.exists("BOM", {"docstatus": 1}):
return

# Added is_stock_item to handle Read Only based on condition for the rate field
frappe.db.sql(
"""
UPDATE
`tabBOM Item` boi,
`tabItem` i
SET
boi.is_stock_item = i.is_stock_item
WHERE
boi.item_code = i.name
"""
)

0 comments on commit a6ab532

Please sign in to comment.