İçereği Atla
Menü
This question has been flagged
1 Cevapla
139 Görünümler

I'm using Odoo 17 and would like to know how I can configure the system so that when I generate a payslip batch containing multiple payslips (e.g., 3 payslips for 3 employees), the system creates only one journal entry that consolidates all the components from each payslip.

Example:

Each payslip contains components such as:

  • Basic Salary
  • Health Allowance
  • General Allowance
  • Net Salary

These components come from salary rules defined in each employee’s salary structure.

What I want is:

When the payslip batch is confirmed, it should generate a single journal entry with lines like:

  • Basic Salary (sum of all 3 payslips)
  • Health Allowance (sum of all 3 payslips)
  • General Allowance (sum of all 3 payslips)
  • Net Salary (sum of all 3 payslips)

And of course, the journal entry must be balanced.

Is this possible with the default configuration in Odoo 17? If not, is there a specific setting or would it require a customization in the hr_payroll_community module?

Thanks in advance! Let me know if anything is unclear.

Avatar
Vazgeç
Best Answer

No, Odoo 17 Community does not support combining payslips into a single journal entry out of the box.

You must customize the hr_payroll_community module to override the accounting logic in payslip batches.


1. Custom Module Structure

  • Make sure you have a custom module (e.g., hr_payroll_batch_entry), and add this in models/hr_payslip_run.py
from odoo import models, api
from collections import defaultdict

class HrPayslipRun(models.Model):
    _inherit = 'hr.payslip.run'

    @api.model
    def _create_batch_account_move(self, payslips):
        if not payslips:
            return

        journal = payslips[0].journal_id
        move_lines_dict = defaultdict(lambda: {'debit': 0.0, 'credit': 0.0, 'name': '', 'account_id': False})

        for slip in payslips:
            slip_lines = slip._prepare_payslip_lines()
            for line in slip_lines:
                key = line['account_id']
                if key:
                    move_line = move_lines_dict[key]
                    move_line['debit'] += line['debit']
                    move_line['credit'] += line['credit']
                    move_line['name'] = line['name']
                    move_line['account_id'] = key

        line_vals = [(0, 0, vals) for vals in move_lines_dict.values()]

        move = self.env['account.move'].create({
            'ref': self.name,
            'journal_id': journal.id,
            'line_ids': line_vals,
            'date': self.date_end or fields.Date.today(),
        })
        move.post()

        for slip in payslips:
            slip.write({'move_id': move.id, 'state': 'done'})

        return move

    def action_validate(self):
        for batch in self:
            payslips = batch.slip_ids.filtered(lambda p: p.state == 'draft')
            payslips.compute_sheet()

            # Instead of creating per payslip move, call the new combined method
            self._create_batch_account_move(payslips)

        return super(HrPayslipRun, self).action_validate()


Add _prepare_payslip_lines() to Slip (If Not Exists)

  • If it's not already defined in hr.payslip, add this helper to extract move lines from payslips:

class HrPayslip(models.Model):

    _inherit = 'hr.payslip'


    def _prepare_payslip_lines(self):

        lines = []

        for line in self.line_ids:

            if not line.salary_rule_id.account_debit or not line.salary_rule_id.account_credit:

                continue


            if line.total > 0:

                lines.append({

                    'name': line.name,

                    'account_id': line.salary_rule_id.account_credit.id,

                    'debit': -line.total,

                    'credit': 0.0,

                })

        return lines


Notes:

  • Make sure your salary rules have correct debit/credit accounts.
  • This will replace individual entries with a single journal entry for the entire batch.
  • You may enhance it to log the link between payslips and the batch move if needed.


Thanks & Regards,

Email :-  contact@datainteger.com

Avatar
Vazgeç
Related Posts Cevaplar Görünümler Aktivite
0
Mar 25
531
0
Şub 25
310
0
Eki 24
552
3
May 24
4041
0
Nis 22
1620