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:
145
addons/hr/models/hr.go
Normal file
145
addons/hr/models/hr.go
Normal file
@@ -0,0 +1,145 @@
|
||||
package models
|
||||
|
||||
import "odoo-go/pkg/orm"
|
||||
|
||||
// initResourceCalendar registers resource.calendar — working schedules.
|
||||
// Mirrors: odoo/addons/resource/models/resource.py
|
||||
func initResourceCalendar() {
|
||||
m := orm.NewModel("resource.calendar", orm.ModelOpts{
|
||||
Description: "Resource Working Time",
|
||||
Order: "name",
|
||||
})
|
||||
|
||||
m.AddFields(
|
||||
orm.Char("name", orm.FieldOpts{String: "Name", Required: true}),
|
||||
orm.Boolean("active", orm.FieldOpts{String: "Active", Default: true}),
|
||||
orm.Many2one("company_id", "res.company", orm.FieldOpts{String: "Company"}),
|
||||
orm.Float("hours_per_week", orm.FieldOpts{String: "Hours per Week"}),
|
||||
orm.Char("tz", orm.FieldOpts{String: "Timezone", Default: "Europe/Berlin"}),
|
||||
orm.Boolean("flexible_hours", orm.FieldOpts{String: "Flexible Hours"}),
|
||||
orm.One2many("attendance_ids", "resource.calendar.attendance", "calendar_id", orm.FieldOpts{String: "Attendances"}),
|
||||
)
|
||||
|
||||
// resource.calendar.attendance — work time slots
|
||||
orm.NewModel("resource.calendar.attendance", orm.ModelOpts{
|
||||
Description: "Work Detail",
|
||||
Order: "dayofweek, hour_from",
|
||||
}).AddFields(
|
||||
orm.Char("name", orm.FieldOpts{String: "Name", Required: true}),
|
||||
orm.Selection("dayofweek", []orm.SelectionItem{
|
||||
{Value: "0", Label: "Monday"}, {Value: "1", Label: "Tuesday"},
|
||||
{Value: "2", Label: "Wednesday"}, {Value: "3", Label: "Thursday"},
|
||||
{Value: "4", Label: "Friday"}, {Value: "5", Label: "Saturday"},
|
||||
{Value: "6", Label: "Sunday"},
|
||||
}, orm.FieldOpts{String: "Day of Week", Required: true}),
|
||||
orm.Float("hour_from", orm.FieldOpts{String: "Work from", Required: true}),
|
||||
orm.Float("hour_to", orm.FieldOpts{String: "Work to", Required: true}),
|
||||
orm.Many2one("calendar_id", "resource.calendar", orm.FieldOpts{
|
||||
String: "Calendar", Required: true, OnDelete: orm.OnDeleteCascade,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
// initHREmployee registers the hr.employee model.
|
||||
// Mirrors: odoo/addons/hr/models/hr_employee.py
|
||||
func initHREmployee() {
|
||||
m := orm.NewModel("hr.employee", orm.ModelOpts{
|
||||
Description: "Employee",
|
||||
Order: "name",
|
||||
})
|
||||
|
||||
m.AddFields(
|
||||
orm.Char("name", orm.FieldOpts{String: "Employee Name", Required: true, Index: true}),
|
||||
orm.Many2one("user_id", "res.users", orm.FieldOpts{String: "Related User"}),
|
||||
orm.Many2one("department_id", "hr.department", orm.FieldOpts{String: "Department", Index: true}),
|
||||
orm.Many2one("job_id", "hr.job", orm.FieldOpts{String: "Job Position"}),
|
||||
orm.Char("job_title", orm.FieldOpts{String: "Job Title"}),
|
||||
orm.Many2one("company_id", "res.company", orm.FieldOpts{
|
||||
String: "Company", Required: true, Index: true,
|
||||
}),
|
||||
orm.Many2one("address_id", "res.partner", orm.FieldOpts{String: "Work Address"}),
|
||||
orm.Char("work_email", orm.FieldOpts{String: "Work Email"}),
|
||||
orm.Char("work_phone", orm.FieldOpts{String: "Work Phone"}),
|
||||
orm.Char("mobile_phone", orm.FieldOpts{String: "Work Mobile"}),
|
||||
orm.Many2one("coach_id", "hr.employee", orm.FieldOpts{String: "Coach"}),
|
||||
orm.Boolean("active", orm.FieldOpts{String: "Active", Default: true}),
|
||||
orm.Many2one("resource_calendar_id", "resource.calendar", orm.FieldOpts{String: "Working Schedule"}),
|
||||
orm.Selection("gender", []orm.SelectionItem{
|
||||
{Value: "male", Label: "Male"},
|
||||
{Value: "female", Label: "Female"},
|
||||
{Value: "other", Label: "Other"},
|
||||
}, orm.FieldOpts{String: "Gender"}),
|
||||
orm.Date("birthday", orm.FieldOpts{String: "Date of Birth", Groups: "hr.group_hr_user"}),
|
||||
orm.Selection("marital", []orm.SelectionItem{
|
||||
{Value: "single", Label: "Single"},
|
||||
{Value: "married", Label: "Married"},
|
||||
{Value: "cohabitant", Label: "Legal Cohabitant"},
|
||||
{Value: "widower", Label: "Widower"},
|
||||
{Value: "divorced", Label: "Divorced"},
|
||||
}, orm.FieldOpts{String: "Marital Status", Default: "single"}),
|
||||
orm.Char("emergency_contact", orm.FieldOpts{String: "Emergency Contact"}),
|
||||
orm.Char("emergency_phone", orm.FieldOpts{String: "Emergency Phone"}),
|
||||
orm.Selection("certificate", []orm.SelectionItem{
|
||||
{Value: "graduate", Label: "Graduate"},
|
||||
{Value: "bachelor", Label: "Bachelor"},
|
||||
{Value: "master", Label: "Master"},
|
||||
{Value: "doctor", Label: "Doctor"},
|
||||
{Value: "other", Label: "Other"},
|
||||
}, orm.FieldOpts{String: "Certificate Level"}),
|
||||
orm.Char("study_field", orm.FieldOpts{String: "Field of Study"}),
|
||||
orm.Char("visa_no", orm.FieldOpts{String: "Visa No", Groups: "hr.group_hr_user"}),
|
||||
orm.Char("permit_no", orm.FieldOpts{String: "Work Permit No", Groups: "hr.group_hr_user"}),
|
||||
orm.Integer("km_home_work", orm.FieldOpts{String: "Home-Work Distance (km)"}),
|
||||
orm.Binary("image_1920", orm.FieldOpts{String: "Image"}),
|
||||
)
|
||||
}
|
||||
|
||||
// initHRDepartment registers the hr.department model.
|
||||
// Mirrors: odoo/addons/hr/models/hr_department.py
|
||||
func initHRDepartment() {
|
||||
m := orm.NewModel("hr.department", orm.ModelOpts{
|
||||
Description: "HR Department",
|
||||
Order: "name",
|
||||
})
|
||||
|
||||
m.AddFields(
|
||||
orm.Char("name", orm.FieldOpts{String: "Department Name", Required: true, Translate: true}),
|
||||
orm.Char("complete_name", orm.FieldOpts{
|
||||
String: "Complete Name",
|
||||
Compute: "_compute_complete_name",
|
||||
Store: true,
|
||||
}),
|
||||
orm.Many2one("parent_id", "hr.department", orm.FieldOpts{String: "Parent Department", Index: true}),
|
||||
orm.Many2one("manager_id", "hr.employee", orm.FieldOpts{String: "Manager"}),
|
||||
orm.Many2one("company_id", "res.company", orm.FieldOpts{
|
||||
String: "Company", Required: true, Index: true,
|
||||
}),
|
||||
orm.Boolean("active", orm.FieldOpts{String: "Active", Default: true}),
|
||||
orm.One2many("child_ids", "hr.department", "parent_id", orm.FieldOpts{String: "Child Departments"}),
|
||||
orm.One2many("member_ids", "hr.employee", "department_id", orm.FieldOpts{String: "Members"}),
|
||||
)
|
||||
}
|
||||
|
||||
// initHRJob registers the hr.job model.
|
||||
// Mirrors: odoo/addons/hr/models/hr_job.py
|
||||
func initHRJob() {
|
||||
m := orm.NewModel("hr.job", orm.ModelOpts{
|
||||
Description: "Job Position",
|
||||
Order: "name",
|
||||
})
|
||||
|
||||
m.AddFields(
|
||||
orm.Char("name", orm.FieldOpts{String: "Job Position", Required: true, Index: true, Translate: true}),
|
||||
orm.Many2one("department_id", "hr.department", orm.FieldOpts{String: "Department"}),
|
||||
orm.Many2one("company_id", "res.company", orm.FieldOpts{
|
||||
String: "Company", Required: true, Index: true,
|
||||
}),
|
||||
orm.Integer("expected_employees", orm.FieldOpts{String: "Expected New Employees", Default: 1}),
|
||||
orm.Integer("no_of_hired_employee", orm.FieldOpts{String: "Hired Employees"}),
|
||||
orm.Selection("state", []orm.SelectionItem{
|
||||
{Value: "recruit", Label: "Recruitment in Progress"},
|
||||
{Value: "open", Label: "Not Recruiting"},
|
||||
}, orm.FieldOpts{String: "Status", Required: true, Default: "recruit"}),
|
||||
orm.Text("description", orm.FieldOpts{String: "Job Description"}),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user