aboutsummaryrefslogtreecommitdiff
path: root/invoice/hooks.go
diff options
context:
space:
mode:
Diffstat (limited to 'invoice/hooks.go')
-rw-r--r--invoice/hooks.go32
1 files changed, 32 insertions, 0 deletions
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
+}