aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/customer
diff options
context:
space:
mode:
Diffstat (limited to 'customer')
-rw-r--r--customer/customer.go41
-rw-r--r--customer/hooks.go16
-rw-r--r--customer/service.go8
3 files changed, 23 insertions, 42 deletions
diff --git a/customer/customer.go b/customer/customer.go
index 521c531..0d107d7 100644
--- a/customer/customer.go
+++ b/customer/customer.go
@@ -1,5 +1,5 @@
/* openbills - Server for web based Libre Billing Software
- * Copyright (C) 2023-2024 Vidhu Kant Sharma <vidhukant@vidhukant.com>
+ * Copyright (C) 2023-2025 Vidhu Kant Sharma <vidhukant@vidhukant.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,36 +20,33 @@ package customer
import (
"gorm.io/gorm"
d "vidhukant.com/openbills/db"
- u "vidhukant.com/openbills/util"
)
var db *gorm.DB
func init() {
db = d.DB
- db.AutoMigrate(&Customer{}, &CustomerBillingAddress{}, &CustomerShippingAddress{})
+ db.AutoMigrate(&Customer{})
}
-type CustomerBillingAddress struct {
+type Customer struct {
gorm.Model
- u.Address
- CustomerID uint
-}
+ FirmName string
+ Gstin string
+ ContactName string
+ Phone string
+ Email string
+ Website string
-type CustomerShippingAddress struct {
- gorm.Model
- u.Address
- CustomerID uint
-}
+ BillingAddressText string
+ BillingAddressCity string
+ BillingAddressState string
+ BillingAddressPostalCode string
+ BillingAddressCountry string
-type Customer struct {
- gorm.Model
- FirmName string
- Gstin string
- ContactName string
- Phone string
- Email string
- Website string
- BillingAddress CustomerBillingAddress
- ShippingAddress CustomerShippingAddress
+ ShippingAddressText string
+ ShippingAddressCity string
+ ShippingAddressState string
+ ShippingAddressPostalCode string
+ ShippingAddressCountry string
}
diff --git a/customer/hooks.go b/customer/hooks.go
index 148004f..7f715c3 100644
--- a/customer/hooks.go
+++ b/customer/hooks.go
@@ -1,5 +1,5 @@
/* openbills - Server for web based Libre Billing Software
- * Copyright (C) 2023 Vidhu Kant Sharma <vidhukant@vidhukant.com>
+ * Copyright (C) 2023-2025 Vidhu Kant Sharma <vidhukant@vidhukant.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -39,19 +39,5 @@ func (c *Customer) BeforeDelete(tx *gorm.DB) error {
return errors.ErrNoWhereCondition
}
- var err error
-
- // delete billing address
- err = db.Where("customer_id = ?", c.ID).Delete(&CustomerBillingAddress{}).Error
- if err != nil {
- return err
- }
-
- // delete shipping address
- err = db.Where("customer_id = ?", c.ID).Delete(&CustomerShippingAddress{}).Error
- if err != nil {
- return err
- }
-
return nil
}
diff --git a/customer/service.go b/customer/service.go
index ca401f1..0286c3e 100644
--- a/customer/service.go
+++ b/customer/service.go
@@ -1,5 +1,5 @@
/* openbills - Server for web based Libre Billing Software
- * Copyright (C) 2023 Vidhu Kant Sharma <vidhukant@vidhukant.com>
+ * Copyright (C) 2023-2025 Vidhu Kant Sharma <vidhukant@vidhukant.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,11 +19,10 @@ package customer
import (
e "vidhukant.com/openbills/errors"
- "gorm.io/gorm"
)
func getCustomer(customer *Customer, id uint) error {
- res := db.Preload("BillingAddress").Preload("ShippingAddress").Find(&customer, id)
+ res := db.Find(&customer, id)
// TODO: handle potential errors
if res.Error != nil {
@@ -53,8 +52,7 @@ func getCustomers(customers *[]Customer) error {
}
func (c *Customer) upsert() error {
- db.Model(&c).Association("ShippingAddress").Replace(c.ShippingAddress)
- res := db.Session(&gorm.Session{FullSaveAssociations: true}).Save(&c)
+ res := db.Save(&c)
// TODO: handle potential errors
return res.Error
}