2017-02-21 8 views
0

odoo 10に棒グラフ(グラフビュー)を作成して、各コースで勉強している生徒の数を表示できます。このpythonデータベースを使って、私はどのように実装できますか?このタイプのビューに関するサンプルコードはインターネット上にありません。odoo 10.0でチャートを作成する

class Student(models.Model): 
    _name = "studentmanagement.student" 

    id= fields.Char(required=True, index=True) 
    full_name= fields.Char(required=True, index=True) 
    gender = fields.Char() 
    birthday = fields.Char(required=True) 
    address = fields.Char(required=True) 
    course_inscription = fields.Many2many('studentmanagement.course',string = 'inscription') 
    _sql_constraints = [('id_unique', 'UNIQUE(id)', 'Two students can not have the same ID!')] 


class course(models.Model): 
    _name = "studentmanagement.course" 

    code = fields.Char(required=True, index=True) 
    course_name = fields.Char(required=True, index=True) 
    credits = fields.Integer(required=True) 
    nstudent= fields.Integer(compute='_compute_percentage_students_course', store=True) 
    _sql_constraints = [('code_unique', 'UNIQUE(code)', 'Two courses can not have the same ID!')] 

    @api.depends('percentage','course_inscription') 
    def _compute_percentage_students_course(self): 
     for record in self: 
      record.nstudent = len(record.course_inscription) 

ありがとうございました!

答えて

1

これはグラフ図である。

<graph string="Sales Orders"> 
        <field name="partner_id"/> 
        <field name="amount_total" type="measure"/> 
</graph> 

グラフ図は、2つのフィールドを有すること。チャートのタイプによっては、それに応じてレンダリングされます。 (計算結果を確認し、あなたがpercentageフィールドの値になるように計算を計算して設定することを_compute_percentage_students_course

percentage = fields.Float(compute='_compute_percentage_students_course' store=True)

:あなたが好きな計算されたパーセンテージを保持するだろうフィールドを作成する必要があり

計算フィールドを正しく作成する方法については、documentationのフィールドセクションを参照してください)

documentationまた、グラフの作成方法、作成可能なグラフの種類などを示すグラフビューを確認してください。T彼は以下のあなたのために働く必要があります。

<graph string="Sales Orders"> 
         <field name="full_name"/> 
         <field name="percentage" type="measure"/> 
    </graph> 
+0

デフ_compute_percentage_students_course(自己):自己におけるRの : nostudent = LEN(r.course_inscription) r.percentage = nostudent/100それは動作しません、他のビューにもちろん、フォームのすべてのperceantagesは0です! –

+0

そのコードが動作しない理由はわかりません! –

+1

計算されたフィールドが保存されている場合、グラフビューが機能します。だから、計算されたフィールドの定義に 'store = True'を入れてください。 –

関連する問題