feat: Portal, Email Inbound, Discuss + module improvements

- Portal: /my/* routes, signup, password reset, portal user support
- Email Inbound: IMAP polling (go-imap/v2), thread matching
- Discuss: mail.channel, long-polling bus, DM, unread count
- Cron: ir.cron runner (goroutine scheduler)
- Bank Import, CSV/Excel Import
- Automation (ir.actions.server)
- Fetchmail service
- HR Payroll model
- Various fixes across account, sale, stock, purchase, crm, hr, project

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marc
2026-04-12 18:41:57 +02:00
parent 2c7c1e6c88
commit 66383adf06
87 changed files with 14696 additions and 654 deletions

View File

@@ -1,6 +1,10 @@
package models
import "odoo-go/pkg/orm"
import (
"fmt"
"odoo-go/pkg/orm"
)
// initIrCron registers ir.cron — Scheduled actions.
// Mirrors: odoo/addons/base/models/ir_cron.py class IrCron
@@ -30,5 +34,86 @@ func initIrCron() {
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"}),
// Execution target (simplified: direct model+method instead of ir.actions.server)
orm.Char("model_name", orm.FieldOpts{String: "Model Name"}),
orm.Char("method_name", orm.FieldOpts{String: "Method Name"}),
// Failure tracking
orm.Integer("failure_count", orm.FieldOpts{String: "Failure Count", Default: 0}),
orm.Datetime("first_failure_date", orm.FieldOpts{String: "First Failure Date"}),
)
// Constraint: validate model_name and method_name against the registry.
// Prevents setting arbitrary/invalid model+method combos on cron jobs.
m.AddConstraint(func(rs *orm.Recordset) error {
records, err := rs.Read([]string{"model_name", "method_name"})
if err != nil || len(records) == 0 {
return nil
}
rec := records[0]
modelName, _ := rec["model_name"].(string)
methodName, _ := rec["method_name"].(string)
if modelName == "" && methodName == "" {
return nil // both empty is OK (legacy code-based crons)
}
if modelName != "" {
model := orm.Registry.Get(modelName)
if model == nil {
return fmt.Errorf("ir.cron: model %q not found in registry", modelName)
}
if methodName != "" && model.Methods != nil {
if _, ok := model.Methods[methodName]; !ok {
return fmt.Errorf("ir.cron: method %q not found on model %q", methodName, modelName)
}
}
}
return nil
})
// method_direct_trigger — manually trigger a cron job.
// Mirrors: odoo/addons/base/models/ir_cron.py method_direct_trigger
m.RegisterMethod("method_direct_trigger", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
// Admin-only: only uid=1 or superuser may trigger cron jobs directly
env := rs.Env()
if env.UID() != 1 && !env.IsSuperuser() {
return nil, fmt.Errorf("ir.cron: method_direct_trigger requires admin privileges")
}
records, err := rs.Read([]string{"model_name", "method_name"})
if err != nil {
return nil, fmt.Errorf("ir.cron: method_direct_trigger read failed: %w", err)
}
if len(records) == 0 {
return nil, fmt.Errorf("ir.cron: method_direct_trigger: no record found")
}
rec := records[0]
modelName, _ := rec["model_name"].(string)
methodName, _ := rec["method_name"].(string)
if modelName == "" || methodName == "" {
return nil, fmt.Errorf("ir.cron: model_name or method_name not set")
}
// Validate model_name against registry (prevents calling arbitrary models)
model := orm.Registry.Get(modelName)
if model == nil {
return nil, fmt.Errorf("ir.cron: model %q not found in registry", modelName)
}
if model.Methods == nil {
return nil, fmt.Errorf("ir.cron: model %q has no methods", modelName)
}
method, ok := model.Methods[methodName]
if !ok {
return nil, fmt.Errorf("ir.cron: method %q not found on model %q", methodName, modelName)
}
result, err := method(env.Model(modelName), args...)
if err != nil {
return nil, fmt.Errorf("ir.cron: %s.%s failed: %w", modelName, methodName, err)
}
return result, nil
})
}