4

I want to inherit the Odoo 11 module "hr.holiday" calendar views and then insert the public holidays into the calendar.

For now I have the model as below for public holiday:

class PublicHoliday(models.Model):
    _name = 'hr.public.holiday'
    _description = 'Public Holidays'

    name = fields.Char(string='Holiday Name', compute="_compute_name", required=True)
    year = fields.Integer(
    "Calendar Year",
    required=True,
    default=datetime.now().year
)
    holiday_ids = fields.One2many('hr.public.holiday.holidays', 'year_id', 'Holidays')
    # company_id = fields.Many2one('res.company', 'Company')



class HrPublicHolidayHolidays(models.Model):
    _name = 'hr.public.holiday.holidays'
    _description = 'Public Holidays Dates'

    name = fields.Char('Holiday Name', required=True)
    date = fields.Date('Holiday Date', required=True)
    date_day = fields.Char('Day')
    year_id = fields.Many2one('hr.public.holiday', 'Calendar Year', required=True)
    variable = fields.Boolean('Date may change')

The code above worked fine, and below is an example public holiday list i've inserted: enter image description here

Then for now i want to add the public holidays in the list as picture above into the calendar view that provided by odoo own hr.holiday module, E.g 3 Aug 2018 is holiday, so the calendar would show that 3 Aug 2018 is a public holiday, and then write the public holiday name in 3 Aug 2018. And the calendar view are:enter image description here

I have tried to inherit and then insert the holidays inside by using xpath, and the code are :

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!-- Insert Public Holidays into Leave Calendar-->
<record id="view_holiday_new_calendar_inherit" model="ir.ui.view">
    <field name="name">hr.holiday.calendar.inherit</field>
    <field name="model">hr.public.holiday.holidays</field>
    <field name="inherit_id" ref="hr_holidays.view_holiday_new_calendar" />
    <field name="arch" type="xml">
        <xpath expr="/calendar" position="after">
            <calendar string="Public Holidays" date_start="date" date_stop="date" mode="month" quick_add="False" color="date">
                <field name="name"/>
            </calendar>
        </xpath>
    </field>
</record>

But this doesn't work and thrown error, and i didn't know is there a ways to insert the holiday to the calendar view. So can somebody help me out? Or tell me either this is possible or not, if not, is there any other ways to achieve this?

Thanks in advance.

1 Answers1

0

Check how module achieves this functionality in v10, you need to see hr_public_holidays/static/src/js/holidays_highlighter.js and hr_public_holidays/templates/assets.xml. Note that here hr_public_holidays/data/ir_config_parameter.xml pre-load default color to highlight in calendar view. Note to that module's name is 'hr_public_holidays' not 'hr_holidays_public' as in v11.

Alien
  • 15,141
  • 6
  • 37
  • 57