Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Field does not exist error [Odoo 9.0]

By
Milos
on 7/22/16, 7:25 AM 568 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

Have you updated your Python code with a -u yourModuleName

Yenthe
on 7/22/16, 9:50 AM
0
tchigy
On 7/22/16, 4:05 PM

eekend_exclude=fields.boolean('Weekend')


the new api start with a capital lettre

eekend_exclude=fields.Boolean('Weekend')

0

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 7/22/16, 2:36 PM

Milos,

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/22/16, 7:25 AM
Seen: 568 times
Last updated: 7/22/16, 4:05 PM