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

@@ -13,4 +13,11 @@ func Init() {
initIrModelAccess()
initIrRule()
initIrModelData()
initIrFilter()
initIrDefault()
initIrConfigParameter() // ir.config_parameter (System Parameters)
initIrLogging() // ir.logging (Server log entries)
initIrCron() // ir.cron (Scheduled Actions)
initResLang() // res.lang (Languages)
initResConfigSettings() // res.config.settings (TransientModel)
}

View File

@@ -0,0 +1,60 @@
package models
import "odoo-go/pkg/orm"
// initIrConfigParameter registers ir.config_parameter — System parameters.
// Mirrors: odoo/addons/base/models/ir_config_parameter.py class IrConfigParameter
//
// Key/value store for system-wide configuration.
// Examples: web.base.url, database.uuid, mail.catchall.domain
func initIrConfigParameter() {
m := orm.NewModel("ir.config_parameter", orm.ModelOpts{
Description: "System Parameter",
Order: "key",
RecName: "key",
})
m.AddFields(
orm.Char("key", orm.FieldOpts{String: "Key", Required: true, Index: true}),
orm.Text("value", orm.FieldOpts{String: "Value", Required: true}),
)
// get_param: returns the value for a key, or default.
// Mirrors: odoo/addons/base/models/ir_config_parameter.py IrConfigParameter.get_param()
m.RegisterMethod("get_param", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
if len(args) == 0 {
return "", nil
}
key, _ := args[0].(string)
defaultVal := ""
if len(args) > 1 {
defaultVal, _ = args[1].(string)
}
env := rs.Env()
var value string
err := env.Tx().QueryRow(env.Ctx(),
`SELECT value FROM ir_config_parameter WHERE key = $1`, key).Scan(&value)
if err != nil {
return defaultVal, nil
}
return value, nil
})
// set_param: sets the value for a key (upsert).
// Mirrors: odoo/addons/base/models/ir_config_parameter.py IrConfigParameter.set_param()
m.RegisterMethod("set_param", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
if len(args) < 2 {
return false, nil
}
key, _ := args[0].(string)
value, _ := args[1].(string)
env := rs.Env()
_, err := env.Tx().Exec(env.Ctx(),
`INSERT INTO ir_config_parameter (key, value) VALUES ($1, $2)
ON CONFLICT (key) DO UPDATE SET value = $2`, key, value)
if err != nil {
return false, err
}
return true, nil
})
}

View File

@@ -0,0 +1,34 @@
package models
import "odoo-go/pkg/orm"
// initIrCron registers ir.cron — Scheduled actions.
// Mirrors: odoo/addons/base/models/ir_cron.py class IrCron
//
// Defines recurring tasks executed by the scheduler.
func initIrCron() {
m := orm.NewModel("ir.cron", orm.ModelOpts{
Description: "Scheduled Actions",
Order: "name",
})
m.AddFields(
orm.Char("name", orm.FieldOpts{String: "Name", Required: true}),
orm.Boolean("active", orm.FieldOpts{String: "Active", Default: true}),
orm.Many2one("user_id", "res.users", orm.FieldOpts{String: "User", Required: true}),
orm.Integer("interval_number", orm.FieldOpts{String: "Interval Number", Default: 1}),
orm.Selection("interval_type", []orm.SelectionItem{
{Value: "minutes", Label: "Minutes"},
{Value: "hours", Label: "Hours"},
{Value: "days", Label: "Days"},
{Value: "weeks", Label: "Weeks"},
{Value: "months", Label: "Months"},
}, orm.FieldOpts{String: "Interval Type", Default: "months"}),
orm.Integer("numbercall", orm.FieldOpts{String: "Number of Calls", Default: -1}),
orm.Datetime("nextcall", orm.FieldOpts{String: "Next Execution Date", Required: true}),
orm.Datetime("lastcall", orm.FieldOpts{String: "Last Execution Date"}),
orm.Integer("priority", orm.FieldOpts{String: "Priority", Default: 5}),
orm.Char("code", orm.FieldOpts{String: "Python Code"}),
orm.Many2one("model_id", "ir.model", orm.FieldOpts{String: "Model"}),
)
}

View File

@@ -0,0 +1,35 @@
package models
import "odoo-go/pkg/orm"
// initIrLogging registers ir.logging — Server-side log entries.
// Mirrors: odoo/addons/base/models/ir_logging.py class IrLogging
//
// Stores structured log entries written by the server,
// accessible via Settings > Technical > Logging.
func initIrLogging() {
m := orm.NewModel("ir.logging", orm.ModelOpts{
Description: "Logging",
Order: "id desc",
})
m.AddFields(
orm.Char("name", orm.FieldOpts{String: "Name", Required: true}),
orm.Selection("type", []orm.SelectionItem{
{Value: "client", Label: "Client"},
{Value: "server", Label: "Server"},
}, orm.FieldOpts{String: "Type", Required: true}),
orm.Char("dbname", orm.FieldOpts{String: "Database Name"}),
orm.Selection("level", []orm.SelectionItem{
{Value: "DEBUG", Label: "Debug"},
{Value: "INFO", Label: "Info"},
{Value: "WARNING", Label: "Warning"},
{Value: "ERROR", Label: "Error"},
{Value: "CRITICAL", Label: "Critical"},
}, orm.FieldOpts{String: "Level"}),
orm.Text("message", orm.FieldOpts{String: "Message", Required: true}),
orm.Char("path", orm.FieldOpts{String: "Path"}),
orm.Char("func", orm.FieldOpts{String: "Function"}),
orm.Char("line", orm.FieldOpts{String: "Line"}),
)
}

View File

@@ -1,6 +1,10 @@
package models
import "odoo-go/pkg/orm"
import (
"fmt"
"odoo-go/pkg/orm"
)
// initIrModel registers ir.model and ir.model.fields — Odoo's model metadata.
// Mirrors: odoo/addons/base/models/ir_model.py
@@ -173,3 +177,139 @@ func initIrModelData() {
orm.Boolean("noupdate", orm.FieldOpts{String: "Non Updatable", Default: false}),
)
}
// initIrFilter registers ir.filters — Saved search filters (Favorites).
// Mirrors: odoo/addons/base/models/ir_filters.py class IrFilters
//
// Filters are saved by the web client when a user bookmarks a search.
// user_id = NULL means the filter is shared with everyone.
func initIrFilter() {
m := orm.NewModel("ir.filters", orm.ModelOpts{
Description: "Filters",
Order: "model_id, name, id desc",
RecName: "name",
})
m.AddFields(
orm.Char("name", orm.FieldOpts{String: "Filter Name", Required: true, Translate: true}),
orm.Many2one("user_id", "res.users", orm.FieldOpts{
String: "User",
OnDelete: orm.OnDeleteCascade,
Help: "The user this filter is private to. When left empty the filter is shared.",
}),
orm.Text("domain", orm.FieldOpts{String: "Domain", Required: true, Default: "[]"}),
orm.Text("context", orm.FieldOpts{String: "Context", Required: true, Default: "{}"}),
orm.Text("sort", orm.FieldOpts{String: "Sort", Required: true, Default: "[]"}),
orm.Char("model_id", orm.FieldOpts{
String: "Model", Required: true,
Help: "Model name of the filtered view, e.g. 'res.partner'.",
}),
orm.Boolean("is_default", orm.FieldOpts{String: "Default Filter"}),
orm.Many2one("action_id", "ir.act.window", orm.FieldOpts{
String: "Action",
OnDelete: orm.OnDeleteCascade,
Help: "The menu action this filter applies to.",
}),
orm.Boolean("active", orm.FieldOpts{String: "Active", Default: true}),
)
// create_or_replace: Creates or updates a filter by (name, model_id, user_id, action_id).
// Mirrors: odoo/addons/base/models/ir_filters.py IrFilters.create_or_replace()
// Called by the web client when saving a favorite.
m.RegisterMethod("create_or_replace", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
if len(args) == 0 {
return nil, fmt.Errorf("ir.filters: create_or_replace requires a filter dict")
}
vals, ok := args[0].(orm.Values)
if !ok {
return nil, fmt.Errorf("ir.filters: create_or_replace expects Values argument")
}
env := rs.Env()
name, _ := vals["name"].(string)
modelID, _ := vals["model_id"].(string)
// Build lookup query
query := `SELECT id FROM ir_filters WHERE name = $1 AND model_id = $2`
qArgs := []interface{}{name, modelID}
idx := 3
// user_id
if uid, ok := vals["user_id"]; ok && uid != nil {
query += fmt.Sprintf(` AND user_id = $%d`, idx)
qArgs = append(qArgs, uid)
idx++
} else {
query += ` AND user_id IS NULL`
}
// action_id
if aid, ok := vals["action_id"]; ok && aid != nil {
query += fmt.Sprintf(` AND action_id = $%d`, idx)
qArgs = append(qArgs, aid)
} else {
query += ` AND action_id IS NULL`
}
query += ` LIMIT 1`
var existingID int64
err := env.Tx().QueryRow(env.Ctx(), query, qArgs...).Scan(&existingID)
if err == nil && existingID > 0 {
// Update existing
existing := rs.Browse(existingID)
if err := existing.Write(vals); err != nil {
return nil, err
}
return existingID, nil
}
// Create new
created, err := env.Model("ir.filters").Create(vals)
if err != nil {
return nil, err
}
return created.ID(), nil
})
}
// initIrDefault registers ir.default — User-defined field defaults.
// Mirrors: odoo/addons/base/models/ir_default.py class IrDefault
//
// Stores default values for specific fields, optionally scoped to a user or company.
// Example: default value for sale.order.payment_term_id for company 1.
func initIrDefault() {
m := orm.NewModel("ir.default", orm.ModelOpts{
Description: "Default Values",
Order: "id",
})
m.AddFields(
// In Python Odoo this is Many2one to ir.model.fields.
// We use Char for now since ir.model.fields may not be fully populated.
orm.Char("field_id", orm.FieldOpts{
String: "Field",
Required: true,
Index: true,
Help: "Reference to the field, format: 'model_name.field_name'.",
}),
orm.Text("json_value", orm.FieldOpts{
String: "Default Value (JSON)",
Help: "JSON-encoded default value for the field.",
}),
orm.Many2one("user_id", "res.users", orm.FieldOpts{
String: "User",
OnDelete: orm.OnDeleteCascade,
Help: "If set, this default only applies to this user.",
}),
orm.Many2one("company_id", "res.company", orm.FieldOpts{
String: "Company",
OnDelete: orm.OnDeleteCascade,
Help: "If set, this default only applies in this company.",
}),
orm.Char("condition", orm.FieldOpts{
String: "Condition",
Help: "Optional condition for applying this default.",
}),
)
}

View File

@@ -0,0 +1,76 @@
package models
import "odoo-go/pkg/orm"
// initResConfigSettings registers the res.config.settings transient model.
// Mirrors: odoo/addons/base/models/res_config.py class ResConfigSettings(TransientModel)
//
// This wizard provides the Settings form. Each "save" creates a new transient
// record, applies the values, then the record is eventually cleaned up.
func initResConfigSettings() {
m := orm.NewModel("res.config.settings", orm.ModelOpts{
Description: "Config Settings",
Type: orm.ModelTransient,
})
// -- General settings --
m.AddFields(
orm.Many2one("company_id", "res.company", orm.FieldOpts{
String: "Company", Index: true,
}),
orm.Boolean("user_default_rights", orm.FieldOpts{String: "Default Access Rights"}),
orm.Boolean("external_email_server_default", orm.FieldOpts{String: "External Email Servers"}),
orm.Boolean("module_base_import", orm.FieldOpts{String: "Allow Import"}),
orm.Boolean("module_google_calendar", orm.FieldOpts{String: "Google Calendar"}),
orm.Boolean("group_multi_company", orm.FieldOpts{String: "Multi Companies"}),
orm.Boolean("show_effect", orm.FieldOpts{String: "Show Effect", Default: true}),
)
// -- Company info fields (mirrors res.company, for display in settings) --
// Mirrors: odoo/addons/base/models/res_config_settings.py company-related fields
m.AddFields(
orm.Char("company_name", orm.FieldOpts{String: "Company Name", Related: "company_id.name"}),
orm.Many2one("company_currency_id", "res.currency", orm.FieldOpts{
String: "Currency", Related: "company_id.currency_id",
}),
orm.Many2one("company_country_id", "res.country", orm.FieldOpts{
String: "Country", Related: "company_id.country_id",
}),
orm.Char("company_street", orm.FieldOpts{String: "Street", Related: "company_id.street"}),
orm.Char("company_street2", orm.FieldOpts{String: "Street2", Related: "company_id.street2"}),
orm.Char("company_zip", orm.FieldOpts{String: "Zip", Related: "company_id.zip"}),
orm.Char("company_city", orm.FieldOpts{String: "City", Related: "company_id.city"}),
orm.Char("company_phone", orm.FieldOpts{String: "Phone", Related: "company_id.phone"}),
orm.Char("company_email", orm.FieldOpts{String: "Email", Related: "company_id.email"}),
orm.Char("company_website", orm.FieldOpts{String: "Website", Related: "company_id.website"}),
orm.Char("company_vat", orm.FieldOpts{String: "Tax ID", Related: "company_id.vat"}),
orm.Char("company_registry", orm.FieldOpts{String: "Company Registry", Related: "company_id.company_registry"}),
)
// -- Accounting settings --
m.AddFields(
orm.Char("chart_template", orm.FieldOpts{String: "Chart of Accounts"}),
orm.Selection("tax_calculation_rounding_method", []orm.SelectionItem{
{Value: "round_per_line", Label: "Round per Line"},
{Value: "round_globally", Label: "Round Globally"},
}, orm.FieldOpts{String: "Tax Calculation Rounding Method", Default: "round_per_line"}),
)
// execute: called by the Settings form to apply configuration.
// Mirrors: odoo/addons/base/models/res_config.py ResConfigSettings.execute()
m.RegisterMethod("execute", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
// In Python Odoo this writes Related fields back to res.company.
// For now we just return true; the Related fields are read-only display.
return true, nil
})
// DefaultGet: pre-fill from current company.
// Mirrors: odoo/addons/base/models/res_config.py ResConfigSettings.default_get()
m.DefaultGet = func(env *orm.Environment, fields []string) orm.Values {
vals := orm.Values{
"company_id": env.CompanyID(),
"show_effect": true,
}
return vals
}
}

View File

@@ -0,0 +1,27 @@
package models
import "odoo-go/pkg/orm"
// initResLang registers res.lang — Languages.
// Mirrors: odoo/addons/base/models/res_lang.py
func initResLang() {
m := orm.NewModel("res.lang", orm.ModelOpts{
Description: "Languages",
RecName: "name",
})
m.AddFields(
orm.Char("name", orm.FieldOpts{String: "Name", Required: true}),
orm.Char("code", orm.FieldOpts{String: "Locale Code", Required: true}),
orm.Char("iso_code", orm.FieldOpts{String: "ISO Code"}),
orm.Char("url_code", orm.FieldOpts{String: "URL Code"}),
orm.Boolean("active", orm.FieldOpts{String: "Active", Default: true}),
orm.Char("direction", orm.FieldOpts{String: "Direction", Default: "ltr"}),
orm.Char("date_format", orm.FieldOpts{String: "Date Format", Default: "%m/%d/%Y"}),
orm.Char("time_format", orm.FieldOpts{String: "Time Format", Default: "%H:%M:%S"}),
orm.Char("week_start", orm.FieldOpts{String: "First Day of Week", Default: "7"}),
orm.Char("decimal_point", orm.FieldOpts{String: "Decimal Separator", Default: "."}),
orm.Char("thousands_sep", orm.FieldOpts{String: "Thousands Separator", Default: ","}),
orm.Char("grouping", orm.FieldOpts{String: "Separator Format", Default: "[]"}),
)
}

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.