Skip to content

Conversation

@hussain
Copy link
Contributor

@hussain hussain commented Oct 16, 2025

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. Migrated code removed usage of address_home_id but did not use a replacement. 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.
  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

nimarosa and others added 30 commits December 21, 2023 07:27
Currently translated at 100.0% (307 of 307 strings)

Translation: payroll-14.0/payroll-14.0-payroll
Translate-URL: https://translation.odoo-community.org/projects/payroll-14-0/payroll-14-0-payroll/es_AR/
…one record

[FIX] payroll: fix _compute_name singleton error
Currently translated at 100.0% (304 of 304 strings)

Translation: payroll-14.0/payroll-14.0-payroll
Translate-URL: https://translation.odoo-community.org/projects/payroll-14-0/payroll-14-0-payroll/es/
Currently translated at 100.0% (304 of 304 strings)

Translation: payroll-14.0/payroll-14.0-payroll
Translate-URL: https://translation.odoo-community.org/projects/payroll-14-0/payroll-14-0-payroll/es_AR/
…ing name

[IMP] payroll: Improve views, add child functionalities, allow compute of name

[FIX] payroll: fix test expected values

[IMP] payroll: [IMP] payroll: Improve views, add child functionalities, allow compute of name

[IMP] payroll: Improve views, add child functionalities, allow compute of name

[IMP] payroll: Improve views, add child functionalities, allow compute of name

[IMP] payroll: Improve views, add child functionalities, allow compute of name

[IMP] payroll: Add test coverage for new child view and flag

[IMP] payroll: Improve views, add child functionalities, allow compute of name

[IMP] payroll: change tab name

[IMP] payroll: Add info alert in salary_rule form explaining functionality
Currently translated at 100.0% (313 of 313 strings)

Translation: payroll-14.0/payroll-14.0-payroll
Translate-URL: https://translation.odoo-community.org/projects/payroll-14-0/payroll-14-0-payroll/es/
Currently translated at 100.0% (313 of 313 strings)

Translation: payroll-14.0/payroll-14.0-payroll
Translate-URL: https://translation.odoo-community.org/projects/payroll-14-0/payroll-14-0-payroll/es_AR/
[IMP] payroll: Move and refactor category sum function (now can be inherited)

[IMP] payroll: _get_payslip_lines refactoring

[IMP] payroll: move basebrowsableobject to own file

[IMP] payroll: adapt compute method to new returned values

[IMP] payroll: Add compute_date and use "verify" unused state - improve views and filters

[IMP] payroll: Add compute_date and use "verify" unused state - improve views and filters

[IMP] payroll: misc changes

[FIX] payslip_change_state: Fix tests and exeptions acording new implementation

[ADD] hr_payroll_cancel: Add mantainer keys

[IMP] payroll: Change more detailes name for lines

[IMP] all: Change repo description and contributors file.

[IMP] payroll: change order

[IMP] payroll: minor changes

[IMP] payroll: minor changes
[IMP] payroll: Add hook method for accesing localdict
Currently translated at 100.0% (315 of 315 strings)

Translation: payroll-14.0/payroll-14.0-payroll
Translate-URL: https://translation.odoo-community.org/projects/payroll-14-0/payroll-14-0-payroll/es/
Currently translated at 100.0% (315 of 315 strings)

Translation: payroll-14.0/payroll-14.0-payroll
Translate-URL: https://translation.odoo-community.org/projects/payroll-14-0/payroll-14-0-payroll/es_AR/
[FIX] payroll: fix tests

[FIX] payroll: fix tests

[IMP] payroll: Add conditional button and computed method for setting

[IMP] payroll: Add conditional button and computed method for setting

[IMP] payroll: Move cancel test to payroll account

[IMP] payroll: Add hr_payslio_cancel refund sheet code

[FIX] payroll: tests change import

[FIX] payroll: Remove account in tests, will add another test in account module

[IMP] payroll_account: Add cancel tests for accounting module

[FIX] payroll_account: Test remove

[FIX] account_payroll: Fix tests
When calling _compute_payslip_line() call it on the payslip object and
not recordset 'self'.
OCA-git-bot and others added 19 commits September 19, 2025 23:15
Currently translated at 100.0% (22 of 22 strings)

Translation: payroll-18.0/payroll-18.0-payroll_account
Translate-URL: https://translation.odoo-community.org/projects/payroll-18-0/payroll-18-0-payroll_account/es_VE/
Currently translated at 100.0% (22 of 22 strings)

Translation: payroll-18.0/payroll-18.0-payroll_account
Translate-URL: https://translation.odoo-community.org/projects/payroll-18-0/payroll-18-0-payroll_account/es/
Currently translated at 100.0% (22 of 22 strings)

Translation: payroll-18.0/payroll-18.0-payroll_account
Translate-URL: https://translation.odoo-community.org/projects/payroll-18-0/payroll-18-0-payroll_account/tr/
[IMP] payroll_account: Remove folder migrations
Signed-off-by nimarosa
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: payroll-17.0/payroll-17.0-payroll
Translate-URL: https://translation.odoo-community.org/projects/payroll-17-0/payroll-17-0-payroll/
Currently translated at 100.0% (355 of 355 strings)

Translation: payroll-17.0/payroll-17.0-payroll
Translate-URL: https://translation.odoo-community.org/projects/payroll-17-0/payroll-17-0-payroll/it/
@OCA-git-bot
Copy link
Contributor

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

if register_partner_id or acc_type in ("asset_receivable", "liability_payable"):
return register_partner_id.id
# Determine which account we're dealing with
acc_type = (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selects the correct account (credit or debit)
then safely checks the account type (account_type) — if not found, returns False to avoid an error

account = (
            self.salary_rule_id.account_credit if credit_account
            else self.salary_rule_id.account_debit
        )
        acc_type = account and account.account_type or False
        if not acc_type:
            return False

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @CristianoMafraJunior
Change applied but in different PR's (somehow I broke this one)
I appreciate it if you can do review for both 17.0 & 18.0

#226 for 18.0
#225 for 17.0

In Odoo 17.0+, the address_home_id field was removed from hr.employee
and replaced with work_contact_id. This caused journal entries to be
created without proper partner information when no register partner
was configured.

This fix implements proper partner resolution logic:
- For asset_receivable and liability_current accounts: Use employee
  partner (work_contact_id with fallback to bank_account_id.partner_id)
- For liability_payable accounts: Use register partner
- For other account types: No partner assigned

Also includes proper null checks to prevent AttributeError when
accessing .id on empty Many2one fields.

Added minimal test coverage for the new partner logic to verify
correct partner assignment for different account types.

Fixes OCA#221
@hussain hussain closed this Oct 16, 2025
@hussain hussain force-pushed the fix-payslip-line-partner-logic-issue-221 branch from 11746ee to eec5d75 Compare October 16, 2025 11:20
@hussain hussain deleted the fix-payslip-line-partner-logic-issue-221 branch October 16, 2025 11:30
@hussain hussain restored the fix-payslip-line-partner-logic-issue-221 branch October 16, 2025 11:46
@hussain hussain changed the title [FIX] payroll_account: Fix partner logic in hr_payslip_line for issue #221 [17.0][FIX] payroll_account: Fix partner logic in hr_payslip_line for issue #221 Oct 16, 2025
@hussain hussain deleted the fix-payslip-line-partner-logic-issue-221 branch October 16, 2025 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[18.0][17.0] payroll_account: partner logic for employee partner