Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion payroll_account/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
"name": "Payroll Accounting",
"version": "17.0.1.0.0",
"version": "17.0.1.0.1",
"category": "Payroll",
"website": "https://github.com/OCA/payroll",
"license": "LGPL-3",
Expand Down
58 changes: 51 additions & 7 deletions payroll_account/models/hr_payslip_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,56 @@ class HrPayslipLine(models.Model):
def _get_partner_id(self, credit_account):
"""
Get partner_id of slip line to use in account_move_line

Partner is required only for specific account types that track external
relationships:
- asset_receivable: Employee loans, salary advances, overpayments to recover
→ Partner source: Employee (work_contact_id or
bank_account_id.partner_id)
- liability_payable: Third-party payables (tax authorities, insurance
companies) typically managed through contribution
registers
→ Partner source: Register partner
(salary_rule_id.register_id.partner_id)
- liability_current: Current liabilities to pay employee salaries, net pay
accruals
→ Partner source: Employee (work_contact_id or
bank_account_id.partner_id)

For other account types (expense, income, asset_current, etc.), no partner
is assigned as these represent internal accounting entries without external
party relationships.
"""
# use partner of salary rule or fallback on employee's address
register_partner_id = self.salary_rule_id.register_id.partner_id
acc_type = self.salary_rule_id.account_debit.account_type
if credit_account:
acc_type = self.salary_rule_id.account_credit.account_type
if register_partner_id or acc_type in ("asset_receivable", "liability_payable"):
return register_partner_id.id
# Determine which account we're dealing with
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

if acc_type in ("asset_receivable", "liability_current"):
# Employee-related accounts - always employee
return (
self.slip_id.employee_id.work_contact_id.id
if self.slip_id.employee_id.work_contact_id
else (
self.slip_id.employee_id.bank_account_id.partner_id.id
if self.slip_id.employee_id.bank_account_id
else False
)
)

elif acc_type == "liability_payable":
# Third-party payables - always register partner
return (
self.salary_rule_id.register_id.partner_id.id
if self.salary_rule_id.register_id
and self.salary_rule_id.register_id.partner_id
else False
)

# All other account types (expense, income, etc.)
return False
36 changes: 36 additions & 0 deletions payroll_account/tests/test_payroll_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,39 @@ def test_hr_payslip_no_accounts(self):

# I verify that the payslip is in done state.
self.assertEqual(self.hr_payslip.state, "done", "State not changed!")

def test_partner_logic_account_types(self):
"""Test partner logic for different account types."""
# Employee already has work_contact_id auto-created
employee_partner = self.hr_employee_john.work_contact_id

# Create register with different partner
register_partner = self.env["res.partner"].create({"name": "Tax Authority"})
register = self.env["hr.contribution.register"].create(
{"name": "Tax Register", "partner_id": register_partner.id}
)

# Create rule and payslip line
rule = self.env.ref("payroll.hr_salary_rule_houserentallowance1")
rule.register_id = register
payslip = self._prepare_payslip(self.hr_employee_john)
line = self.env["hr.payslip.line"].create(
{"slip_id": payslip.id, "salary_rule_id": rule.id, "name": "Test"}
)

# Test asset_receivable -> employee partner
self.account_credit.account_type = "asset_receivable"
rule.account_credit = self.account_credit
self.assertEqual(line._get_partner_id(True), employee_partner.id)

# Test liability_current -> employee partner
self.account_credit.account_type = "liability_current"
self.assertEqual(line._get_partner_id(True), employee_partner.id)

# Test liability_payable -> register partner
self.account_credit.account_type = "liability_payable"
self.assertEqual(line._get_partner_id(True), register_partner.id)

# Test other account types -> no partner
self.account_credit.account_type = "expense"
self.assertFalse(line._get_partner_id(True))