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)
ありがとうございました!
デフ_compute_percentage_students_course(自己):自己におけるRの : nostudent = LEN(r.course_inscription) r.percentage = nostudent/100それは動作しません、他のビューにもちろん、フォームのすべてのperceantagesは0です! –
そのコードが動作しない理由はわかりません! –
計算されたフィールドが保存されている場合、グラフビューが機能します。だから、計算されたフィールドの定義に 'store = True'を入れてください。 –