This question has been flagged
3 Replies
5290 Views

I am trying to add a boolean field to hr_holiday that should enable me to not count weekends on leaves when checked.

I get the following error:

ParseError: "Invalid view definition

Error details:

Field `weekend_exclude` does not exist

Error context:

View `excluding.days.leaves`

[view_id: 700, xml_id: n/a, model: hr.holidays, parent_id: n/a] ...

weekend_leaves_view.xml

<?xml version="1.0" encoding="UTF-8"?> 
<openerp>
 <data>
 <record model="ir.ui.view" id="excluding_days_leaves">
 <field name="name">excluding.days.leaves</field>
 <field name="model">hr.holidays</field>
 <field name="arch" type="xml">
 <form string="Session Form">
 <sheet>
 <group>
 <group string="Weekend Leave">
 <field name='weekend_exclude'/>
 </group>
 </group>
 </sheet>
 </form>
 </field>
 </record>
 <record model="ir.actions.act_window" id="excluding_days_leaves_action">
 <field name="name">Excluding days</field>
 <field name="res_model">hr.holidays</field>
 <field name="view_type">form</field>
 <field name="view_mode">form</field>
 </record>
 <record model="ir.actions.act_window.view" id="excluding_days_leaves_action_form">
 <field name="view_mode">form</field>
 <field name="view_id" ref="excluding_days_leaves"/>
 <field name="act_window_id" ref="excluding_days_leaves_action"/>
 </record>
 <menuitem id="excluding_days_leaves_menuitem" name="Excluding days" parent="hr_holidays.menu_hr_holidays_root" action="excluding_days_leaves_action"/>
 </data>
</openerp>

model.py

from openerp.osv import fields, orm
import datetime
class nites_weekend_leaves(orm.Model):
 _inherit = 'hr.holidays'
 weekend_exclude=fields.boolean('Weekend')
 def _get_number_of_days(self, date_from, date_to): """Returns a float equals to the timedelta between two dates given as string."""
 DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S" from_dt = datetime.datetime.strptime(date_from, DATETIME_FORMAT)
 to_dt = datetime.datetime.strptime(date_to, DATETIME_FORMAT)
timedelta = to_dt - from_dt
 weekend_days=0
 if self.weekend_exclude:
while from_dt < to_dt:
  if from_dt.weekday()==5 or from_dt.weekday()==6: #count how many saturdays and sundays
  weekend_days += 1
  from_dt=from_dt+datetime.timedelta(days=1)
 diff_day = timedelta.days - weekend_days + float(timedelta.seconds) / 86400
return diff_day
Avatar
Discard

Have you updated your Python code with a -u yourModuleName

Best Answer

Milos,

Make sure you have imported the py file in __init__.py

Avatar
Discard
Best Answer

eekend_exclude=fields.boolean('Weekend')


the new api start with a capital lettre

eekend_exclude=fields.Boolean('Weekend')

Avatar
Discard