feat: enforce singleton active invoice template per language during updates and revisions
This commit is contained in:
parent
f544dab9a3
commit
221bac3b2a
@ -135,6 +135,14 @@ class DocumentTemplateService {
|
|||||||
}, uow.connection);
|
}, uow.connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enforce singleton active invoice template per lang
|
||||||
|
if (state === 'active' && current.type === 'invoice') {
|
||||||
|
await DocumentTemplateRepository.deactivateOtherActiveInvoices({
|
||||||
|
excludeId: id,
|
||||||
|
lang: current.lang,
|
||||||
|
}, uow.connection);
|
||||||
|
}
|
||||||
|
|
||||||
const updated = await DocumentTemplateRepository.findById(id, uow.connection);
|
const updated = await DocumentTemplateRepository.findById(id, uow.connection);
|
||||||
await uow.commit();
|
await uow.commit();
|
||||||
logger.info('DocumentTemplateService.updateTemplateState:success', { id, state });
|
logger.info('DocumentTemplateService.updateTemplateState:success', { id, state });
|
||||||
@ -186,6 +194,15 @@ class DocumentTemplateService {
|
|||||||
}, uow.connection);
|
}, uow.connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If new template is active and is an invoice template, deactivate other active invoices for same lang
|
||||||
|
const effectiveType = data.type || previous.type;
|
||||||
|
if (nextState === 'active' && effectiveType === 'invoice') {
|
||||||
|
await DocumentTemplateRepository.deactivateOtherActiveInvoices({
|
||||||
|
excludeId: created.id,
|
||||||
|
lang: (data.lang || previous.lang),
|
||||||
|
}, uow.connection);
|
||||||
|
}
|
||||||
|
|
||||||
// Deactivate previous (requirement: deactive the previous one)
|
// Deactivate previous (requirement: deactive the previous one)
|
||||||
await DocumentTemplateRepository.updateState(previousId, 'inactive', uow.connection);
|
await DocumentTemplateRepository.updateState(previousId, 'inactive', uow.connection);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user