Files
goodie/pkg/server/fields_get.go
Marc b57176de2f 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>
2026-04-02 19:26:08 +02:00

96 lines
2.4 KiB
Go

package server
import "odoo-go/pkg/orm"
// fieldsGetForModel returns field metadata for a model.
// Mirrors: odoo/orm/models.py BaseModel.fields_get()
func fieldsGetForModel(modelName string) map[string]interface{} {
m := orm.Registry.Get(modelName)
if m == nil {
return map[string]interface{}{}
}
result := make(map[string]interface{})
for name, f := range m.Fields() {
// Never expose password fields in metadata
if name == "password" || name == "password_crypt" {
continue
}
fType := f.Type.String()
fieldInfo := map[string]interface{}{
"name": name,
"type": fType,
"string": f.String,
"help": f.Help,
"readonly": f.Readonly,
"required": f.Required,
"searchable": f.IsStored(),
"sortable": f.IsStored(),
"store": f.IsStored(),
"manual": false,
"depends": f.Depends,
"groupable": f.IsStored() && f.Type != orm.TypeText && f.Type != orm.TypeHTML,
"exportable": true,
"change_default": false,
"company_dependent": false,
}
// Relational fields
if f.Comodel != "" {
fieldInfo["relation"] = f.Comodel
}
if f.InverseField != "" {
fieldInfo["relation_field"] = f.InverseField
}
// Selection
if f.Type == orm.TypeSelection && len(f.Selection) > 0 {
sel := make([][]string, len(f.Selection))
for i, item := range f.Selection {
sel[i] = []string{item.Value, item.Label}
}
fieldInfo["selection"] = sel
}
// Monetary fields need currency_field
if f.Type == orm.TypeMonetary {
cf := f.CurrencyField
if cf == "" {
cf = "currency_id"
}
fieldInfo["currency_field"] = cf
}
// Computed fields
if f.Compute != "" {
fieldInfo["compute"] = f.Compute
}
if f.Related != "" {
fieldInfo["related"] = f.Related
}
// Aggregator hint for read_group
// Mirrors: odoo/orm/fields.py Field.group_operator
switch f.Type {
case orm.TypeInteger, orm.TypeFloat, orm.TypeMonetary:
fieldInfo["aggregator"] = "sum"
fieldInfo["group_operator"] = "sum"
case orm.TypeBoolean:
fieldInfo["aggregator"] = "bool_or"
fieldInfo["group_operator"] = "bool_or"
default:
fieldInfo["aggregator"] = nil
fieldInfo["group_operator"] = nil
}
// Default domain & context
fieldInfo["domain"] = []interface{}{}
fieldInfo["context"] = map[string]interface{}{}
result[name] = fieldInfo
}
return result
}