Skip to content

Commit

Permalink
fix: do not allow to delete standard dropdown items
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik committed Jan 3, 2025
1 parent 280af61 commit d0cf66e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
14 changes: 14 additions & 0 deletions crm/fcrm/doctype/fcrm_settings/fcrm_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ class FCRMSettings(Document):
def restore_defaults(self, force=False):
after_install(force)

def validate(self):
self.do_not_allow_to_delete_if_standard()

def do_not_allow_to_delete_if_standard(self):
if not self.has_value_changed("dropdown_items"):
return
old_items = self.get_doc_before_save().get("dropdown_items")
standard_new_items = [d.name1 for d in self.dropdown_items if d.is_standard]
standard_old_items = [d.name1 for d in old_items if d.is_standard]
deleted_standard_items = set(standard_old_items) - set(standard_new_items)
if deleted_standard_items:
frappe.throw(frappe._("Cannot delete standard items {0}").format(", ".join(deleted_standard_items)))



def after_migrate():
sync_table("dropdown_items", "standard_dropdown_items")
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/components/Settings/GeneralSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,32 @@
</div>
</div>

<div class="flex flex-row-reverse">
<div class="flex justify-between flex-row-reverse">
<Button
variant="solid"
:label="__('Update')"
:disabled="!settings.isDirty"
@click="updateSettings"
/>
<ErrorMessage :message="settings.save.error" />
</div>
</div>
</template>
<script setup>
import ImageUploader from '@/components/Controls/ImageUploader.vue'
import Grid from '@/components/Controls/Grid.vue'
import { FormControl, Badge } from 'frappe-ui'
import { FormControl, Badge, ErrorMessage } from 'frappe-ui'
import { getSettings } from '@/stores/settings'
import { showSettings } from '@/composables/settings'
const { _settings: settings, setupBrand } = getSettings()
function updateSettings() {
settings.save.submit()
showSettings.value = false
setupBrand()
settings.save.submit(null, {
onSuccess: () => {
showSettings.value = false
setupBrand()
},
})
}
</script>

0 comments on commit d0cf66e

Please sign in to comment.