Skip to Content
Menu
This question has been flagged
3 Replies
10253 Views

When I try to extend the view of my parent view an error: "Model not found: todo.task" raise here is my code:

my parent Model:

# -*- coding: utf-8 -*-
from odoo import models, fields, api


class TodoTask(models.Model):
_name= 'todo.task'
_description = 'To-do Task'
name= fields.Char('Description', required=True)
is_done= fields.Boolean('Done?')
active = fields.Boolean('Active?', default=True)

@api.multi
def do_toggle_done(self):
for task in self:
task.is_done= not task.is_done
return True



@api.model
def do_clear_done(self):
dones = self.search([('is_done','=',True)])
dones.write({'active':False})
return True

the extending Model:

# -*- coding: utf-8 -*-

from odoo import models, fields,api
from odoo.exceptions import ValidationError

class TodoTask(models.Model):

_inherit = 'todo.task'
user_id= fields.Many2one('res.users', 'Responsible')
date_deadline= fields.Date('Deadline')

@api.multi
def do_clear_done(self):
domain = [('is_done','=',True), '|', ('user_id', '=', self.env.uid),('user_id','=',False)]
dones= self.search(domain)
dones.write({'active': False})
return True

@api.multi
def do_toggle_done(self):
for task in self:
if task.user_id != self.env.user:
raise ValidationError(
'Only the responsible can do this !'
)
return super(TodoTask, self).do_toggle_done()

my parent view:

<odoo>

<record
id="view_form_todo_task" model="ir.ui.view">
<field
name="name"> To-do Task Form</field>
<field
name ="model">todo.task</field>
<field
name="arch" type="xml">


<form >
<header>

<button
name ="do_toggle_done" type="object"
string="Toggle Done"
class="oe_highlight" />

<button
name ="do_clear_done"
type="object"
string="Clear All Done" />

</header>

<sheet>

<group
name="group_top">

<group
name="group-left">
<field
name="name"/>
</group>

<group
name="group_right">
<field
name="is_done"/>
<field
name="active" readonly="1"/>
</group>

</group>

</sheet>
</form>


</field>

</record>


<record
id="view_tree_todo_task" model="ir.ui.view">
<field
name="name">To-do Task Tree</field>
<field
name="model">todo.task</field>
<field
name="arch" type="xml">

<tree
colors="decoration-muted:is_done==True">
<field
name="name"/>
<field
name="is_done"/>
</tree>

</field>
</record>



<record
id="view_filter_todo_task" model="ir.ui.view">
<field
name="name">To-do Task Filter</field>
<field
name="model">todo.task</field>
<field
name="arch" type="xml">

<search>
<field
name="name"/>

<filter
string="Not Done"
domain="[('is_done','=',False)]"/>

<filter
string="Done"
domain="[('is_done','!=',False)]"/>

</search>
</field>
</record>


</odoo>


the extending view:


<odoo>


<record id="view_form_todo_task_inherited"
model="ir.ui.view">

<field name="name">
Todo Task form -User extension
</field>

<field name="model">
todo.task
</field>

<field name="inherit_id"
ref="todo_app.view_form_todo_task"/>

<field name="arch" type="xml">

<field name="name" position="after">

<field name="user_id"></field>

<field name="is_done" position="before">

<field name="date_deadline"/>
</field>

<field name="active" position="attributes">
<attribute name="invisible">1</attribute>

</field>

</field>

</field>


</record>


<record id="view_tree_todo_task_inherited"
model="ir.ui.view">
<field name="name">
Todo Task tree - User extension
</field>

<field name="model">
todo.task
</field>

<field name="inherit_id"
ref="todo_app.view_tree_todo_task"/>

<field name="arch" type="xml">

<field name="name" position="after">
<field name="user_id"/>
</field>


</field>

</record>


<record id="view_filter_todo_task_inherited"
model="ir.ui.view">

<field name="name">
Todo Task tree - User extension
</field>

<field name="model">
todo.task
</field>

<field name="inherited_id"
ref="todo_app.view_filter_todo_task"/>

<field name="arch" type="xml">

<field name="name" position="after">

<field name="user_id"/>
<filter name="filter_my_tasks" string="My Tasks"
domain="[('user_id','in',[uid,False])]"/>

<filter name="filter_not_assigned" string="Not Assigned"
domain="[('user_id','=',False)]"/>

</field>



</field>



</record>



</odoo>



Avatar
Discard

Next time, I will review the date of the post before read 

Best Answer

Hi,

Are you defining the model and inheriting the model in the same module itself? if you are doing such rather than inheriting it, add it where you define the model.  Also, you can check the sequence of the python file called in the init. Make sure that first the file where you define the model will get defined.


If it is a separate module, give the module in which you have defined the model as depend for the new module in manifest file.


Thanks

Avatar
Discard
Author

Its a separated one and every thing is set in the manifest file as depends but still shows me the same error:

Model not found:

todo.task

Error context:

View `

Todo Task form -User extension

`

[view_id: 328, xml_id: n/a, model:

todo.task

, parent_id: 228]

None" while parsing /opt/odoo/odoo11/odoo11-custom-addons/todo_user/views/todo_task.xml:6, near

<record id="view_form_todo_task_inherited" model="ir.ui.view">

Related Posts Replies Views Activity
1
Mar 20
1994
1
Sep 19
3015
12
Dec 18
32539
1
Jul 16
5610
2
Mar 15
4605