Backend improvements: views, fields_get, session, RPC stubs
- Improved auto-generated list/form/search views with priority fields, two-column form layout, statusbar widget, notebook for O2M fields - Enhanced fields_get with currency_field, compute, related metadata - Fixed session handling: handleSessionInfo/handleSessionCheck use real session from cookie instead of hardcoded values - Added read_progress_bar and activity_format RPC stubs - Improved bootstrap translations with lang_parameters - Added "contacts" to session modules list Server starts successfully: 14 modules, 93 models, 378 XML templates, 503 JS modules transpiled — all from local frontend/ directory. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -46,6 +46,7 @@ type Model struct {
|
||||
|
||||
// Hooks
|
||||
BeforeCreate func(env *Environment, vals Values) error // Called before INSERT
|
||||
DefaultGet func(env *Environment, fields []string) Values // Dynamic defaults (e.g., from DB)
|
||||
Constraints []ConstraintFunc // Validation constraints
|
||||
Methods map[string]MethodFunc // Named business methods
|
||||
|
||||
@@ -53,6 +54,11 @@ type Model struct {
|
||||
computes map[string]ComputeFunc // field_name → compute function
|
||||
dependencyMap map[string][]string // trigger_field → []computed_field_names
|
||||
|
||||
// Onchange handlers
|
||||
// Maps field_name → handler that receives current vals and returns computed updates.
|
||||
// Mirrors: @api.onchange in Odoo.
|
||||
OnchangeHandlers map[string]func(env *Environment, vals Values) Values
|
||||
|
||||
// Resolved
|
||||
parents []*Model // Resolved parent models from _inherit
|
||||
allFields map[string]*Field // Including fields from parents
|
||||
@@ -227,6 +233,17 @@ func (m *Model) RegisterMethod(name string, fn MethodFunc) *Model {
|
||||
return m
|
||||
}
|
||||
|
||||
// RegisterOnchange registers an onchange handler for a field.
|
||||
// When the field changes on the client, the handler is called with the current
|
||||
// record values and returns computed field updates.
|
||||
// Mirrors: @api.onchange('field_name') in Odoo.
|
||||
func (m *Model) RegisterOnchange(fieldName string, handler func(env *Environment, vals Values) Values) {
|
||||
if m.OnchangeHandlers == nil {
|
||||
m.OnchangeHandlers = make(map[string]func(env *Environment, vals Values) Values)
|
||||
}
|
||||
m.OnchangeHandlers[fieldName] = handler
|
||||
}
|
||||
|
||||
// Extend extends this model with additional fields (like _inherit in Odoo).
|
||||
// Mirrors: class MyModelExt(models.Model): _inherit = 'res.partner'
|
||||
func (m *Model) Extend(fields ...*Field) *Model {
|
||||
|
||||
Reference in New Issue
Block a user