Massive module expansion: Stock, CRM, HR — +2895 LOC
Stock (1193→2867 LOC): - Valuation layers (FIFO consumption, product valuation history) - Landed costs (split by equal/qty/cost/weight/volume, validation) - Stock reports (by product, by location, move history, valuation) - Forecasting (on_hand + incoming - outgoing per product) - Batch transfers (confirm/assign/done with picking delegation) - Barcode interface (scan product/lot/package/location, qty increment) CRM (233→1113 LOC): - Sales teams with dashboard KPIs (opportunity count/amount/unassigned) - Team members with lead capacity + round-robin auto-assignment - Lead extended: activities, UTM tracking, scoring, address fields - Lead methods: merge, duplicate, schedule activity, set priority/stage - Pipeline analysis (stages, win rate, conversion, team/salesperson perf) - Partner onchange (auto-populate contact from partner) HR (223→520 LOC): - Leave management: hr.leave.type, hr.leave, hr.leave.allocation with full approval workflow (draft→confirm→validate/refuse) - Attendance: check in/out with computed worked_hours - Expenses: hr.expense + hr.expense.sheet with state machine - Skills/Resume: skill types, employee skills, resume lines - Employee extensions: skills, attendance, leave count links Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -109,6 +109,22 @@ func initHREmployee() {
|
||||
})
|
||||
}
|
||||
|
||||
// initHrEmployeeExtensions adds skill, resume, attendance and leave fields
|
||||
// to hr.employee after the related models have been registered.
|
||||
func initHrEmployeeExtensions() {
|
||||
emp := orm.ExtendModel("hr.employee")
|
||||
emp.AddFields(
|
||||
orm.One2many("skill_ids", "hr.employee.skill", "employee_id", orm.FieldOpts{String: "Skills"}),
|
||||
orm.One2many("resume_line_ids", "hr.resume.line", "employee_id", orm.FieldOpts{String: "Resume"}),
|
||||
orm.One2many("attendance_ids", "hr.attendance", "employee_id", orm.FieldOpts{String: "Attendances"}),
|
||||
orm.Float("leaves_count", orm.FieldOpts{String: "Time Off", Compute: "_compute_leaves"}),
|
||||
orm.Selection("attendance_state", []orm.SelectionItem{
|
||||
{Value: "checked_out", Label: "Checked Out"},
|
||||
{Value: "checked_in", Label: "Checked In"},
|
||||
}, orm.FieldOpts{String: "Attendance", Compute: "_compute_attendance_state"}),
|
||||
)
|
||||
}
|
||||
|
||||
// initHRDepartment registers the hr.department model.
|
||||
// Mirrors: odoo/addons/hr/models/hr_department.py
|
||||
func initHRDepartment() {
|
||||
|
||||
30
addons/hr/models/hr_attendance.go
Normal file
30
addons/hr/models/hr_attendance.go
Normal file
@@ -0,0 +1,30 @@
|
||||
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
|
||||
env.Tx().QueryRow(env.Ctx(),
|
||||
`SELECT COALESCE(EXTRACT(EPOCH FROM (check_out - check_in)) / 3600.0, 0)
|
||||
FROM hr_attendance WHERE id = $1 AND check_out IS NOT NULL`, attID,
|
||||
).Scan(&hours)
|
||||
return orm.Values{"worked_hours": hours}, nil
|
||||
})
|
||||
}
|
||||
59
addons/hr/models/hr_expense.go
Normal file
59
addons/hr/models/hr_expense.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package models
|
||||
|
||||
import "odoo-go/pkg/orm"
|
||||
|
||||
// initHrExpense registers the hr.expense and hr.expense.sheet models.
|
||||
// Mirrors: odoo/addons/hr_expense/models/hr_expense.py
|
||||
func initHrExpense() {
|
||||
orm.NewModel("hr.expense", orm.ModelOpts{
|
||||
Description: "Expense",
|
||||
Order: "date desc, id desc",
|
||||
}).AddFields(
|
||||
orm.Char("name", orm.FieldOpts{String: "Description", Required: true}),
|
||||
orm.Many2one("employee_id", "hr.employee", orm.FieldOpts{String: "Employee", Required: true}),
|
||||
orm.Many2one("product_id", "product.product", orm.FieldOpts{String: "Expense Type"}),
|
||||
orm.Date("date", orm.FieldOpts{String: "Date", Required: true}),
|
||||
orm.Monetary("total_amount", orm.FieldOpts{String: "Total", Required: true, CurrencyField: "currency_id"}),
|
||||
orm.Monetary("unit_amount", orm.FieldOpts{String: "Unit Price", CurrencyField: "currency_id"}),
|
||||
orm.Float("quantity", orm.FieldOpts{String: "Quantity", Default: 1}),
|
||||
orm.Many2one("currency_id", "res.currency", orm.FieldOpts{String: "Currency"}),
|
||||
orm.Many2one("company_id", "res.company", orm.FieldOpts{String: "Company"}),
|
||||
orm.Many2one("sheet_id", "hr.expense.sheet", orm.FieldOpts{String: "Expense Report"}),
|
||||
orm.Many2one("account_id", "account.account", orm.FieldOpts{String: "Account"}),
|
||||
orm.Selection("state", []orm.SelectionItem{
|
||||
{Value: "draft", Label: "To Submit"},
|
||||
{Value: "reported", Label: "Submitted"},
|
||||
{Value: "approved", Label: "Approved"},
|
||||
{Value: "done", Label: "Paid"},
|
||||
{Value: "refused", Label: "Refused"},
|
||||
}, orm.FieldOpts{String: "Status", Default: "draft"}),
|
||||
orm.Selection("payment_mode", []orm.SelectionItem{
|
||||
{Value: "own_account", Label: "Employee (to reimburse)"},
|
||||
{Value: "company_account", Label: "Company"},
|
||||
}, orm.FieldOpts{String: "Payment By", Default: "own_account"}),
|
||||
orm.Text("description", orm.FieldOpts{String: "Notes"}),
|
||||
orm.Binary("receipt", orm.FieldOpts{String: "Receipt"}),
|
||||
)
|
||||
|
||||
orm.NewModel("hr.expense.sheet", orm.ModelOpts{
|
||||
Description: "Expense Report",
|
||||
Order: "create_date desc",
|
||||
}).AddFields(
|
||||
orm.Char("name", orm.FieldOpts{String: "Report Name", Required: true}),
|
||||
orm.Many2one("employee_id", "hr.employee", orm.FieldOpts{String: "Employee", Required: true}),
|
||||
orm.Many2one("manager_id", "hr.employee", orm.FieldOpts{String: "Manager"}),
|
||||
orm.One2many("expense_line_ids", "hr.expense", "sheet_id", orm.FieldOpts{String: "Expenses"}),
|
||||
orm.Monetary("total_amount", orm.FieldOpts{String: "Total", Compute: "_compute_total", Store: true, CurrencyField: "currency_id"}),
|
||||
orm.Many2one("currency_id", "res.currency", orm.FieldOpts{String: "Currency"}),
|
||||
orm.Many2one("company_id", "res.company", orm.FieldOpts{String: "Company"}),
|
||||
orm.Selection("state", []orm.SelectionItem{
|
||||
{Value: "draft", Label: "Draft"},
|
||||
{Value: "submit", Label: "Submitted"},
|
||||
{Value: "approve", Label: "Approved"},
|
||||
{Value: "post", Label: "Posted"},
|
||||
{Value: "done", Label: "Paid"},
|
||||
{Value: "cancel", Label: "Refused"},
|
||||
}, orm.FieldOpts{String: "Status", Default: "draft"}),
|
||||
orm.Many2one("account_move_id", "account.move", orm.FieldOpts{String: "Journal Entry"}),
|
||||
)
|
||||
}
|
||||
121
addons/hr/models/hr_leave.go
Normal file
121
addons/hr/models/hr_leave.go
Normal file
@@ -0,0 +1,121 @@
|
||||
package models
|
||||
|
||||
import "odoo-go/pkg/orm"
|
||||
|
||||
// initHrLeaveType registers the hr.leave.type model.
|
||||
// Mirrors: odoo/addons/hr_holidays/models/hr_leave_type.py
|
||||
func initHrLeaveType() {
|
||||
orm.NewModel("hr.leave.type", orm.ModelOpts{
|
||||
Description: "Time Off Type",
|
||||
Order: "sequence, id",
|
||||
}).AddFields(
|
||||
orm.Char("name", orm.FieldOpts{String: "Name", Required: true, Translate: true}),
|
||||
orm.Integer("sequence", orm.FieldOpts{String: "Sequence", Default: 100}),
|
||||
orm.Boolean("active", orm.FieldOpts{String: "Active", Default: true}),
|
||||
orm.Selection("leave_validation_type", []orm.SelectionItem{
|
||||
{Value: "no_validation", Label: "No Validation"},
|
||||
{Value: "hr", Label: "By Time Off Officer"},
|
||||
{Value: "manager", Label: "By Employee's Approver"},
|
||||
{Value: "both", Label: "By Employee's Approver and Time Off Officer"},
|
||||
}, orm.FieldOpts{String: "Approval", Default: "hr"}),
|
||||
orm.Many2one("company_id", "res.company", orm.FieldOpts{String: "Company"}),
|
||||
orm.Integer("color", orm.FieldOpts{String: "Color"}),
|
||||
orm.Boolean("requires_allocation", orm.FieldOpts{String: "Requires Allocation", Default: true}),
|
||||
orm.Float("max_allowed", orm.FieldOpts{String: "Max Days Allowed"}),
|
||||
)
|
||||
}
|
||||
|
||||
// initHrLeave registers the hr.leave model.
|
||||
// Mirrors: odoo/addons/hr_holidays/models/hr_leave.py
|
||||
func initHrLeave() {
|
||||
m := orm.NewModel("hr.leave", orm.ModelOpts{
|
||||
Description: "Time Off",
|
||||
Order: "date_from desc",
|
||||
})
|
||||
m.AddFields(
|
||||
orm.Char("name", orm.FieldOpts{String: "Description"}),
|
||||
orm.Many2one("employee_id", "hr.employee", orm.FieldOpts{String: "Employee", Required: true}),
|
||||
orm.Many2one("holiday_status_id", "hr.leave.type", orm.FieldOpts{String: "Time Off Type", Required: true}),
|
||||
orm.Many2one("department_id", "hr.department", orm.FieldOpts{String: "Department"}),
|
||||
orm.Many2one("manager_id", "hr.employee", orm.FieldOpts{String: "Manager"}),
|
||||
orm.Datetime("date_from", orm.FieldOpts{String: "Start Date", Required: true}),
|
||||
orm.Datetime("date_to", orm.FieldOpts{String: "End Date", Required: true}),
|
||||
orm.Float("number_of_days", orm.FieldOpts{String: "Duration (Days)"}),
|
||||
orm.Selection("state", []orm.SelectionItem{
|
||||
{Value: "draft", Label: "To Submit"},
|
||||
{Value: "confirm", Label: "To Approve"},
|
||||
{Value: "validate1", Label: "Second Approval"},
|
||||
{Value: "validate", Label: "Approved"},
|
||||
{Value: "refuse", Label: "Refused"},
|
||||
}, orm.FieldOpts{String: "Status", Default: "draft"}),
|
||||
orm.Many2one("company_id", "res.company", orm.FieldOpts{String: "Company"}),
|
||||
orm.Text("notes", orm.FieldOpts{String: "Reasons"}),
|
||||
)
|
||||
|
||||
m.RegisterMethod("action_approve", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
|
||||
env := rs.Env()
|
||||
for _, id := range rs.IDs() {
|
||||
env.Tx().Exec(env.Ctx(), `UPDATE hr_leave SET state = 'validate' WHERE id = $1 AND state IN ('confirm','validate1')`, id)
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
|
||||
m.RegisterMethod("action_refuse", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
|
||||
env := rs.Env()
|
||||
for _, id := range rs.IDs() {
|
||||
env.Tx().Exec(env.Ctx(), `UPDATE hr_leave SET state = 'refuse' WHERE id = $1`, id)
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
|
||||
m.RegisterMethod("action_draft", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
|
||||
env := rs.Env()
|
||||
for _, id := range rs.IDs() {
|
||||
env.Tx().Exec(env.Ctx(), `UPDATE hr_leave SET state = 'draft' WHERE id = $1`, id)
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
|
||||
m.RegisterMethod("action_confirm", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
|
||||
env := rs.Env()
|
||||
for _, id := range rs.IDs() {
|
||||
env.Tx().Exec(env.Ctx(), `UPDATE hr_leave SET state = 'confirm' WHERE id = $1 AND state = 'draft'`, id)
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
}
|
||||
|
||||
// initHrLeaveAllocation registers the hr.leave.allocation model.
|
||||
// Mirrors: odoo/addons/hr_holidays/models/hr_leave_allocation.py
|
||||
func initHrLeaveAllocation() {
|
||||
m := orm.NewModel("hr.leave.allocation", orm.ModelOpts{
|
||||
Description: "Time Off Allocation",
|
||||
Order: "create_date desc",
|
||||
})
|
||||
m.AddFields(
|
||||
orm.Char("name", orm.FieldOpts{String: "Description"}),
|
||||
orm.Many2one("employee_id", "hr.employee", orm.FieldOpts{String: "Employee", Required: true}),
|
||||
orm.Many2one("holiday_status_id", "hr.leave.type", orm.FieldOpts{String: "Time Off Type", Required: true}),
|
||||
orm.Float("number_of_days", orm.FieldOpts{String: "Duration (Days)", Required: true}),
|
||||
orm.Selection("state", []orm.SelectionItem{
|
||||
{Value: "draft", Label: "To Submit"},
|
||||
{Value: "confirm", Label: "To Approve"},
|
||||
{Value: "validate", Label: "Approved"},
|
||||
{Value: "refuse", Label: "Refused"},
|
||||
}, orm.FieldOpts{String: "Status", Default: "draft"}),
|
||||
orm.Many2one("department_id", "hr.department", orm.FieldOpts{String: "Department"}),
|
||||
orm.Many2one("company_id", "res.company", orm.FieldOpts{String: "Company"}),
|
||||
orm.Selection("allocation_type", []orm.SelectionItem{
|
||||
{Value: "regular", Label: "Regular Allocation"},
|
||||
{Value: "accrual", Label: "Accrual Allocation"},
|
||||
}, orm.FieldOpts{String: "Allocation Type", Default: "regular"}),
|
||||
)
|
||||
|
||||
m.RegisterMethod("action_approve", func(rs *orm.Recordset, args ...interface{}) (interface{}, error) {
|
||||
env := rs.Env()
|
||||
for _, id := range rs.IDs() {
|
||||
env.Tx().Exec(env.Ctx(), `UPDATE hr_leave_allocation SET state = 'validate' WHERE id = $1`, id)
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
}
|
||||
53
addons/hr/models/hr_skills.go
Normal file
53
addons/hr/models/hr_skills.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package models
|
||||
|
||||
import "odoo-go/pkg/orm"
|
||||
|
||||
// initHrSkill registers hr.skill.type, hr.skill, hr.employee.skill and hr.resume.line.
|
||||
// Mirrors: odoo/addons/hr_skills/models/hr_skill.py
|
||||
func initHrSkill() {
|
||||
orm.NewModel("hr.skill.type", orm.ModelOpts{
|
||||
Description: "Skill Type",
|
||||
Order: "name",
|
||||
}).AddFields(
|
||||
orm.Char("name", orm.FieldOpts{String: "Name", Required: true}),
|
||||
orm.One2many("skill_ids", "hr.skill", "skill_type_id", orm.FieldOpts{String: "Skills"}),
|
||||
)
|
||||
|
||||
orm.NewModel("hr.skill", orm.ModelOpts{
|
||||
Description: "Skill",
|
||||
Order: "name",
|
||||
}).AddFields(
|
||||
orm.Char("name", orm.FieldOpts{String: "Name", Required: true}),
|
||||
orm.Many2one("skill_type_id", "hr.skill.type", orm.FieldOpts{String: "Skill Type", Required: true}),
|
||||
)
|
||||
|
||||
orm.NewModel("hr.employee.skill", orm.ModelOpts{
|
||||
Description: "Employee Skill",
|
||||
}).AddFields(
|
||||
orm.Many2one("employee_id", "hr.employee", orm.FieldOpts{String: "Employee", Required: true, OnDelete: orm.OnDeleteCascade}),
|
||||
orm.Many2one("skill_id", "hr.skill", orm.FieldOpts{String: "Skill", Required: true}),
|
||||
orm.Many2one("skill_type_id", "hr.skill.type", orm.FieldOpts{String: "Skill Type"}),
|
||||
orm.Selection("skill_level", []orm.SelectionItem{
|
||||
{Value: "beginner", Label: "Beginner"},
|
||||
{Value: "intermediate", Label: "Intermediate"},
|
||||
{Value: "advanced", Label: "Advanced"},
|
||||
{Value: "expert", Label: "Expert"},
|
||||
}, orm.FieldOpts{String: "Level", Default: "beginner"}),
|
||||
)
|
||||
|
||||
orm.NewModel("hr.resume.line", orm.ModelOpts{
|
||||
Description: "Resume Line",
|
||||
Order: "date_start desc",
|
||||
}).AddFields(
|
||||
orm.Many2one("employee_id", "hr.employee", orm.FieldOpts{String: "Employee", Required: true, OnDelete: orm.OnDeleteCascade}),
|
||||
orm.Char("name", orm.FieldOpts{String: "Name", Required: true}),
|
||||
orm.Date("date_start", orm.FieldOpts{String: "Start Date", Required: true}),
|
||||
orm.Date("date_end", orm.FieldOpts{String: "End Date"}),
|
||||
orm.Text("description", orm.FieldOpts{String: "Description"}),
|
||||
orm.Selection("line_type_id", []orm.SelectionItem{
|
||||
{Value: "experience", Label: "Experience"},
|
||||
{Value: "education", Label: "Education"},
|
||||
{Value: "certification", Label: "Certification"},
|
||||
}, orm.FieldOpts{String: "Type", Default: "experience"}),
|
||||
)
|
||||
}
|
||||
@@ -1,9 +1,27 @@
|
||||
package models
|
||||
|
||||
func Init() {
|
||||
// Core HR models
|
||||
initResourceCalendar()
|
||||
initHREmployee()
|
||||
initHRDepartment()
|
||||
initHRJob()
|
||||
initHrContract()
|
||||
|
||||
// Leave management
|
||||
initHrLeaveType()
|
||||
initHrLeave()
|
||||
initHrLeaveAllocation()
|
||||
|
||||
// Attendance
|
||||
initHrAttendance()
|
||||
|
||||
// Expenses
|
||||
initHrExpense()
|
||||
|
||||
// Skills & Resume
|
||||
initHrSkill()
|
||||
|
||||
// Extend hr.employee with links to new models (must come last)
|
||||
initHrEmployeeExtensions()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user