Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
764 Zobrazení

Hello everyone.

I am creating a list view to display the list of employees on leave. The fields that need to be displayed include employee_id, holiday_status_id, allocated_days, taken_leaves, remaining_balance, department_id, gender, and job_title. I have done the following:
folder report: hr_leave_balance_report.py:

from odoo import models, fields, tools

class HrLeaveBalanceReport(models.Model):

    _name = 'hr.leave.balance.report'

    _description = 'Time Off Balance Report'

    _auto = False

    employee_id = fields.Many2one('hr.employee', string='Employee', readonly=True)

    holiday_status_id = fields.Many2one('hr.leave.type', string='Leave Type', readonly=True)

    allocated_days = fields.Float(string='Allocated Days', readonly=True)

    taken_leaves = fields.Float(string='Taken Leaves', readonly=True)

    remaining_balance = fields.Float(string='Remaining Balance', readonly=True)

    department_id = fields.Many2one('hr.department', string='Department', readonly=True)

    gender = fields.Char(string="Gender", readonly=True)

    job_title = fields.Char(string="Job Title", readonly=True)


    def init(self):

        tools.drop_view_if_exists(self._cr, 'hr_leave_balance_report')


        self._cr.execute("""

            CREATE or REPLACE view hr_leave_balance_report AS (

                SELECT

                    ROW_NUMBER() OVER () AS id,

                    e.id AS employee_id,

                    e.department_id,

                    e.gender,

                    e.job_title,

                    lt.id AS holiday_status_id,

                    COALESCE(SUM(a.number_of_days), 0) AS allocated_days,

                    COALESCE(SUM(l.number_of_days), 0) AS taken_leaves,

                    COALESCE(SUM(a.number_of_days), 0) - COALESCE(SUM(l.number_of_days), 0) AS remaining_balance

                FROM hr_employee e

                CROSS JOIN hr_leave_type lt

                LEFT JOIN hr_leave_allocation a ON a.employee_id = e.id

                    AND a.holiday_status_id = lt.id

                    AND a.state = 'validate'

                LEFT JOIN hr_leave l ON l.employee_id = e.id

                    AND l.holiday_status_id = lt.id

                    AND l.state = 'validate'

                GROUP BY e.id, e.department_id, e.gender, e.job_title, lt.id

            )

        """)

<?xml version="1.0" encoding="utf-8"?>

<odoo>


    <record id="action_hr_leave_balance_report" model="ir.actions.act_window">

        <field name="name">Time Off Balance Report</field>

        <field name="res_model">hr.leave.balance.report</field>

        <field name="view_mode">list</field>

        <field name="help" type="html">

            <p class="o_view_nocontent_smiling_face">

                No Time Off data to display

            </p>

        </field>

    </record>


    <record id="view_hr_leave_balance_report_tree" model="ir.ui.view">

        <field name="name">hr.leave.balance.report.tree</field>

        <field name="model">hr.leave.balance.report</field>

        <field name="arch" type="xml">

            <list string="Time Off Balance Report">

                <field name="employee_id" />

                <field name="gender" />

                <field name="holiday_status_id" />

                <field name="allocated_days" />

                <field name="taken_leaves" />

                <field name="remaining_balance" />

                <field name="department_id" />

                <field name="job_title" />

            </list>

        </field>

    </record>


    <menuitem

        id="menu_hr_leave_balance_report"

        name="Time Off Balance Report"

        parent="hr_holidays.menu_hr_holidays_report"

        action="action_hr_leave_balance_report" />

</odoo>

but I encountered an error:

RPC_ERROR

Odoo Server Error

Occured on localhost:8069 on model hr.leave.balance.report and id 19 on 2025-05-24 10:01:48 GMT

Traceback (most recent call last):

  File "C:\odoo\Odoo18\odoo\value.id

           ^^^^^^^^

AttributeError: '_unknown' object has no attribute 'id'

The above server error caused the following client error:

OwlError: An error occured in the owl lifecycle (see this Error's "cause" property)

    Error: An error occured in the owl lifecycle (see this Error's "cause" property)

        at handleError (http://localhost:8069/web/assets/8ba1529/web.assets_web.min.js:952:101)

        at App.handleError (http://localhost:8069/web/assets/8ba1529/web.assets_web.min.js:1595:29)

        at ComponentNode.initiateRender (http://localhost:8069/web/assets/8ba1529/web.assets_web.min.js:1044:19)

Caused by: RPC_ERROR: Odoo Server Error

    RPC_ERROR

        at makeErrorFromResponse (http://localhost:8069/web/assets/8ba1529/web.assets_web.min.js:3116:163)

        at XMLHttpRequest.<anonymous> (http://localhost:8069/web/assets/8ba1529/web.assets_web.min.js:3121:13)

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
čvc 25
652
1
čvn 25
1160
3
bře 25
2106
2
úno 25
5075
1
úno 25
1873