Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
13 ตอบกลับ
2587 มุมมอง

In my student management system when I am saving my subject name it is stored as record numbers 1,2,3,----instead of subjectname getting saved in Odoo12 Community Version

My Model is:-

from odoo import models,fields,api


class StudentSubject(models.Model):
    _name = 'student.subject'
   
    name= fields.Char(string='Subject Name', required=True)

class StudentBranch(models.Model):
    _name = 'student.branch'
    _rec_name = 'subname'

    name= fields.Char(string='BranchName', required=True)
    branchcode= fields.Integer(string='Branch Code')
    subname= fields.One2many('student.subject','name',string='Subject Name')       
    My View :-

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<!--Branch Generic View -->
<record id="studentbranch_menu_action" model="ir.actions.act_window">
            <field name="name">Branch</field>
            <field name="res_model">student.branch</field>
            <field name="view_type">form</field>
            <field name="view_mode">kanban,tree,form</field>
            <field name="domain">[]</field>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">Create The First Branch
                </p>
            </field>
</record>
<!-- Tree View of branch -->
<record  id="view_tree_studentbranch"  model="ir.ui.view"> 
            <field  name="name">Branch</field> 
            <field  name="model">student.branch</field> 
            <field  name="arch"  type="xml"> 
                <tree>
                    <field  name="branchcode"/>
                    <field  name="name"/> 
                    <field  name="subname" mode='tree'/> 
                </tree> 
            </field> 
        </record>
<!-- Subjects Generic View -->
<record id="studentsubject_menu_action" model="ir.actions.act_window">
            <field name="name">Subjects</field>
            <field name="res_model">student.subject</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="domain">[]</field>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">Create The First Subject
                </p>
            </field>
</record>
<!-- Tree View of Subject -->
<record  id="view_tree_studentsubject"  model="ir.ui.view"> 
            <field  name="name">SubjectsSubject</field> 
            <field  name="model">student.subject</field> 
            <field  name="arch"  type="xml"> 
                <tree> 
                    <field  name="name"/>
                </tree> 
            </field> 
        </record>
<!-- Kanban View of Branch -->
<record id="studentbranch_kanban_view" model="ir.ui.view">
            <field name="name">StudentBranch Kanban</field>
            <field name="model">student.branch</field>
            <field name="arch" type="xml">
                <kanban>
                  
                    <templates>
                        <t t-name="kanban-box">
                            <div class="oe_kanban_global_click">
                                <div class="oe_kanban_details">
                                <ul>
                                    <li><field name="name"/></li>
                                 </ul> 
                                </div>
                            </div>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>


<menuitem id="school_studentsubject_menu"
                  parent="school_menu"
                  name="Branch" sequence="3"/>
<menuitem id="school_studentbranch_details_menu"
            parent="school_studentsubject_menu"
            name="Branchs"
                  action="studentbranch_menu_action"/>
<menuitem id="school_studentsubject_details_menu"
            parent="school_studentsubject_menu"
            name="Subjects"
                  action="studentsubject_menu_action"/> 
</data>
</odoo>

Please Help....

Thanks in Advance...

อวตาร
ละทิ้ง

Please use concise and meaningful titles. It will also help you to really identify your problems.

ผู้เขียน

Okay...Thanks...

คำตอบที่ดีที่สุด

hello

in your code one2many fields relation is with Character type field.

from odoo import models,fields,api


class StudentSubject(models.Model):
    _name = 'student.subject'
    
    name= fields.Char(string='Subject Name', required=True)

class StudentBranch(models.Model):
    _name = 'student.branch'
    _rec_name = 'subname'

    name= fields.Char(string='BranchName', required=True)
    branchcode= fields.Integer(string='Branch Code')
    subname= fields.One2many('student.subject','name',string='Subject Name')     


# here the inverse_name field is name field and that must be many2one field while in your it is character field. for that add new field for make the relationship between two table.

second thing is you give the _rec_name = 'subname' which is one2many field. please give the field name which is not one2many or many2many field.


   

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

_name = 'student.subject'
 name= fields.Char(string='Subject Name', required=True)
Here required Many2one field of (student.branch) in this model.

Example:
_name = 'student.subject'
 name= fields.Char(string='Subject Name', required=True)

branch_id = fields.Many2one("student.branch","Branch")


subname= fields.One2many('student.subject','name',string='Subject Name')
name ---> Here we used Many2one field for define One2many field.

This branch_id is add in One2many field that you have created.

Example:
subname= fields.One2many('student.subject','branch_id',string='Subject Name')       

Please Try above code.


อวตาร
ละทิ้ง
ผู้เขียน

Not displaying properly..I have given the model like this

class StudentSubject(models.Model):

_name = 'student.subject'

#name=fields.Char(string='Subject Name',required=True)

name= fields.Char(string='Subject Name', required=True)

branch_id = fields.Many2one("student.branch","Branch")

class StudentBranch(models.Model):

_name = 'student.branch'

name= fields.Char(string='BranchName', required=True)

branchcode= fields.Integer(string='Branch Code')

subname= fields.One2many('student.subject','branch_id',string='Subject Name')

And my View is :-

<!--Branch Generic View -->

<record id="studentbranch_menu_action" model="ir.actions.act_window">

<field name="name">Branch</field>

<field name="res_model">student.branch</field>

<field name="view_type">form</field>

<field name="view_mode">kanban,tree,form</field>

<field name="domain">[]</field>

<field name="help" type="html">

<p class="oe_view_nocontent_create">Create The First Branch

</p>

</field>

</record>

<!-- Tree View of branch -->

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

<field name="name">Branch</field>

<field name="model">student.branch</field>

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

<tree>

<field name="branchcode"/>

<field name="name"/>

<field name="subname" mode='tree'/>

</tree>

</field>

</record>

<!-- Subjects Generic View -->

<record id="studentsubject_menu_action" model="ir.actions.act_window">

<field name="name">Subjects</field>

<field name="res_model">student.subject</field>

<field name="view_type">form</field>

<field name="view_mode">tree,form</field>

<field name="domain">[]</field>

<field name="help" type="html">

<p class="oe_view_nocontent_create">Create The First Subject

</p>

</field>

</record>

<!-- Tree View of Subject -->

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

<field name="name">SubjectsSubject</field>

<field name="model">student.subject</field>

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

<tree>

<field name="name"/>

</tree>

</field>

</record>

<!-- Kanban View of Branch -->

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

<field name="name">StudentBranch Kanban</field>

<field name="model">student.branch</field>

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

<kanban>

<templates>

<t t-name="kanban-box">

<div class="oe_kanban_global_click">

<div class="oe_kanban_details">

<ul>

<li><field name="name"/></li>

</ul>

</div>

</div>

</t>

</templates>

</kanban>

</field>

</record>

ผู้เขียน

In subject Name, Add a Line

If we give Add a Line..It displays Subject name and branch...In branch it is dsplayed in dropdown

Please explain your purpose to use this.

On Fri, Jan 4, 2019, 5:03 PM aswathy.ps@confianzit.biz <aswathy.ps@confianzit.biz wrote:

In subject Name, Add a Line

If we give Add a Line..It displays Subject name and branch...In branch it is dsplayed in dropdown

Sent by Odoo S.A. using Odoo.

ผู้เขียน

In dropdown of branch,it shows the option of create branch ,not the branch listing ....

My idea is to create a Branch,with branchname ,branchcode,and Subjects related to that branch by using Add a Line..But in Add a Line its showing subject name and branch.in branch dropdown it shows again the branch form itself...

ผู้เขียน

In dropdown of branch,it shows the option of create branch ,not the branch listing ....

My idea is to create a Branch,with branchname ,branchcode,and Subjects related to that branch by using Add a Line..But in Add a Line its showing subject name and branch.in branch dropdown it shows again the branch form itself...

ผู้เขียน

I just need the subjectname only in it

ผู้เขียน

I got it

class StudentSubject(models.Model):

_name = 'student.subject'

name=fields.Char(string='Subject Name',required=True)

branch_id =fields.Many2one("student.branch",string="Branch",index=True,readonly="1")

#Model of Branch

class StudentBranch(models.Model):

_name = 'student.branch'

_rec_name = 'branchname'

branchname= fields.Char(string='BranchName', required=True)

branchcode= fields.Integer(string='Branch Code')

subname= fields.One2many('student.subject','branch_id',string='Subject Name')

My view is:-

<record id="studentbranch_menu_action" model="ir.actions.act_window">

<field name="name">Branch</field>

<field name="res_model">student.branch</field>

<field name="view_type">form</field>

<field name="view_mode">kanban,tree,form</field>

<field name="domain">[]</field>

<field name="help" type="html">

<p class="oe_view_nocontent_create">Create The First Branch

</p>

</field>

</record>

<!-- Tree View of branch -->

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

<field name="name">Branch.tree</field>

<field name="model">student.branch</field>

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

<field name="branchname"/>

<field name="branchcode"/>

<tree string="Branch Tree">

<field name="subname"/>

</tree>

</field>

</record>

<!-- Subjects Generic View -->

<record id="studentsubject_menu_action" model="ir.actions.act_window">

<field name="name">Subjects</field>

<field name="res_model">student.subject</field>

<field name="view_type">form</field>

<field name="view_mode">tree,form</field>

<field name="domain">[]</field>

<field name="help" type="html">

<p class="oe_view_nocontent_create">Create The First Subject

</p>

</field>

</record>

<!-- Tree View of Subject -->

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

<field name="name">SubjectsSubject</field>

<field name="model">student.subject</field>

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

<tree string="Subject Tree">

<field name="name"/>

<field name="branch_id"/>

</tree>

</field>

</record>

<!-- Kanban View of Branch -->

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

<field name="name">StudentBranch Kanban</field>

<field name="model">student.branch</field>

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

<kanban>

<templates>

<t t-name="kanban-box">

<div class="oe_kanban_global_click">

<div class="oe_kanban_details">

<ul>

<li><field name="branchname"/></li>

<li><field name="branchcode"/></li>

</ul>

</div>

</div>

</t>

</templates>

</kanban>

</field>

</record>

คำตอบที่ดีที่สุด

Hello Aswathy,

Please try with _order it will work 100%


class StudentSubject(models.Model):
    _name = 'student.subject'
    _order = 'name'

    name= fields.Char(string='Subject Name', required=True)

class StudentBranch(models.Model):
    _name = 'student.branch'
    _rec_name = 'subname'
    _order = 'subname'

อวตาร
ละทิ้ง
ผู้เขียน

Not Working

you have to restart and upgrade the module,

ผู้เขียน

I have done its not the issue .Here required Many2one field of (student.branch) in this model.