payroll
payroll copied to clipboard
[18.0][FIX] payroll_account: Fix _get_partner_id logic in hr_payslip_line
Description
This PR fixes the partner logic in hr_payslip_line._get_partner_id() to address issue #221 where journal entries were created without proper partner information in Odoo 17.0+.
Problem
The original logic had several issues:
- Odoo removed field
address_home_idfrom modelhr.employeewhich was used in getting partner for employee inpayroll_accountto set partner in created journal entry. Migrated code removed usage ofaddress_home_idbut did not use a replacement. - Old code (16.0 and earlier) used a confusing fallback chain that could potentially assign wrong partners
- Missing
liability_currentaccount type in partner-required accounts
Solution
Replaced the flawed logic with semantically-correct partner assignment using the proper partner source:
- asset_receivable & liability_current: Always use employee partner (work_contact_id → bank_account_id.partner_id)
- liability_payable: Always use register partner (salary_rule_id.register_id.partner_id)
- Other account types (expense, income, etc.): No partner assigned
Changes
Core Logic (payroll_account/models/hr_payslip_line.py)
- Simplified logic from confusing fallback to clear semantic rules
- Added liability_current to partner-required account types
- Enhanced documentation with business semantics and partner sources
- Replaced if register_partner_id or acc_type in (...) with proper if elif structure
Business Logic
| Account Type | Business Use | Partner Source |
|---|---|---|
| asset_receivable | Employee loans, advances | Employee |
| liability_current | Employee salary payable | Employee |
| liability_payable | Tax authorities, insurance | Register Partner |
| expense, income, etc. | Internal accounting | No Partner |
Test Coverage
Added test_partner_logic_account_types() to verify:
- asset_receivable accounts return employee partner
- liability_current accounts return employee partner
- liability_payable accounts return register partner
- Other account types return False (no partner)
Fixes #221
Pull Request opened by Augment Code with guidance from the PR author
Hi @nimarosa, @appstogrow, some modules you are maintaining are being modified, check this out!