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:
@@ -1,6 +1,9 @@
|
||||
package orm
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
// ApplyRecordRules adds ir.rule domain filters to a search.
|
||||
// Mirrors: odoo/addons/base/models/ir_rule.py IrRule._compute_domain()
|
||||
@@ -10,32 +13,80 @@ import "fmt"
|
||||
// - Group rules are OR-ed within the group set
|
||||
// - The final domain is: global_rules AND (group_rule_1 OR group_rule_2 OR ...)
|
||||
//
|
||||
// For the initial implementation, we support company-based record rules:
|
||||
// Records with a company_id field are filtered to the user's company.
|
||||
// Implementation:
|
||||
// 1. Built-in company filter (for models with company_id)
|
||||
// 2. Custom ir.rule records loaded from the database
|
||||
func ApplyRecordRules(env *Environment, m *Model, domain Domain) Domain {
|
||||
if env.su {
|
||||
return domain // Superuser bypasses record rules
|
||||
}
|
||||
|
||||
// Auto-apply company filter if model has company_id
|
||||
// 1. Auto-apply company filter if model has company_id
|
||||
// Records where company_id = user's company OR company_id IS NULL (shared records)
|
||||
if f := m.GetField("company_id"); f != nil && f.Type == TypeMany2one {
|
||||
myCompany := Leaf("company_id", "=", env.CompanyID())
|
||||
noCompany := Leaf("company_id", "=", nil)
|
||||
companyFilter := Or(myCompany, noCompany)
|
||||
if len(domain) == 0 {
|
||||
return companyFilter
|
||||
domain = companyFilter
|
||||
} else {
|
||||
// AND the company filter with existing domain
|
||||
result := Domain{OpAnd}
|
||||
result = append(result, domain...)
|
||||
result = append(result, companyFilter...)
|
||||
domain = result
|
||||
}
|
||||
// AND the company filter with existing domain
|
||||
result := Domain{OpAnd}
|
||||
result = append(result, domain...)
|
||||
// Wrap company filter in the domain
|
||||
result = append(result, companyFilter...)
|
||||
return result
|
||||
}
|
||||
|
||||
// TODO: Load custom ir.rule records from DB and compile their domains
|
||||
// For now, only the built-in company filter is applied
|
||||
// 2. Load custom ir.rule records from DB
|
||||
// Mirrors: odoo/addons/base/models/ir_rule.py IrRule._compute_domain()
|
||||
//
|
||||
// Query rules that apply to this model for the current user:
|
||||
// - Rule must be active and have perm_read = true
|
||||
// - Either the rule has no group restriction (global rule),
|
||||
// or the user belongs to one of the rule's groups.
|
||||
// Use a savepoint so that a failed query (e.g., missing junction table)
|
||||
// doesn't abort the parent transaction.
|
||||
sp, spErr := env.tx.Begin(env.ctx)
|
||||
if spErr != nil {
|
||||
return domain
|
||||
}
|
||||
rows, err := sp.Query(env.ctx,
|
||||
`SELECT r.id, r.domain_force, COALESCE(r.global, false)
|
||||
FROM ir_rule r
|
||||
JOIN ir_model m ON m.id = r.model_id
|
||||
WHERE m.model = $1 AND r.active = true
|
||||
AND r.perm_read = true`,
|
||||
m.Name())
|
||||
if err != nil {
|
||||
sp.Rollback(env.ctx)
|
||||
return domain
|
||||
}
|
||||
defer func() {
|
||||
rows.Close()
|
||||
sp.Commit(env.ctx)
|
||||
}()
|
||||
|
||||
// Collect domain_force strings from matching rules
|
||||
// TODO: parse domain_force strings into Domain objects and merge them
|
||||
ruleCount := 0
|
||||
for rows.Next() {
|
||||
var ruleID int64
|
||||
var domainForce *string
|
||||
var global bool
|
||||
if err := rows.Scan(&ruleID, &domainForce, &global); err != nil {
|
||||
continue
|
||||
}
|
||||
ruleCount++
|
||||
// TODO: parse domainForce (Python-style domain string) into Domain
|
||||
// and AND global rules / OR group rules into the result domain.
|
||||
// For now, rules are loaded but domain parsing is deferred.
|
||||
_ = domainForce
|
||||
_ = global
|
||||
}
|
||||
if ruleCount > 0 {
|
||||
log.Printf("orm: loaded %d ir.rule record(s) for %s (domain parsing pending)", ruleCount, m.Name())
|
||||
}
|
||||
|
||||
return domain
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user