fix: BOM cost update message

(cherry picked from commit 9cfe527492)

# Conflicts:
#	erpnext/manufacturing/doctype/bom/test_bom.py
This commit is contained in:
Rohit Waghchaure
2022-10-20 13:49:46 +05:30
committed by Mergify
parent 2df24ec459
commit 98bcb7255d
2 changed files with 41 additions and 1 deletions

View File

@@ -384,6 +384,7 @@ class BOM(WebsiteGenerator):
if self.docstatus == 2:
return
self.flags.cost_updated = False
existing_bom_cost = self.total_cost
if self.docstatus == 1:
@@ -406,7 +407,11 @@ class BOM(WebsiteGenerator):
frappe.get_doc("BOM", bom).update_cost(from_child_bom=True)
if not from_child_bom:
frappe.msgprint(_("Cost Updated"), alert=True)
msg = "Cost Updated"
if not self.flags.cost_updated:
msg = "No changes in cost found"
frappe.msgprint(_(msg), alert=True)
def update_parent_cost(self):
if self.total_cost:
@@ -592,11 +597,16 @@ class BOM(WebsiteGenerator):
# not via doc event, table is not regenerated and needs updation
self.calculate_exploded_cost()
old_cost = self.total_cost
self.total_cost = self.operating_cost + self.raw_material_cost - self.scrap_material_cost
self.base_total_cost = (
self.base_operating_cost + self.base_raw_material_cost - self.base_scrap_material_cost
)
if self.total_cost != old_cost:
self.flags.cost_updated = True
def calculate_op_cost(self, update_hour_rate=False):
"""Update workstation rate and calculates totals"""
self.operating_cost = 0

View File

@@ -9,8 +9,16 @@ import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import cstr, flt
<<<<<<< HEAD
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
from erpnext.manufacturing.doctype.bom.bom import BOMRecursionError, item_query
=======
from erpnext.controllers.tests.test_subcontracting_controller import (
make_stock_in_entry,
set_backflush_based_on,
)
from erpnext.manufacturing.doctype.bom.bom import BOMRecursionError, item_query, make_variant_bom
>>>>>>> 9cfe527492 (fix: BOM cost update message)
from erpnext.manufacturing.doctype.bom_update_log.test_bom_update_log import (
update_cost_in_all_boms_in_test,
)
@@ -583,6 +591,28 @@ class TestBOM(FrappeTestCase):
bom.submit()
self.assertEqual(bom.exploded_items[0].rate, bom.items[0].base_rate)
def test_bom_cost_update_flag(self):
rm_item = make_item(
properties={"is_stock_item": 1, "valuation_rate": 99, "last_purchase_rate": 89}
).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])
create_stock_reconciliation(
item_code=rm_item, warehouse="_Test Warehouse - _TC", qty=100, rate=600
)
bom.load_from_db()
bom.update_cost()
self.assertTrue(bom.flags.cost_updated)
bom.load_from_db()
bom.update_cost()
self.assertFalse(bom.flags.cost_updated)
def get_default_bom(item_code="_Test FG Item 2"):
return frappe.db.get_value("BOM", {"item": item_code, "is_active": 1, "is_default": 1})