Error in query: could not serialize access due to concurrent update - using Postgres

It updates the value in Employee Document initially but when i try to do that again i mean trying to update it once more time it gives me error Error in query:
could not serialize access due to concurrent update.

here is a complete code
frappe.ui.form.on(‘Employee Transfer’, {
refresh: function(frm) {
frm.fields_dict[‘detail_grid’].grid.wrapper.find(‘.grid-add-row’).remove();
toggleTransferDetails(frm);
},
employee: function(frm) {
toggleTransferDetails(frm);
},
property: function(frm) {
console.log(“Inside on change of field property”);
// Disable input fields during async operation
frm.toggle_enable(‘property’, false);
frm.toggle_enable(‘current’, false);
frm.toggle_enable(‘new’, false);

  frappe.call({
    method: 'hr.hr.utils.get_employee_field_property',
    args: { employee: frm.doc.employee, fieldname: frm.doc.property },
    callback: function(r) {
      if (r.message) {
        console.log(r);
        frm.doc.current = r.message.value;
        frm.refresh_field('current');
        render_dynamic_field(frm, r.message.datatype, r.message.options, frm.doc.property);
      }
      // Enable input fields after async operation completes
      frm.toggle_enable('property', true);
      frm.toggle_enable('current', true);
      frm.toggle_enable('new', true);
    },
    error: function(err) {
      // Handle specific error scenarios and provide appropriate messages
      console.log('Error: ', err);
      frappe.msgprint('An error occurred while fetching property details.');
    }
  });
},
add_to_grid: function(frm) {
  var property = frm.doc.property;
  var current = frm.doc.current;
  var new_value = frm.fields_dict.new.input.value;

  // Check if the property already exists in the grid

var gridRows = frm.doc.detail_grid || [];
for (var i = 0; i < gridRows.length; i++) {
if (gridRows[i].property === property) {
frappe.msgprint(‘This property already exists in the grid.’);
return;
}
}

  if (!property || !current || !new_value) {
    frappe.msgprint('Please enter all values (Property, Current, New) before adding to the grid.');
    return;
  }

  var row = frappe.model.add_child(frm.doc, 'Employee Transfer Details', 'detail_grid');

  row.property = property;
  row.current = current;
  row.new = new_value;

  frm.refresh_field('detail_grid');

  // Reset the field values to null
  frm.doc.property = null;
  frm.doc.current = null;
  frm.doc.new = null;
  frm.refresh_field('property');
  frm.refresh_field('current');
  frm.refresh_field('new');
},

on_submit: function(frm) {
  updateEmployeeDetails(frm);

},

});

var render_dynamic_field = function(frm, fieldtype, options, fieldname) {
var dynamic_field = frappe.ui.form.make_control({
df: {
fieldtype: fieldtype,
fieldname: fieldname,
options: options || ‘’,
label: ‘New’
},
parent: frm.fields_dict.new.wrapper,
only_input: false
});
dynamic_field.make_input();
frm.layout.replace_field(‘new’, dynamic_field.df);
console.log(frm.fields_dict);
};
function toggleTransferDetails(frm) {
var isEmployeeSelected = frm.doc.employee;
frm.toggle_display(‘detail_grid’, isEmployeeSelected);
frm.toggle_display(‘property’, isEmployeeSelected);
frm.toggle_display(‘current’, isEmployeeSelected);
frm.toggle_display(‘new’, isEmployeeSelected);
frm.toggle_display(‘add_to_grid’, isEmployeeSelected);

var field = frappe.meta.get_docfield('Employee Transfer', 'property', frm.docname);

const allowed_fields = [];
const exclude_fields = [];
const exclude_field_types = ["HTML", "Section Break", "Column Break", "Button", "Read Only", "Tab Break", "Table"];

frappe.model.with_doctype('Employee', () => {
  frappe.get_meta('Employee').fields.forEach(field => {
    if (!exclude_field_types.includes(field.fieldtype) && !exclude_fields.includes(field.fieldname)) {
      allowed_fields.push({
        label: `${__(field.label)} (${field.fieldname})`,
        value: field.fieldname
      });
    }
  });

  field.options = allowed_fields;
  frm.set_df_property('property', field);
});
frm.refresh_fields();

}

function updateEmployeeDetails(frm) {
var transferDetails = frm.doc.detail_grid || [];

// Create an array of promises for each update operation
var updatePromises = transferDetails.map(function (detail) {
var employeeID = frm.doc.employee;
var property = detail.property;
var newValue = detail.new;

return frappe.call({
  method: 'frappe.client.set_value',
  args: {
    doctype: 'Employee',
    name: employeeID,
    fieldname: property,
    value: newValue
  }
});

});

// Execute all promises and wait for them to complete
Promise.all(updatePromises)
.then(function () {
frappe.msgprint(‘Employee details have been updated successfully.’);
})
.catch(function (error) {
console.log(error);
frappe.msgprint(‘An error occurred while updating the Employee document.’);
});
}