Odoo Help


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.


Problem inheriting project.view_task_form2

on 10/20/14, 2:45 AM 626 views

I'm trying to add a new field "End date" in project.task.work that would be related to 'date' (start date) and 'duration'. That seems to be ok. But when I'm customizing the view project.view_task_form2 to add my new field end_date, I got a error of type ViewError:

Can't find field 'end_date' in the following view parts composing the view of object model 'project.task':
 * project.task.form.inherit

Either you wrongly customized this view, or some modules bringing those views are not compatible with your current data model

Here is the code:

class CustomProjectWork(osv.osv):
    _name = "project.task.work"
    _inherit = "project.task.work"

    def _determin_end_date(self, cr, uid, ids, field, arg, context=None):
        result = {}
        for projectwork in self.browse(cr, uid, ids, context=context):
            if projectwork.date and projectwork.hours:
                # Get a datetime object from projectwork.date
                start_date = datetime.strptime(projectwork.date, "%Y-%m-%d %H:%M:%S")
                # Get a timedelta object from projectwork.duration
                duration = timedelta(days=(projectwork.duration - 1))
                # Calculate the end time
                end_date = start_date + duration
                # Render in format YYYY-MM-DD
                result[projectwork.id] = end_date.strftime("%Y-%m-%d %H:%M:%S")
                result[projectwork.id] = projectwork.date
                return result

    def _set_end_date(self, cr, uid, id, field, value, arg, context=None):
        projectwork = self.browse(cr, uid, id, context=context)
        if projectwork.date and value:
            start_date = datetime.strptime(projectwork.date, "%Y-%m-%d %H:%M:%S")
            end_date = datetime.strptime(value[:20], "%Y-%m-%d %H:%M:%S")
            duration = end_date - start_date
            self.write(cr, uid, id, {'duration': (duration.days + 1)}, context=context)

    _column = {
        'end_date': fields.function(_determin_end_date, fnct_inv=_set_end_date, type='datetime', string="End Date", store=True)

The view:

<record id="view_task_form2_inherit" model="ir.ui.view">
            <field name="name">project.task.form.inherit</field>
            <field name="model">project.task</field>
            <field name="inherit_id" ref="project.view_task_form2" />
            <field name="type">form</field>
            <field name="arch" type="xml">
                <field name="work_ids" position="replace">
                    <field colspan="4" name="work_ids" nolabel="1" attrs="{'readonly':[('state','in',['draft','done'])]}">
                        <tree string="Task Work" editable="top">
                            <field name="date" />
                            <field name="end_date" />
                            <field name="user_id" />
                            <field name="hours" widget="float_time" />
                            <field name="name" />

Hi Gregoire, first replace name _column to _columns and check it.

Anup Kandalkar
on 10/20/14, 5:29 AM

Working! Thanks.

on 10/20/14, 5:48 AM


The reason, why you getting this error is you have not restarted Odoo server or not updated your module.

Please restart your Odoo server and update the module in which you have written the code. Once you do this, in model class "end_date" will able to register and then in View there will be no problem.

And yes, Did you forgot to add class file in your __init__.py file ? I am sure you have forgot.

Please check everything and back to me. This is small problem and generally it comes when you are beginner. 

I have this message when I'm starting my server with an update of my module! __init__.py file contains the proper import. __openerp__.py is declaring the view in 'data' and make a dependency to 'project' into 'depends' entry.

on 10/20/14, 3:46 AM

Also, there is no error if I comment the end_date field tag.

on 10/20/14, 3:54 AM

Oh my god !!! Please write your column under "Columns" not in "Column" Do change as follows, _columns = { 'end_date': fields.function(_determin_end_date, fnct_inv=_set_end_date, type='datetime', string="End Date", store=True) } (facepalm)

Viraj Joshi
on 10/20/14, 5:22 AM

Yes, Please define your column under "_columns" , not in "_column".

Hiren Vora - CEO at Emipro Technologies Pvt. Ltd. India
on 10/20/14, 5:24 AM

Ah indeed... Thanks guys.

on 10/20/14, 5:47 AM

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

2 follower(s)


Asked: 10/20/14, 2:45 AM
Seen: 626 times
Last updated: 3/16/15, 8:10 AM