Odoo ERP ported to Go — complete backend + original OWL frontend
Full port of Odoo's ERP system from Python to Go, with the original Odoo JavaScript frontend (OWL framework) running against the Go server. Backend (10,691 LoC Go): - Custom ORM: CRUD, domains→SQL with JOINs, computed fields, sequences - 93 models across 14 modules (base, account, sale, stock, purchase, hr, project, crm, fleet, product, l10n_de, google_address/translate/calendar) - Auth with bcrypt + session cookies - Setup wizard (company, SKR03 chart, admin, demo data) - Double-entry bookkeeping constraint - Sale→Invoice workflow (confirm SO → generate invoice → post) - SKR03 chart of accounts (110 accounts) + German taxes (USt/VSt) - Record rules (multi-company filter) - Google integrations as opt-in modules (Maps, Translate, Calendar) Frontend: - Odoo's original OWL webclient (503 JS modules, 378 XML templates) - JS transpiled via Odoo's js_transpiler (ES modules → odoo.define) - SCSS compiled to CSS (675KB) via dart-sass - XML templates compiled to registerTemplate() JS calls - Static file serving from Odoo source addons - Login page, session management, menu navigation - Contacts list view renders with real data from PostgreSQL Infrastructure: - 14MB single binary (CGO_ENABLED=0) - Docker Compose (Go server + PostgreSQL 16) - Zero phone-home (no outbound calls to odoo.com) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
112
pkg/modules/graph.go
Normal file
112
pkg/modules/graph.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"odoo-go/pkg/orm"
|
||||
)
|
||||
|
||||
// ResolveDependencies returns modules in topological order (dependencies first).
|
||||
// Mirrors: odoo/modules/module_graph.py Graph.add_modules()
|
||||
//
|
||||
// Uses Kahn's algorithm for topological sort.
|
||||
func ResolveDependencies(moduleNames []string) ([]string, error) {
|
||||
// Build adjacency list and in-degree map
|
||||
inDegree := make(map[string]int)
|
||||
dependents := make(map[string][]string) // module → modules that depend on it
|
||||
|
||||
// Initialize all requested modules
|
||||
for _, name := range moduleNames {
|
||||
if _, exists := inDegree[name]; !exists {
|
||||
inDegree[name] = 0
|
||||
}
|
||||
}
|
||||
|
||||
// Build graph from dependencies
|
||||
for _, name := range moduleNames {
|
||||
m := Get(name)
|
||||
if m == nil {
|
||||
return nil, fmt.Errorf("modules: %q not found", name)
|
||||
}
|
||||
for _, dep := range m.Depends {
|
||||
// Ensure dependency is in our set
|
||||
if _, exists := inDegree[dep]; !exists {
|
||||
inDegree[dep] = 0
|
||||
}
|
||||
inDegree[name]++
|
||||
dependents[dep] = append(dependents[dep], name)
|
||||
}
|
||||
}
|
||||
|
||||
// Kahn's algorithm
|
||||
var queue []string
|
||||
for name, degree := range inDegree {
|
||||
if degree == 0 {
|
||||
queue = append(queue, name)
|
||||
}
|
||||
}
|
||||
|
||||
var sorted []string
|
||||
for len(queue) > 0 {
|
||||
// Pop first element
|
||||
current := queue[0]
|
||||
queue = queue[1:]
|
||||
sorted = append(sorted, current)
|
||||
|
||||
// Reduce in-degree for dependents
|
||||
for _, dep := range dependents[current] {
|
||||
inDegree[dep]--
|
||||
if inDegree[dep] == 0 {
|
||||
queue = append(queue, dep)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check for circular dependencies
|
||||
if len(sorted) != len(inDegree) {
|
||||
var circular []string
|
||||
for name, degree := range inDegree {
|
||||
if degree > 0 {
|
||||
circular = append(circular, name)
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("modules: circular dependency detected among: %v", circular)
|
||||
}
|
||||
|
||||
return sorted, nil
|
||||
}
|
||||
|
||||
// LoadModules initializes all modules in dependency order.
|
||||
// Mirrors: odoo/modules/loading.py load_modules()
|
||||
func LoadModules(moduleNames []string) error {
|
||||
sorted, err := ResolveDependencies(moduleNames)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Phase 1: Call Init() for each module (registers models and fields)
|
||||
for _, name := range sorted {
|
||||
m := Get(name)
|
||||
if m == nil {
|
||||
continue
|
||||
}
|
||||
if m.Init != nil {
|
||||
m.Init()
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 2: Call PostInit() after all models are registered
|
||||
for _, name := range sorted {
|
||||
m := Get(name)
|
||||
if m == nil {
|
||||
continue
|
||||
}
|
||||
if m.PostInit != nil {
|
||||
m.PostInit()
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 3: Build computed field dependency maps
|
||||
orm.SetupAllComputes()
|
||||
|
||||
return nil
|
||||
}
|
||||
76
pkg/modules/module.go
Normal file
76
pkg/modules/module.go
Normal file
@@ -0,0 +1,76 @@
|
||||
// Package modules implements Odoo's module system.
|
||||
// Mirrors: odoo/modules/module.py, odoo/modules/loading.py
|
||||
package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Module represents an Odoo addon module.
|
||||
// Mirrors: ir.module.module + __manifest__.py
|
||||
type Module struct {
|
||||
Name string // Technical name (e.g., "base", "account", "sale")
|
||||
Description string // Human-readable description
|
||||
Version string // Module version
|
||||
Category string // Module category
|
||||
Depends []string // Required modules (dependency list)
|
||||
AutoInstall bool // Auto-install when all depends are installed
|
||||
Application bool // Show in app list
|
||||
Installable bool // Can be installed
|
||||
Sequence int // Loading order
|
||||
|
||||
// Init function registers models, fields, and methods.
|
||||
// Called during module loading in dependency order.
|
||||
Init func()
|
||||
|
||||
// PostInit is called after all modules are loaded.
|
||||
PostInit func()
|
||||
|
||||
// Data files to load (SQL seed data, etc.)
|
||||
Data []string
|
||||
}
|
||||
|
||||
// ModuleRegistry holds all registered modules.
|
||||
// Mirrors: odoo/modules/module.py loaded modules
|
||||
var ModuleRegistry = &moduleRegistry{
|
||||
modules: make(map[string]*Module),
|
||||
}
|
||||
|
||||
type moduleRegistry struct {
|
||||
mu sync.RWMutex
|
||||
modules map[string]*Module
|
||||
order []string // Registration order
|
||||
}
|
||||
|
||||
// Register adds a module to the registry.
|
||||
func Register(m *Module) {
|
||||
ModuleRegistry.mu.Lock()
|
||||
defer ModuleRegistry.mu.Unlock()
|
||||
|
||||
if m.Name == "" {
|
||||
panic("modules: module name is required")
|
||||
}
|
||||
if _, exists := ModuleRegistry.modules[m.Name]; exists {
|
||||
panic(fmt.Sprintf("modules: module %q already registered", m.Name))
|
||||
}
|
||||
|
||||
ModuleRegistry.modules[m.Name] = m
|
||||
ModuleRegistry.order = append(ModuleRegistry.order, m.Name)
|
||||
}
|
||||
|
||||
// Get returns a module by name.
|
||||
func Get(name string) *Module {
|
||||
ModuleRegistry.mu.RLock()
|
||||
defer ModuleRegistry.mu.RUnlock()
|
||||
return ModuleRegistry.modules[name]
|
||||
}
|
||||
|
||||
// All returns all registered module names.
|
||||
func All() []string {
|
||||
ModuleRegistry.mu.RLock()
|
||||
defer ModuleRegistry.mu.RUnlock()
|
||||
result := make([]string, len(ModuleRegistry.order))
|
||||
copy(result, ModuleRegistry.order)
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user