Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Custom code: hr_holidays

Subscribe

Get notified when there's activity on this post

This question has been flagged
time-offv18
1 Reply
1662 Views
Avatar
huyennx

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)

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Leave days based on seniority - Time off Solved
time-off v18
Avatar
Avatar
Avatar
2
Jul 25
1064
Is it possible to sell on credit directly at the point of sale and leave the order pending payment?
v18
Avatar
Avatar
2
Sep 25
676
How to segrigate a product into multiple products & at the same time i have to manufacture that product also with separate BOM? Solved
v18
Avatar
Avatar
1
Jun 25
1828
Turkey live currency rates from TCMB
v18
Avatar
Avatar
Avatar
3
Mar 25
2917
Problem including JS asset in v18
v18
Avatar
Avatar
2
Feb 25
7875
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now