Mark exportable invoice as deleted, instead of actually deleting

and allow bulk-delete, but prevent edit
This commit is contained in:
Lance Edgar 2023-08-09 18:06:08 -05:00
parent 74bf66cd71
commit 831403c90a

View file

@ -54,6 +54,8 @@ class ExportableInvoiceView(MasterView):
model_class = QuickbooksExportableInvoice
route_prefix = 'quickbooks.exportable_invoices'
url_prefix = '/quickbooks/exportable-invoices'
editable = False
bulk_deletable = True
has_versions = True
labels = {
@ -171,6 +173,8 @@ class ExportableInvoiceView(MasterView):
g.check_all_handler = 'allChecked'
def grid_extra_class(self, invoice, i):
if invoice.deleted:
return 'warning'
if not self.exportable(invoice):
if invoice.status_code in (invoice.STATUS_DEPTS_IGNORED,
invoice.STATUS_EXPORTED,
@ -203,6 +207,22 @@ class ExportableInvoiceView(MasterView):
"""
return invoice.status_code == invoice.STATUS_EXPORTABLE
def deletable_instance(self, invoice):
if invoice.deleted:
return False
if invoice.exported:
return False
return True
def delete_instance(self, invoice):
app = self.get_rattail_app()
session = app.get_session(invoice)
invoice.deleted = app.make_utc()
# nb. when bulk-deleting, user is in different session
invoice.deleted_by = session.merge(self.request.user)
invoice.status_code = invoice.STATUS_DELETED
session.flush()
def configure_form(self, f):
super(ExportableInvoiceView, self).configure_form(f)
model = self.model