mirror of
https://github.com/aclindsa/moneygo.git
synced 2025-07-02 20:28:38 -04:00
Add per-user default currency
This commit is contained in:
@ -36,7 +36,7 @@ type Security struct {
|
||||
// security is precise to
|
||||
Precision int
|
||||
Type int64
|
||||
// AlternateId is CUSIP for Type=Stock
|
||||
// AlternateId is CUSIP for Type=Stock, ISO4217 for Type=Currency
|
||||
AlternateId string
|
||||
}
|
||||
|
||||
@ -86,6 +86,16 @@ func FindSecurityTemplate(name string, _type int64) *Security {
|
||||
return nil
|
||||
}
|
||||
|
||||
func FindCurrencyTemplate(iso4217 int64) *Security {
|
||||
iso4217string := strconv.FormatInt(iso4217, 10)
|
||||
for _, security := range SecurityTemplates {
|
||||
if security.Type == Currency && security.AlternateId == iso4217string {
|
||||
return &security
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetSecurity(securityid int64, userid int64) (*Security, error) {
|
||||
var s Security
|
||||
|
||||
@ -171,6 +181,15 @@ func DeleteSecurity(s *Security) error {
|
||||
return errors.New("One or more accounts still use this security")
|
||||
}
|
||||
|
||||
user, err := GetUserTx(transaction, s.UserId)
|
||||
if err != nil {
|
||||
transaction.Rollback()
|
||||
return err
|
||||
} else if user.DefaultCurrency == s.SecurityId {
|
||||
transaction.Rollback()
|
||||
return errors.New("Cannot delete security which is user's default currency")
|
||||
}
|
||||
|
||||
count, err := transaction.Delete(s)
|
||||
if err != nil {
|
||||
transaction.Rollback()
|
||||
|
Reference in New Issue
Block a user