Bring odoo-go to ~70%: read_group, record rules, admin, sessions

Phase 1: read_group/web_read_group with SQL GROUP BY, aggregates
  (sum/avg/min/max/count/array_agg/sum_currency), date granularity,
  M2O groupby resolution to [id, display_name].

Phase 2: Record rules with domain_force parsing (Python literal parser),
  global AND + group OR merging. Domain operators: child_of, parent_of,
  any, not any compiled to SQL hierarchy/EXISTS queries.

Phase 3: Button dispatch via /web/dataset/call_button, method return
  values interpreted as actions. Payment register wizard
  (account.payment.register) for sale→invoice→pay flow.

Phase 4: ir.filters, ir.default, product fields expanded, SO line
  product_id onchange, ir_model+ir_model_fields DB seeding.

Phase 5: CSV export (/web/export/csv), attachment upload/download
  via ir.attachment, fields_get with aggregator hints.

Admin/System: Session persistence (PostgreSQL-backed), ir.config_parameter
  with get_param/set_param, ir.cron, ir.logging, res.lang, res.config.settings
  with company-related fields, Settings form view. Technical menu with
  Views/Actions/Parameters/Security/Logging sub-menus. User change_password,
  preferences. Password never exposed in UI/API.

Bugfixes: false→nil for varchar/int fields, int32 in toInt64, call_button
  route with trailing slash, create_invoices returns action, search view
  always included, get_formview_action, name_create, ir.http stub.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Marc
2026-04-02 19:26:08 +02:00
parent 06e49c878a
commit b57176de2f
29 changed files with 3243 additions and 111 deletions

View File

@@ -1,6 +1,11 @@
package models
import "odoo-go/pkg/orm"
import (
"fmt"
"odoo-go/pkg/orm"
"odoo-go/pkg/tools"
)
// initResUsers registers the res.users model.
// Mirrors: odoo/addons/base/models/res_users.py class Users
@@ -78,6 +83,55 @@ func initResUsers() {
"context": map[string]interface{}{},
}, nil
})
// change_password: verifies old password and sets a new one.
// Mirrors: odoo/addons/base/models/res_users.py Users.change_password()
m.RegisterMethod("change_password", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
if len(args) < 2 {
return false, fmt.Errorf("change_password requires old_password and new_password")
}
oldPw, _ := args[0].(string)
newPw, _ := args[1].(string)
env := rs.Env()
uid := env.UID()
// Verify old password
var hashedPw string
err := env.Tx().QueryRow(env.Ctx(),
`SELECT password FROM res_users WHERE id = $1`, uid).Scan(&hashedPw)
if err != nil {
return false, fmt.Errorf("user not found")
}
if !tools.CheckPassword(hashedPw, oldPw) {
return false, fmt.Errorf("incorrect old password")
}
// Hash and set new password
newHash, err := tools.HashPassword(newPw)
if err != nil {
return false, err
}
_, err = env.Tx().Exec(env.Ctx(),
`UPDATE res_users SET password = $1 WHERE id = $2`, newHash, uid)
if err != nil {
return false, err
}
return true, nil
})
// preference_save: called when saving user preferences.
// Mirrors: odoo/addons/base/models/res_users.py Users.preference_save()
m.RegisterMethod("preference_save", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
// Preferences are saved via normal write; just return true.
return true, nil
})
// preference_change_password: alias for change_password from preferences dialog.
// Mirrors: odoo/addons/base/models/res_users.py Users.preference_change_password()
m.RegisterMethod("preference_change_password", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
return rs.Env().Model("res.users").Browse(rs.Env().UID()).Read([]string{"id"})
})
}
// initResGroups registers the res.groups model.