payroll icon indicating copy to clipboard operation
payroll copied to clipboard

[18.0][FIX] payroll_account: Fix _get_partner_id logic in hr_payslip_line

Open hussain opened this issue 2 months ago • 1 comments

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:

  1. Odoo removed field address_home_id from model hr.employee which was used in getting partner for employee in payroll_account to set partner in created journal entry. Migrated code removed usage of address_home_id but did not use a replacement.
  2. Old code (16.0 and earlier) used a confusing fallback chain that could potentially assign wrong partners
  3. Missing liability_current account 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

hussain avatar Oct 16 '25 12:10 hussain

Hi @nimarosa, @appstogrow, some modules you are maintaining are being modified, check this out!

OCA-git-bot avatar Oct 16 '25 12:10 OCA-git-bot