I made 2 models and try to make relationships between them but hr table work fine and my student table won't show.
This how form looks:
https://ibb.co/dP4GmJ
This how hr shows:
https://ibb.co/fZ7afd
This how students shows (this is problem), no select student table?
https://ibb.co/cVFYYy
When i change relationship student_ids to many2many everything works well but i wanna one2many.
This is my code:
Also i am set 'depends': ['base', 'hr', 'students',], in study_room __openerp__.py
#student model
from openerp import models, fields, api
class students(models.Model):
_name = 'students.students'
name = fields.Char(string='First Name', required=True)
last_name = fields.Char(string='Last Name', required=True)
email = fields.Char(string='Email', required=True)
phone = fields.Char(string='Phone')
gender = fields.Selection([('m', 'Male'), ('f', 'Female')], string='Gender', default='m')
is_active = fields.Boolean(string='Active', default=True)
birth_date = fields.Date(string='Birth Date', default=fields.Date.today())
room_id = fields.Many2one(comodel_name="study.room", string="Study Room", )
_sql_constraints = [
('unique_email', 'unique(email)', 'User with that email already exist!')
]
#study room model
class study_room(models.Model):
_name = 'study.room'
@api.one
@api.depends('student_ids')
def _get_no_of_students(self):
self.no_of_students = len(self.student_ids)
name = fields.Char(string="Name")
teacher_ids = fields.Many2many(string="Teachers", comodel_name="hr.employee", relation="room_teacher_rel",
column1="room_id", column2="teacher_id")
student_ids = fields.One2many(string="Students", comodel_name="students.students", inverse_name="room_id")
no_of_students = fields.Integer(string="No. of Students", compute="_get_no_of_students")
#student view
<openerp>
<data>
<record id="student_form_view" model="ir.ui.view">
<field name="name">Student Form View</field>
<field name="model">students.students</field>
<field name="arch" type="xml">
<form string="Students">
<sheet>
<group>
<field name="name"/>
<field name="last_name"/>
<field name="email"/>
<field name="phone"/>
<field name="gender"/>
<field name="is_active"/>
<field name="birth_date"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="student_tree_view" model="ir.ui.view">
<field name="name">Student Tree View</field>
<field name="model">students.students</field>
<field name="arch" type="xml">
<tree string="Students">
<field name="name"/>
<field name="last_name"/>
<field name="birth_date"/>
</tree>
</field>
</record>
<record id="students_students_action" model="ir.actions.act_window">
<field name="name">Students</field>
<field name="res_model">students.students</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="School Management" id="school_man_menu" sequence="85"/>
<menuitem name="Students" id="school_students_menu" sequence="10" parent="school_man_menu"/>
<menuitem name="Student Info" id="schools_info" sequence="10" parent="school_students_menu" action="students_students_action"/>
</data>
</openerp>
#study room view
<openerp>
<data>
<menuitem name="Study Room" parent="students.school_man_menu" id="study_room_categ"/>
<record id="study_room_form" model="ir.ui.view">
<field name="name">Study Room Form</field>
<field name="model">study.room</field>
<field name="arch" type="xml">
<form string="Study Room">
<sheet>
<group>
<field name="name"/>
<field name="no_of_students"/>
</group>
<notebook>
<page string="Students">
<field name="student_ids"/>
</page>
<page string="Teachers">
<field name="teacher_ids"/>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record id="study_room_tree" model="ir.ui.view">
<field name="name">Study Room Tree View</field>
<field name="model">study.room</field>
<field name="arch" type="xml">
<tree string="Study Room">
<field name="name"/>
<field name="no_of_students"/>
</tree>
</field>
</record>
<record id="study_room_action" model="ir.actions.act_window">
<field name="name">Study Room</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">study.room</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click Here to create study rooms
</p>
</field>
</record>
<menuitem name="Study Room" parent="study_room_categ" id="study_room_act" action="study_room_action"/>
</data>
</openerp>