nwabunike harrison
nwabunike harrison

Reputation: 1

Frappe not updating database

please i am new to programming. i am working on a project on frappe. my database dont update. please can someone help me out

DETAILS OF THE PROBLEM i made a button on a doctype inventory_reconcilation the code is as follows //

frappe.ui.form.on('Inventory Reconciliation', {
    update_inventory: function(frm) {
        
        frappe.call({
            method: "parkeyauto.api.reconcile_item_quantity",
            freeze:true,
            callback: (response) => {
                console.log(response)
                                
            }
            
        })
        
    }
});

it is to call an api and update my database the api code is

#from future import unicode_literals import frappe

#http://localhost:8001/api/method/parkeyauto.api.reconcile_item_quantity

@frappe.whitelist()
def reconcile_item_quantity():
    update_item_lists_to_zero_total()
   
def update_item_lists_to_zero_total():      
    try:
        query = ("SELECT item_name,initial_inventory_qty,po_qty, so_qty, damaged_qty, missing_qty, average_cost_price FROM _d101da5a9b48a4a9.`tabItem2`;")
        result_array = frappe.db.sql(query, as_dict=True)
        for detail in result_array:           
            item = frappe.get_doc('Item', detail.item_name)
            item.initial_inventory_qty = 0
            item.po_qty  = 0
            item.so_qty = 0
            item.damaged_qty = 0
            item.missing_qty  = 0
            item.average_cost_price = 0
            item.save()            
        return True
    except Exception as e:
        return e
 

please i need to know why my database is not updating.

Upvotes: 0

Views: 1566

Answers (1)

Rushabh Mehta
Rushabh Mehta

Reputation: 1563

If you are using a GET query, you have to explicitly commit to the database.

Add frappe.db.commit() to your server side code.

Upvotes: 1

Related Questions