After Saving changes not saving for that Item document

Hello,

I have written one sever script and there i have used After save event. There basically i am calculating some values and assigning to the field like below

if length != 0 and width != 0 and height != 0:
vol = ((heightlengthwidth)/1000000)
doc.custom_volume_cms = vol

if packing_gms != 0 and pcs_ctn != 0:
net_weight = ((packing_gms*pcs_ctn)/1000)
doc.custom_net_weight_corton_kg = net_weight

but when i save that Item after giving values the it stores the value in respected field but whenever i used to refresh the page it goes back to previous values. below is the entire script

lpp_exists = frappe.db.exists(“Latest Purchase Price”, {“item_code”: doc.item_code})
items_costs_exists = frappe.db.exists(“Items Costs”, {“item_code”: doc.item_code})
master_qty_exist = frappe.db.exists(“Master Qty”, {“item_code”: doc.item_code})

price_list = “MPL-” + doc.customer_name

existing_buying_item_price = frappe.get_all(“Item Price”, filters={“item_code”: doc.item_code, “price_list”: “Standard Buying”})
existing_selling_item_price = frappe.get_all(“Item Price”, filters={“item_code”: doc.item_code, “price_list”: “Standard Selling”})
length = float(doc.custom_length_cms or 0)
width = float(doc.custom_width_cms or 0)
height = float(doc.custom_height_cms or 0)
packing_gms = float(doc.custom_packing_in_gms or 0)
pcs_ctn = float(doc.custom_no_of_pcsctn or 0)

if length != 0 and width != 0 and height != 0:
vol = ((heightlengthwidth)/1000000)
doc.custom_volume_cms = vol

if packing_gms != 0 and pcs_ctn != 0:
net_weight = ((packing_gms*pcs_ctn)/1000)
doc.custom_net_weight_corton_kg = net_weight

if(doc.item_brand_type == ‘Customer Specific Brand’):
price_list = “MPL-” + doc.customer_name
existing_item_price = frappe.get_all(“Item Price”, filters={“item_code”: doc.item_code, “price_list”: price_list})
if(not existing_item_price):
new_item_price = frappe.new_doc(“Item Price”)
new_item_price.item_code = doc.item_code
new_item_price.price_list = price_list
new_item_price.price_list_rate = doc.valuation_rate
new_item_price.selling = 1
new_item_price.gst_rate = doc.custom_gst_rate
new_item_price.mrp_product = doc.custom_mrp_product_
new_item_price.save()
doc.save()

else:
existing_selling_item_price = frappe.get_all(“Item Price”, filters={“item_code”: doc.item_code, “price_list”: “Standard Selling”})
existing_buying_item_price = frappe.get_all(“Item Price”, filters={“item_code”: doc.item_code, “price_list”: “Standard Buying”})

if(not existing_selling_item_price and not existing_buying_item_price):
    new_item_price = frappe.new_doc("Item Price")
    new_item_price.item_code = doc.item_code
    new_item_price.price_list = "Standard Selling"
    new_item_price.price_list_rate = 0
    new_item_price.selling = 1
    new_item_price.gst_rate = doc.custom_gst_rate 
    new_item_price.mrp_product = doc.custom_mrp_product_
    
    new_item_price1 = frappe.new_doc("Item Price")
    new_item_price1.item_code = doc.item_code
    new_item_price1.price_list = "Standard Buying"
    new_item_price1.price_list_rate = doc.valuation_rate
    new_item_price1.buying = 1
    new_item_price1.gst_rate = doc.custom_gst_rate 
    new_item_price1.mrp_product = doc.custom_mrp_product_
    
    new_item_price.save()
    new_item_price1.save()

if items_costs_exists and lpp_exists and master_qty_exist:
pass
else:
# Create a new document
new_items_costs = frappe.new_doc(‘Items Costs’)
new_items_costs.item_code = doc.item_code
new_items_costs.freight_cost_criteria = “Percent”
new_items_costs.freight_cost_percent = 5
new_items_costs.storage_cost_criteria = “Percent”
new_items_costs.storage_cost_percent = 5
new_items_costs.shipping_cost_criteria = “Percent”
new_items_costs.shipping_cost_percent = 5

new_lpp = frappe.new_doc('Latest Purchase Price')
new_lpp.item_code = doc.item_code
new_lpp.item_name = doc.item_name
new_lpp.updated_date = frappe.utils.getdate()
new_lpp.rate = doc.valuation_rate

new_master_qty = frappe.new_doc('Master Qty')
new_master_qty.item_code = doc.item_code
new_master_qty.item_name = doc.item_name
new_master_qty.actual_qty = 0
new_master_qty.opportunity_qty = 0
new_master_qty.available_qty = 0

new_items_costs.insert()
new_lpp.insert()
new_master_qty.insert()


frappe.msgprint(f"New Latest Purchase Price is created for {doc.item_name} with Rate {doc.valuation_rate}")
frappe.msgprint(f"New Items Costs is created for {doc.item_name}.")
frappe.msgprint(f"New Master Qty is created for {doc.item_name}.")