mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-12-26 07:33:21 -05:00
Add user-editable securities, strip hard-coded ones from securities.go
This commit is contained in:
parent
7ffd12b144
commit
a61e460c2f
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,3 +2,5 @@
|
|||||||
static/bundle.js
|
static/bundle.js
|
||||||
static/react-widgets
|
static/react-widgets
|
||||||
node_modules
|
node_modules
|
||||||
|
cusip_list.csv
|
||||||
|
security_templates.go
|
||||||
|
34
accounts.go
34
accounts.go
@ -143,7 +143,11 @@ func GetTradingAccount(transaction *gorp.Transaction, userid int64, securityid i
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
security := GetSecurity(securityid)
|
security, err := GetSecurity(securityid, userid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
account.UserId = userid
|
account.UserId = userid
|
||||||
account.Name = security.Name
|
account.Name = security.Name
|
||||||
account.ParentAccountId = ta.AccountId
|
account.ParentAccountId = ta.AccountId
|
||||||
@ -176,7 +180,11 @@ func GetImbalanceAccount(transaction *gorp.Transaction, userid int64, securityid
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
security := GetSecurity(securityid)
|
security, err := GetSecurity(securityid, userid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
account.UserId = userid
|
account.UserId = userid
|
||||||
account.Name = security.Name
|
account.Name = security.Name
|
||||||
account.ParentAccountId = ia.AccountId
|
account.ParentAccountId = ia.AccountId
|
||||||
@ -346,7 +354,13 @@ func AccountHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
account.UserId = user.UserId
|
account.UserId = user.UserId
|
||||||
account.AccountVersion = 0
|
account.AccountVersion = 0
|
||||||
|
|
||||||
if GetSecurity(account.SecurityId) == nil {
|
security, err := GetSecurity(account.SecurityId, user.UserId)
|
||||||
|
if err != nil {
|
||||||
|
WriteError(w, 999 /*Internal Error*/)
|
||||||
|
log.Print(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if security == nil {
|
||||||
WriteError(w, 3 /*Invalid Request*/)
|
WriteError(w, 3 /*Invalid Request*/)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -432,7 +446,13 @@ func AccountHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
account.UserId = user.UserId
|
account.UserId = user.UserId
|
||||||
|
|
||||||
if GetSecurity(account.SecurityId) == nil {
|
security, err := GetSecurity(account.SecurityId, user.UserId)
|
||||||
|
if err != nil {
|
||||||
|
WriteError(w, 999 /*Internal Error*/)
|
||||||
|
log.Print(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if security == nil {
|
||||||
WriteError(w, 3 /*Invalid Request*/)
|
WriteError(w, 3 /*Invalid Request*/)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -451,12 +471,6 @@ func AccountHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if r.Method == "DELETE" {
|
} else if r.Method == "DELETE" {
|
||||||
accountid, err := GetURLID(r.URL.Path)
|
|
||||||
if err != nil {
|
|
||||||
WriteError(w, 3 /*Invalid Request*/)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
account, err := GetAccount(accountid, user.UserId)
|
account, err := GetAccount(accountid, user.UserId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
WriteError(w, 3 /*Invalid Request*/)
|
WriteError(w, 3 /*Invalid Request*/)
|
||||||
|
1
db.go
1
db.go
@ -19,6 +19,7 @@ func initDB() *gorp.DbMap {
|
|||||||
dbmap.AddTableWithName(User{}, "users").SetKeys(true, "UserId")
|
dbmap.AddTableWithName(User{}, "users").SetKeys(true, "UserId")
|
||||||
dbmap.AddTableWithName(Session{}, "sessions").SetKeys(true, "SessionId")
|
dbmap.AddTableWithName(Session{}, "sessions").SetKeys(true, "SessionId")
|
||||||
dbmap.AddTableWithName(Account{}, "accounts").SetKeys(true, "AccountId")
|
dbmap.AddTableWithName(Account{}, "accounts").SetKeys(true, "AccountId")
|
||||||
|
dbmap.AddTableWithName(Security{}, "securities").SetKeys(true, "SecurityId")
|
||||||
dbmap.AddTableWithName(Transaction{}, "transactions").SetKeys(true, "TransactionId")
|
dbmap.AddTableWithName(Transaction{}, "transactions").SetKeys(true, "TransactionId")
|
||||||
dbmap.AddTableWithName(Split{}, "splits").SetKeys(true, "SplitId")
|
dbmap.AddTableWithName(Split{}, "splits").SetKeys(true, "SplitId")
|
||||||
|
|
||||||
|
@ -121,7 +121,13 @@ func AccountImportHandler(w http.ResponseWriter, r *http.Request, user *User, ac
|
|||||||
split := new(Split)
|
split := new(Split)
|
||||||
r := new(big.Rat)
|
r := new(big.Rat)
|
||||||
r.Neg(&imbalance)
|
r.Neg(&imbalance)
|
||||||
security := GetSecurity(imbalanced_security)
|
security, err := GetSecurity(imbalanced_security, user.UserId)
|
||||||
|
if err != nil {
|
||||||
|
sqltransaction.Rollback()
|
||||||
|
WriteError(w, 999 /*Internal Error*/)
|
||||||
|
log.Print(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
split.Amount = r.FloatString(security.Precision)
|
split.Amount = r.FloatString(security.Precision)
|
||||||
split.SecurityId = -1
|
split.SecurityId = -1
|
||||||
split.AccountId = imbalanced_account.AccountId
|
split.AccountId = imbalanced_account.AccountId
|
||||||
|
41
libofx.go
41
libofx.go
@ -132,7 +132,13 @@ func OFXTransactionCallback(transaction_data C.struct_OfxTransactionData, data u
|
|||||||
split := new(Split)
|
split := new(Split)
|
||||||
r := new(big.Rat)
|
r := new(big.Rat)
|
||||||
r.SetFloat64(float64(transaction_data.amount))
|
r.SetFloat64(float64(transaction_data.amount))
|
||||||
security := GetSecurity(itl.Account.SecurityId)
|
security, err := GetSecurity(itl.Account.SecurityId, itl.Account.UserId)
|
||||||
|
if err != nil {
|
||||||
|
if iobj.Error == nil {
|
||||||
|
iobj.Error = err
|
||||||
|
}
|
||||||
|
return 1
|
||||||
|
}
|
||||||
split.Amount = r.FloatString(security.Precision)
|
split.Amount = r.FloatString(security.Precision)
|
||||||
if transaction_data.memo_valid != 0 {
|
if transaction_data.memo_valid != 0 {
|
||||||
split.Memo = C.GoString(&transaction_data.memo[0])
|
split.Memo = C.GoString(&transaction_data.memo[0])
|
||||||
@ -151,6 +157,7 @@ func OFXTransactionCallback(transaction_data C.struct_OfxTransactionData, data u
|
|||||||
}
|
}
|
||||||
|
|
||||||
var security *Security
|
var security *Security
|
||||||
|
var err error
|
||||||
split := new(Split)
|
split := new(Split)
|
||||||
units := new(big.Rat)
|
units := new(big.Rat)
|
||||||
|
|
||||||
@ -183,7 +190,13 @@ func OFXTransactionCallback(transaction_data C.struct_OfxTransactionData, data u
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
security = GetSecurity(itl.Account.SecurityId)
|
security, err = GetSecurity(itl.Account.SecurityId, itl.Account.UserId)
|
||||||
|
if err != nil {
|
||||||
|
if iobj.Error == nil {
|
||||||
|
iobj.Error = err
|
||||||
|
}
|
||||||
|
return 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Calculate units from other available fields if its not present
|
// Calculate units from other available fields if its not present
|
||||||
@ -207,7 +220,13 @@ func OFXTransactionCallback(transaction_data C.struct_OfxTransactionData, data u
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If 'units' wasn't present, assume we're using the account's security
|
// If 'units' wasn't present, assume we're using the account's security
|
||||||
security = GetSecurity(itl.Account.SecurityId)
|
security, err = GetSecurity(itl.Account.SecurityId, itl.Account.UserId)
|
||||||
|
if err != nil {
|
||||||
|
if iobj.Error == nil {
|
||||||
|
iobj.Error = err
|
||||||
|
}
|
||||||
|
return 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
split.Amount = units.FloatString(security.Precision)
|
split.Amount = units.FloatString(security.Precision)
|
||||||
@ -219,7 +238,13 @@ func OFXTransactionCallback(transaction_data C.struct_OfxTransactionData, data u
|
|||||||
split := new(Split)
|
split := new(Split)
|
||||||
r := new(big.Rat)
|
r := new(big.Rat)
|
||||||
r.SetFloat64(float64(-transaction_data.fees))
|
r.SetFloat64(float64(-transaction_data.fees))
|
||||||
security := GetSecurity(itl.Account.SecurityId)
|
security, err := GetSecurity(itl.Account.SecurityId, itl.Account.UserId)
|
||||||
|
if err != nil {
|
||||||
|
if iobj.Error == nil {
|
||||||
|
iobj.Error = err
|
||||||
|
}
|
||||||
|
return 1
|
||||||
|
}
|
||||||
split.Amount = r.FloatString(security.Precision)
|
split.Amount = r.FloatString(security.Precision)
|
||||||
split.Memo = "fees"
|
split.Memo = "fees"
|
||||||
split.SecurityId = itl.Account.SecurityId
|
split.SecurityId = itl.Account.SecurityId
|
||||||
@ -231,7 +256,13 @@ func OFXTransactionCallback(transaction_data C.struct_OfxTransactionData, data u
|
|||||||
split := new(Split)
|
split := new(Split)
|
||||||
r := new(big.Rat)
|
r := new(big.Rat)
|
||||||
r.SetFloat64(float64(-transaction_data.commission))
|
r.SetFloat64(float64(-transaction_data.commission))
|
||||||
security := GetSecurity(itl.Account.SecurityId)
|
security, err := GetSecurity(itl.Account.SecurityId, itl.Account.UserId)
|
||||||
|
if err != nil {
|
||||||
|
if iobj.Error == nil {
|
||||||
|
iobj.Error = err
|
||||||
|
}
|
||||||
|
return 1
|
||||||
|
}
|
||||||
split.Amount = r.FloatString(security.Precision)
|
split.Amount = r.FloatString(security.Precision)
|
||||||
split.Memo = "commission"
|
split.Memo = "commission"
|
||||||
split.SecurityId = itl.Account.SecurityId
|
split.SecurityId = itl.Account.SecurityId
|
||||||
|
1
main.go
1
main.go
@ -70,6 +70,7 @@ func main() {
|
|||||||
servemux.HandleFunc("/session/", SessionHandler)
|
servemux.HandleFunc("/session/", SessionHandler)
|
||||||
servemux.HandleFunc("/user/", UserHandler)
|
servemux.HandleFunc("/user/", UserHandler)
|
||||||
servemux.HandleFunc("/security/", SecurityHandler)
|
servemux.HandleFunc("/security/", SecurityHandler)
|
||||||
|
servemux.HandleFunc("/securitytemplate/", SecurityTemplateHandler)
|
||||||
servemux.HandleFunc("/account/", AccountHandler)
|
servemux.HandleFunc("/account/", AccountHandler)
|
||||||
servemux.HandleFunc("/transaction/", TransactionHandler)
|
servemux.HandleFunc("/transaction/", TransactionHandler)
|
||||||
servemux.HandleFunc("/import/gnucash", GnucashImportHandler)
|
servemux.HandleFunc("/import/gnucash", GnucashImportHandler)
|
||||||
|
55953
securities.go
55953
securities.go
File diff suppressed because it is too large
Load Diff
@ -294,6 +294,7 @@ func InsertTransactionTx(transaction *gorp.Transaction, t *Transaction, user *Us
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func InsertTransaction(t *Transaction, user *User) error {
|
func InsertTransaction(t *Transaction, user *User) error {
|
||||||
transaction, err := DB.Begin()
|
transaction, err := DB.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -692,7 +693,10 @@ func GetAccountTransactions(user *User, accountid int64, sort string, page uint6
|
|||||||
}
|
}
|
||||||
atl.TotalTransactions = count
|
atl.TotalTransactions = count
|
||||||
|
|
||||||
security := GetSecurity(atl.Account.SecurityId)
|
security, err := GetSecurity(atl.Account.SecurityId, user.UserId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if security == nil {
|
if security == nil {
|
||||||
return nil, errors.New("Security not found")
|
return nil, errors.New("Security not found")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user