Files
goodie/addons/hr/models/hr.go
Marc 03fd58a852 Bring all areas to 60%: modules, reporting, i18n, views, data
Business modules deepened:
- sale: tag_ids, invoice/delivery counts with computes
- stock: _action_confirm/_action_done on stock.move, quant update stub
- purchase: done state added
- hr: parent_id, address_home_id, no_of_recruitment
- project: user_id, date_start, kanban_state on tasks

Reporting framework (0% → 60%):
- ir.actions.report model registered
- /report/html/<name>/<ids> endpoint serves styled HTML reports
- Report-to-model mapping for invoice, sale, stock, purchase

i18n framework (0% → 60%):
- ir.translation model with src/value/lang/type fields
- handleTranslations loads from DB, returns per-module structure
- 140 German translations seeded (UI terms across all modules)
- res_lang seeded with en_US + de_DE

Views/UI improved:
- Stored form views: sale.order (with editable O2M lines), account.move
  (with Post/Cancel buttons), res.partner (with title)
- Stored list views: purchase.order, hr.employee, project.project

Demo data expanded:
- 5 products (templates + variants with codes)
- 3 HR departments, 3 employees
- 2 projects

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 20:11:45 +02:00

162 lines
7.2 KiB
Go

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("parent_id", "hr.employee", orm.FieldOpts{String: "Manager", Index: true}),
orm.Many2one("address_id", "res.partner", orm.FieldOpts{String: "Work Address"}),
orm.Many2one("address_home_id", "res.partner", orm.FieldOpts{
String: "Private Address", Groups: "hr.group_hr_user",
}),
orm.Char("identification_id", orm.FieldOpts{String: "Identification No", Groups: "hr.group_hr_user"}),
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"}),
)
// toggle_active: archive/unarchive employee
m.RegisterMethod("toggle_active", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
env := rs.Env()
for _, id := range rs.IDs() {
env.Tx().Exec(env.Ctx(),
`UPDATE hr_employee SET active = NOT active WHERE id = $1`, id)
}
return true, nil
})
}
// 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_recruitment", orm.FieldOpts{String: "Expected in Recruitment"}),
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"}),
)
}