From d0a44ff5cfad5d063929426e2420f6f0d55b1dbe Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Tue, 9 Jul 2024 07:58:34 +0530 Subject: added custom fields support --- invoice/hooks.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'invoice/hooks.go') diff --git a/invoice/hooks.go b/invoice/hooks.go index 7a59352..b0ec877 100644 --- a/invoice/hooks.go +++ b/invoice/hooks.go @@ -85,3 +85,35 @@ func (i *InvoiceItem) BeforeDelete(tx *gorm.DB) error { return nil } + +func (cf *CustomField) BeforeSave(tx *gorm.DB) error { + var err error + + isDraft, err := isDraft(cf.InvoiceID) + if err != nil { + return err + } + + if !isDraft { + return errors.ErrCannotEditInvoice + } + + // TODO: check if field is duplicate + + return nil +} + +func (cf *CustomField) BeforeDelete(tx *gorm.DB) error { + var err error + + isDraft, err := isDraft(cf.InvoiceID) + if err != nil { + return err + } + + if !isDraft { + return errors.ErrCannotEditInvoice + } + + return nil +} -- cgit v1.2.3