def test_update_bom_cost_in_all_boms(self): # get current rate for '_Test Item 2' rm_rate = frappe.db.sql("""select rate from `tabBOM Item` where parent='BOM-_Test Item Home Desktop Manufactured-001' and item_code='_Test Item 2' and docstatus=1 and parenttype='BOM'""") rm_rate = rm_rate[0][0] if rm_rate else 0 # update valuation rate of item '_Test Item 2' warehouse_list = frappe.db.sql_list("""select warehouse from `tabBin` where item_code='_Test Item 2' and actual_qty > 0""") if not warehouse_list: warehouse_list.append("_Test Warehouse - _TC") for warehouse in warehouse_list: create_stock_reconciliation(item_code="_Test Item 2", warehouse=warehouse, qty=200, rate=rm_rate + 10) # update cost of all BOMs based on latest valuation rate update_cost() # check if new valuation rate updated in all BOMs for d in frappe.db.sql("""select rate from `tabBOM Item` where item_code='_Test Item 2' and docstatus=1 and parenttype='BOM'""", as_dict=1): self.assertEqual(d.rate, rm_rate + 10)
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)
def test_update_bom_cost_in_all_boms(self): # get current rate for '_Test Item 2' rm_rate = frappe.db.sql("""select rate from `tabBOM Item` where parent='BOM-_Test Item Home Desktop Manufactured-001' and item_code='_Test Item 2' and docstatus=1""") rm_rate = rm_rate[0][0] if rm_rate else 0 # update valuation rate of item '_Test Item 2' warehouse_list = frappe.db.sql_list("""select warehouse from `tabBin` where item_code='_Test Item 2' and actual_qty > 0""") if not warehouse_list: warehouse_list.append("_Test Warehouse - _TC") for warehouse in warehouse_list: create_stock_reconciliation(item_code="_Test Item 2", warehouse=warehouse, qty=200, rate=rm_rate + 10) # update cost of all BOMs based on latest valuation rate update_cost() # check if new valuation rate updated in all BOMs for d in frappe.db.sql("""select rate from `tabBOM Item` where item_code='_Test Item 2' and docstatus=1""", as_dict=1): self.assertEqual(d.rate, rm_rate + 10)
def run_bom_job( doc: "BOMUpdateLog", boms: Optional[Dict[str, str]] = None, update_type: Literal["Replace BOM", "Update Cost"] = "Replace BOM", ) -> None: try: doc.db_set("status", "In Progress") if not frappe.flags.in_test: frappe.db.commit() frappe.db.auto_commit_on_many_writes = 1 boms = frappe._dict(boms or {}) if update_type == "Replace BOM": replace_bom(boms) else: update_cost() doc.db_set("status", "Completed") except Exception: frappe.db.rollback() error_log = doc.log_error("BOM Update Tool Error") doc.db_set("status", "Failed") doc.db_set("error_log", error_log.name) finally: frappe.db.auto_commit_on_many_writes = 0 frappe.db.commit() # nosemgrep
def test_update_bom_cost_in_all_boms(self): # get current rate for '_Test Item 2' rm_rate = frappe.db.sql("""select rate from `tabBOM Item` where parent='BOM-_Test Item Home Desktop Manufactured-001' and item_code='_Test Item 2' and docstatus=1 and parenttype='BOM'""") rm_rate = rm_rate[0][0] if rm_rate else 0 # Reset item valuation rate reset_item_valuation_rate(item_code='_Test Item 2', qty=200, rate=rm_rate + 10) # update cost of all BOMs based on latest valuation rate update_cost() # check if new valuation rate updated in all BOMs for d in frappe.db.sql("""select rate from `tabBOM Item` where item_code='_Test Item 2' and docstatus=1 and parenttype='BOM'""", as_dict=1): self.assertEqual(d.rate, rm_rate + 10)