fix(documents): correct demo sequences and save errors (#740)

This commit is contained in:
Darko Gjorgjijoski
2026-08-02 17:31:03 +02:00
committed by GitHub
parent 1e72d9d449
commit 8ae82ae91e
5 changed files with 164 additions and 38 deletions

View File

@@ -115,6 +115,11 @@ import {
} from '@vuelidate/validators'
import useVuelidate from '@vuelidate/core'
import { useEstimateStore } from '../store'
import { useNotificationStore } from '@/scripts/stores/notification.store'
import {
handleApiError,
getErrorTranslationKey,
} from '@/scripts/utils/error-handling'
import EstimateBasicFields from '../components/EstimateBasicFields.vue'
import {
DocumentItemsTable,
@@ -125,6 +130,7 @@ import {
} from '../../../shared/document-form'
const estimateStore = useEstimateStore()
const notificationStore = useNotificationStore()
const { t } = useI18n()
const route = useRoute()
const router = useRouter()
@@ -200,32 +206,32 @@ async function submitForm(): Promise<void> {
isSaving.value = true
const data: Record<string, unknown> = {
...cloneDeep(estimateStore.newEstimate),
sub_total: Math.round(estimateStore.getSubTotal),
total: Math.round(estimateStore.getTotal),
tax: Math.round(estimateStore.getTotalTax),
}
const items = data.items as Array<Record<string, unknown>>
if (data.discount_per_item === 'YES') {
items.forEach((item, index) => {
if (item.discount_type === 'fixed') {
items[index].discount = Math.round((item.discount as number) * 100)
}
})
} else {
if (data.discount_type === 'fixed') {
data.discount = Math.round((data.discount as number) * 100)
}
}
const taxes = data.taxes as Array<Record<string, unknown>>
if (data.tax_per_item !== 'YES' && taxes.length) {
data.tax_type_ids = taxes.map((tax) => tax.tax_type_id)
}
try {
const data: Record<string, unknown> = {
...cloneDeep(estimateStore.newEstimate),
sub_total: Math.round(estimateStore.getSubTotal),
total: Math.round(estimateStore.getTotal),
tax: Math.round(estimateStore.getTotalTax),
}
const items = data.items as Array<Record<string, unknown>>
if (data.discount_per_item === 'YES') {
items.forEach((item, index) => {
if (item.discount_type === 'fixed') {
items[index].discount = Math.round((item.discount as number) * 100)
}
})
} else {
if (data.discount_type === 'fixed') {
data.discount = Math.round((data.discount as number) * 100)
}
}
const taxes = data.taxes as Array<Record<string, unknown>>
if (data.tax_per_item !== 'YES' && taxes.length) {
data.tax_type_ids = taxes.map((tax) => tax.tax_type_id)
}
const action = isEdit.value
? estimateStore.updateEstimate
: estimateStore.addEstimate
@@ -234,10 +240,16 @@ async function submitForm(): Promise<void> {
if (res.data.data) {
router.push(`/admin/estimates/${res.data.data.id}/view`)
}
} catch (err) {
console.error(err)
}
} catch (err: unknown) {
const normalized = handleApiError(err)
const translationKey = getErrorTranslationKey(normalized.message)
isSaving.value = false
notificationStore.showNotification({
type: 'error',
message: translationKey ? t(translationKey) : normalized.message,
})
} finally {
isSaving.value = false
}
}
</script>

View File

@@ -121,6 +121,11 @@ import useVuelidate from '@vuelidate/core'
import { useInvoiceStore } from '../store'
import { useRecurringInvoiceStore } from '@/scripts/features/company/recurring-invoices/store'
import { useCompanyStore } from '@/scripts/stores/company.store'
import { useNotificationStore } from '@/scripts/stores/notification.store'
import {
handleApiError,
getErrorTranslationKey,
} from '@/scripts/utils/error-handling'
import InvoiceBasicFields from '../components/InvoiceBasicFields.vue'
import {
DocumentItemsTable,
@@ -133,6 +138,7 @@ import {
const invoiceStore = useInvoiceStore()
const recurringInvoiceStore = useRecurringInvoiceStore()
const companyStore = useCompanyStore()
const notificationStore = useNotificationStore()
const { t } = useI18n()
const route = useRoute()
const router = useRouter()
@@ -426,10 +432,16 @@ async function submitForm(): Promise<void> {
const response = await action(data)
router.push(`/admin/invoices/${response.data.data.id}/view`)
}
} catch (err) {
console.error(err)
}
} catch (err: unknown) {
const normalized = handleApiError(err)
const translationKey = getErrorTranslationKey(normalized.message)
isSaving.value = false
notificationStore.showNotification({
type: 'error',
message: translationKey ? t(translationKey) : normalized.message,
})
} finally {
isSaving.value = false
}
}
</script>