fix: bom update cost issue (#21372)

* fix: bom update cost is not working

* added test case for bom cost
This commit is contained in:
rohitwaghchaure 2020-04-23 09:48:50 +05:30 committed by GitHub
parent 6fa6caf46c
commit 168babfebc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 6 deletions

View File

@ -246,12 +246,13 @@ class BOM(WebsiteGenerator):
if rate:
d.rate = rate
d.amount = flt(d.rate) * flt(d.qty)
d.db_update()
if self.docstatus == 1:
self.flags.ignore_validate_update_after_submit = True
self.calculate_cost()
if save:
self.save()
self.db_update()
self.update_exploded_items()
# update parent BOMs

View File

@ -82,7 +82,7 @@ def enqueue_replace_bom(args):
@frappe.whitelist()
def enqueue_update_cost():
frappe.enqueue("erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool.update_cost")
frappe.enqueue("erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool.update_cost", timeout=40000)
frappe.msgprint(_("Queued for updating latest price in all Bill of Materials. It may take a few minutes."))
def update_latest_price_in_all_boms():
@ -98,6 +98,9 @@ def replace_bom(args):
doc.replace_bom()
def update_cost():
frappe.db.auto_commit_on_many_writes = 1
bom_list = get_boms_in_bottom_up_order()
for bom in bom_list:
frappe.get_doc("BOM", bom).update_cost(update_parent=False, from_child_bom=True)
frappe.get_doc("BOM", bom).update_cost(update_parent=False, from_child_bom=True)
frappe.db.auto_commit_on_many_writes = 0

View File

@ -5,6 +5,9 @@
from __future__ import unicode_literals
import unittest
import frappe
from erpnext.stock.doctype.item.test_item import create_item
from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom
from erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool import update_cost
test_records = frappe.get_test_records('BOM')
@ -27,4 +30,31 @@ class TestBOMUpdateTool(unittest.TestCase):
# reverse, as it affects other testcases
update_tool.current_bom = bom_doc.name
update_tool.new_bom = current_bom
update_tool.replace_bom()
update_tool.replace_bom()
def test_bom_cost(self):
for item in ["BOM Cost Test Item 1", "BOM Cost Test Item 2", "BOM Cost Test Item 3"]:
item_doc = create_item(item, valuation_rate=100)
if item_doc.valuation_rate != 100.00:
frappe.db.set_value("Item", item_doc.name, "valuation_rate", 100)
bom_no = frappe.db.get_value('BOM', {'item': 'BOM Cost Test Item 1'}, "name")
if not bom_no:
doc = make_bom(item = 'BOM Cost Test Item 1',
raw_materials =['BOM Cost Test Item 2', 'BOM Cost Test Item 3'], currency="INR")
else:
doc = frappe.get_doc("BOM", bom_no)
self.assertEquals(doc.total_cost, 200)
frappe.db.set_value("Item", "BOM Cost Test Item 2", "valuation_rate", 200)
update_cost()
doc.load_from_db()
self.assertEquals(doc.total_cost, 300)
frappe.db.set_value("Item", "BOM Cost Test Item 2", "valuation_rate", 100)
update_cost()
doc.load_from_db()
self.assertEquals(doc.total_cost, 200)

View File

@ -192,9 +192,10 @@ def make_bom(**args):
args = frappe._dict(args)
bom = frappe.get_doc({
'doctype': "BOM",
'doctype': 'BOM',
'is_default': 1,
'item': args.item,
'currency': args.currency or 'USD',
'quantity': args.quantity or 1,
'company': args.company or '_Test Company'
})
@ -211,4 +212,5 @@ def make_bom(**args):
})
bom.insert(ignore_permissions=True)
bom.submit()
bom.submit()
return bom