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:
@@ -140,6 +140,12 @@ func (rs *Recordset) Create(vals Values) (*Recordset, error) {
|
||||
if !exists {
|
||||
continue
|
||||
}
|
||||
// Odoo sends false for empty fields; convert to nil for non-boolean types
|
||||
val = sanitizeFieldValue(f, val)
|
||||
// Skip nil values (let DB use column default)
|
||||
if val == nil {
|
||||
continue
|
||||
}
|
||||
columns = append(columns, fmt.Sprintf("%q", f.Column()))
|
||||
placeholders = append(placeholders, fmt.Sprintf("$%d", idx))
|
||||
args = append(args, val)
|
||||
@@ -239,6 +245,9 @@ func (rs *Recordset) Write(vals Values) error {
|
||||
continue
|
||||
}
|
||||
|
||||
// Odoo sends false for empty fields; convert to nil for non-boolean types
|
||||
val = sanitizeFieldValue(f, val)
|
||||
|
||||
setClauses = append(setClauses, fmt.Sprintf("%q = $%d", f.Column(), idx))
|
||||
args = append(args, val)
|
||||
idx++
|
||||
@@ -585,7 +594,7 @@ func (rs *Recordset) Search(domain Domain, opts ...SearchOpts) (*Recordset, erro
|
||||
domain = ApplyRecordRules(rs.env, m, domain)
|
||||
|
||||
// Compile domain to SQL
|
||||
compiler := &DomainCompiler{model: m}
|
||||
compiler := &DomainCompiler{model: m, env: rs.env}
|
||||
where, params, err := compiler.Compile(domain)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("orm: search %s: %w", m.name, err)
|
||||
@@ -638,7 +647,7 @@ func (rs *Recordset) Search(domain Domain, opts ...SearchOpts) (*Recordset, erro
|
||||
func (rs *Recordset) SearchCount(domain Domain) (int64, error) {
|
||||
m := rs.model
|
||||
|
||||
compiler := &DomainCompiler{model: m}
|
||||
compiler := &DomainCompiler{model: m, env: rs.env}
|
||||
where, params, err := compiler.Compile(domain)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("orm: search_count %s: %w", m.name, err)
|
||||
@@ -859,3 +868,31 @@ func processRelationalCommands(env *Environment, m *Model, parentID int64, vals
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// sanitizeFieldValue converts Odoo's false/empty values to Go-native types
|
||||
// suitable for PostgreSQL. Odoo sends false for empty string/numeric/relational
|
||||
// fields; PostgreSQL rejects false for varchar/int columns.
|
||||
// Mirrors: odoo/orm/fields.py convert_to_column()
|
||||
func sanitizeFieldValue(f *Field, val interface{}) interface{} {
|
||||
if val == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Handle the Odoo false → nil conversion for non-boolean fields
|
||||
if b, ok := val.(bool); ok && !b {
|
||||
if f.Type == TypeBoolean {
|
||||
return false // Keep false for boolean fields
|
||||
}
|
||||
return nil // Convert false → NULL for all other types
|
||||
}
|
||||
|
||||
// Handle float→int conversion for integer/M2O fields
|
||||
switch f.Type {
|
||||
case TypeInteger, TypeMany2one:
|
||||
if fv, ok := val.(float64); ok {
|
||||
return int64(fv)
|
||||
}
|
||||
}
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user