aboutsummaryrefslogtreecommitdiff
path: root/invoice/hooks.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2024-07-09 07:58:34 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2024-07-09 07:58:34 +0530
commitd0a44ff5cfad5d063929426e2420f6f0d55b1dbe (patch)
tree476ad4ff14e39bed40049b4d1cba296c6d395c1b /invoice/hooks.go
parent908fb4b2b0fd1c31aa8c1cc87f56d490b42aca7a (diff)
added custom fields supportv0.9.0
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
+}