⚠️ HIGH |
Category: Odoo Tips |
ID: T09 |
Owner: CEO
T09 — Odoo 19 Payslip worked_days gộp OT — salary rules OT không chạy
Tóm tắt
Odoo 19 gộp TẤT CẢ OT work entries vàoworked_days['OVERTIME'] — KHÔNG tách riêng OT150/OT200/OT300. Salary rule condition worked_days['OT150'] LUÔN FALSE → rules không execute → OT không tính.
Chi tiết
is_overtime=True thành 1 dòng worked_days duy nhất với code OVERTIMEworked_daysworked_days.OT150 → False | worked_days.OVERTIME → True (chứa tổng hợp)Solution
Queryhr.work.entry trực tiếp thay vì dùng worked_days:
WRONG — luôn False
result = worked_days['OT150'] and worked_days['OT150'].number_of_hours or 0
CORRECT — query work entries trực tiếp
entries = payslip.env['hr.work.entry'].search([
('employee_id', '=', employee.id),
('work_entry_type_id.code', '=', 'OT150'),
('date', '>=', payslip.date_from),
('date', '<=', payslip.date_to),
('state', '=', 'validated'),
])
result = sum(entries.mapped('duration'))
Pattern này giống cách tính ALW_LUNCH_PT (query attendance trực tiếp).
Ảnh hưởng
Cách xử lý / Phòng tránh
1. KHÔNG dùngworked_days['OT_CODE'] cho OT types — luôn False
2. Query hr.work.entry trực tiếp với filter work_entry_type_id.code
3. Dùng payslip.env để access ORM từ salary rule Python code
4. Test bằng cách print worked_days dict trong salary rule → verify keys
Bằng chứng / Tham khảo
aef5ffa — fix OT salary rulesHR/scripts/fix_ot_salary_rules.py — script apply fixhr_payroll/models/hr_payslip.py → _get_worked_day_lines()Liên quan
📚 Published from Company Knowledge Base — T09
Last updated: 2026-03-12
Review by: 2026-06-10