Don’t allow editing cancelled/reversed invoices

This commit is contained in:
Hillel Coren 2020-06-24 23:24:57 +03:00
parent 9010a8084d
commit c57551504f
4 changed files with 19 additions and 2 deletions

View File

@ -259,6 +259,8 @@ abstract class BaseEntity implements SelectableEntity {
bool get isArchived =>
archivedAt != null && archivedAt > 0 && !(isDeleted ?? false);
bool get isEditable => !isDeleted;
bool userCanAccess(String userId) =>
createdUserId == userId || assignedUserId == userId;

View File

@ -337,6 +337,21 @@ abstract class InvoiceEntity extends Object
bool get hasInvoice => '${invoiceId ?? ''}'.isNotEmpty;
@override
bool get isEditable {
if (isDeleted) {
return false;
}
if (entityType == EntityType.invoice) {
if (isCancelledOrReversed) {
return false;
}
}
return true;
}
int get age {
int ageInDays = 0;
if (isPastDue) {

View File

@ -740,7 +740,7 @@ void editEntityById(
final map = store.state.getEntityMap(entityType);
final entity = map[entityId] as BaseEntity;
if (entity.isDeleted) {
if (!entity.isEditable) {
return;
}

View File

@ -87,7 +87,7 @@ class ViewScaffold extends StatelessWidget {
userCompany.canEditEntity(entity)
? Builder(builder: (context) {
return EditIconButton(
isVisible: !(entity.isDeleted ?? false),
isVisible: entity.isEditable,
onPressed: () =>
editEntity(context: context, entity: entity),
);