Hello, odoo devs,
I'm trying to learn inheritance using ODOO 11, I built a simple module that displays TODO-List, after that, i developed another module that is responsible for adding new fields on the first module view (form & view) using inheritance mechanism. The problem the new fields do not show after installing the second module.
Any help, please ?
The first module python & XML files :
# -*- coding: utf-8 -*-
from odoo import models, fields, api
import logging
_logger = logging.getLogger(__name__)
class TodoTask(models.Model):
_name = 'todo.task'
name = fields.Char("name", required=True)
active = fields.Boolean("Is active ?", default=True)
is_done = fields.Boolean("Is done ?")
@api.multi
def do_toggle_done(self):
for task in self:
task.is_done = not task.is_done
log_data = str(task.name) + (" is done" if task.is_done else " not done yet")
self.show_log(log_data)
return True
@api.multi
def do_clear_done(self):
dones = self.search([('is_done', '=', 'True')])
dones.write({'active': False})
return True
@api.model
def show_log(self, log_data):
_logger.critical(str(log_data))jdf
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!--Task form view-->
<record model="ir.ui.view" id="view_form_todo_task">
<field name="name">Todo tasks form</field>
<field name="model">todo.task</field>
<field name="arch" type="xml">
<form string="Todo Task">
<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_task_info_top">
<field name="name" placeholder="Task's description" required="True"/>
<group name="group_task_info_right">
<field name="is_done"/>
</group>
<group name='group_task_info_left'>
<field name="active" readonly="1"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
<!--Task tree view-->
<record model="ir.ui.view" id="view_tree_todo_task">
<field name="name">Todo tasks list</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>
<!--Task Search view-->
<record model="ir.ui.view" id="view_search_todo_task">
<field name="name">Todo tasks search</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','=',True)]"/>
</search>
</field>
</record>
</data>
</odoo>
The second module python & XML files:
# -*- coding: utf-8 -*-
from odoo import models, fields, api
from odoo.exceptions import ValidationError
class TodoTask(models.Model):
_inherit = 'todo.task'
# Adding new filed
user = fields.Many2one('res.users', string='Responsible')
deadline = fields.Date("Deadline")
# Modifying existing fields
name = fields.Char(help="What needs to be done ?")
# Overriding methods
@api.multi
def do_clear_done(self):
dones = self.search\
([
('is_done', '=', True),
'|',
('user', '=', self.env.uid),
('user', '=', False)
])
for done in dones:
done.write({'active': False})
return True
@api.multi
def do_toggle_done(self):
for task in self:
if task.user != self.env.uid:
raise ValidationError('Only the responsible van do this !')
return super(TodoTask, self).do_toggle_done()
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="view_form_todo_task_extension" model="ir.ui.view">
<field name="name">Todo Form 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' postion="after">
<field name="deadline"/>
</field>
<field name='active' postion="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name='active' postion="before">
<field name="user"/>
</field>
</field>
</record>
<record id="view_tree_todo_task_extension" model="ir.ui.view">
<field name="name">Todo Tree 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' postion="after">
<field name="deadline"/>
<field name="user"/>
</field>
</field>
</record>
<record id="view_search_todo_task_extension" model="ir.ui.view">
<field name="name">Todo Search Extension</field>
<field name="model">todo.task</field>
<field name="inherit_id" ref="todo_app.view_search_todo_task"/>
<field name="arch" type="xml">
<field name='name' postion="after">
<field name="user"/>
<filter string="All" domain="[('user','in',[uid,False])]"/>
<filter string="My tasks" domain="[('user','in',uid)]"/>
<filter string="Not Assigned" domain="[('user','=',False)]"/>
</field>
</field>
</record>
</data>
</odoo>
do you use the default created files or do you use own named files. If you use own don't forget to add them to __manifest__.py and models/__init__.py. If you have 2 different custom modules don't forget on the second to add the 1st custom module to depends in __manifest__.py.
Odoo will use his own view if you don't define your custom view. Where are actions and menu items in your views?
I check that, and I think that I did it correctly