You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Odoo 9工资单详情字段重复显示问题及修改咨询

Hey there! Let's fix that duplicate category issue in your Odoo 9 payslip details report. I've run into this exact problem before, so here's a step-by-step solution:

Why This Happens

The duplicate code, rule_category, and total fields are showing up because your report is looping through every individual salary rule line instead of grouping them by their salary rule category. Each line in the same category repeats the category info, hence the duplicates.

Step 1: Adjust the Report Data Source (Python File)

First, we need to modify report_payslip_details.py to group salary lines by their category and calculate the total per category. Replace your _get_report_values method with this:

def _get_report_values(self, docids, data=None):
    docs = self.env['hr.payslip'].browse(docids)
    category_groups = {}
    
    for payslip in docs:
        category_groups[payslip.id] = {}
        for line in payslip.line_ids:
            category = line.category_id
            # Initialize category entry if it doesn't exist
            if category not in category_groups[payslip.id]:
                category_groups[payslip.id][category] = {
                    'code': category.code,
                    'name': category.name,
                    'lines': [],
                    'total': 0.0
                }
            # Add the line to the category and update total
            category_groups[payslip.id][category]['lines'].append(line)
            category_groups[payslip.id][category]['total'] += line.total
    
    return {
        'doc_ids': docids,
        'doc_model': 'hr.payslip',
        'docs': docs,
        'category_groups': category_groups,
    }

This code aggregates all salary lines under their respective categories and computes the total for each category, so we have one entry per category (Base, Brut, Net, etc.).

Step 2: Update the Report Template (XML File)

Now modify report_payslipdetails.xml to loop through our grouped categories instead of individual lines. Replace the section where you're displaying the category details with this:

<!-- Replace your existing category/rule loop with this -->
<t t-foreach="category_groups[doc.id].values()" t-as="category">
    <!-- Category header row (shows once per category) -->
    <tr>
        <td><strong><span t-esc="category['code']"/></strong></td>
        <td><strong><span t-esc="category['name']"/></strong></td>
        <td><strong><span t-esc="category['total']"/></strong></td>
    </tr>
    <!-- Optional: Show individual rules under the category -->
    <t t-foreach="category['lines']" t-as="line">
        <tr style="padding-left: 20px;">
            <td><span t-esc="line.code"/></td>
            <td><span t-esc="line.name"/></td>
            <td><span t-esc="line.total"/></td>
        </tr>
    </t>
</t>

This will display each category (Base, Brut, Net) once, followed by all the individual salary rules under that category (if you choose to include them). If you don't need the individual rules, just remove the inner <t t-foreach> block.

Step 3: Apply Changes & Test

  1. Restart your Odoo server to load the updated Python code.
  2. Go to Settings > Modules > Update Apps List, then find your payroll module and click Update to apply the XML changes.
  3. Clear your browser cache (or use incognito mode) to make sure the old report template isn't cached.
  4. Generate a payslip report again—your categories should now only show once!

Quick Troubleshooting

  • If you still see duplicates, double-check that your salary rules are correctly assigned to their categories in Odoo (under Payroll > Configuration > Salary Rules).
  • Make sure you're referencing the right fields: category_id is the correct relation between hr.payslip.line and hr.salary.rule.category in Odoo 9.

内容的提问来源于stack exchange,提问作者Dhouha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:27:35