- Portal: /my/* routes, signup, password reset, portal user support - Email Inbound: IMAP polling (go-imap/v2), thread matching - Discuss: mail.channel, long-polling bus, DM, unread count - Cron: ir.cron runner (goroutine scheduler) - Bank Import, CSV/Excel Import - Automation (ir.actions.server) - Fetchmail service - HR Payroll model - Various fixes across account, sale, stock, purchase, crm, hr, project Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
33 lines
1.2 KiB
Go
33 lines
1.2 KiB
Go
package models
|
|
|
|
import "odoo-go/pkg/orm"
|
|
|
|
// initHrAttendance registers the hr.attendance model.
|
|
// Mirrors: odoo/addons/hr_attendance/models/hr_attendance.py
|
|
func initHrAttendance() {
|
|
m := orm.NewModel("hr.attendance", orm.ModelOpts{
|
|
Description: "Attendance",
|
|
Order: "check_in desc",
|
|
})
|
|
m.AddFields(
|
|
orm.Many2one("employee_id", "hr.employee", orm.FieldOpts{String: "Employee", Required: true}),
|
|
orm.Datetime("check_in", orm.FieldOpts{String: "Check In", Required: true}),
|
|
orm.Datetime("check_out", orm.FieldOpts{String: "Check Out"}),
|
|
orm.Float("worked_hours", orm.FieldOpts{String: "Worked Hours", Compute: "_compute_worked_hours", Store: true}),
|
|
orm.Many2one("company_id", "res.company", orm.FieldOpts{String: "Company"}),
|
|
)
|
|
|
|
m.RegisterCompute("worked_hours", func(rs *orm.Recordset) (orm.Values, error) {
|
|
env := rs.Env()
|
|
attID := rs.IDs()[0]
|
|
var hours float64
|
|
if err := env.Tx().QueryRow(env.Ctx(),
|
|
`SELECT COALESCE(EXTRACT(EPOCH FROM (COALESCE(check_out, NOW()) - check_in)) / 3600.0, 0)
|
|
FROM hr_attendance WHERE id = $1`, attID,
|
|
).Scan(&hours); err != nil {
|
|
return orm.Values{"worked_hours": float64(0)}, nil
|
|
}
|
|
return orm.Values{"worked_hours": hours}, nil
|
|
})
|
|
}
|