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:
@@ -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.",
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user