我正在修改 Odoo OpenEduCat 考试模块以满足我机构的需要。为此,我已经定制了如下所示的代码。但是,当我单击生成按钮时,odoo 会引发预期的单例错误。生成按钮 错误详情
--Python代码--
from openerp import models, fields, api
class OpResultTemplate(models.Model):
_name = 'op.result.template'
_description = 'Result Template'
_rec_name = 'name'
exam_session_id = fields.Many2one(
'op.exam.session', 'Exam Session', related='line_ids.exam_session_id', required=False)
name = fields.Char("Name", size=254, required=True)
result_date = fields.Date(
'Result Date', required=True, default=fields.Date.today())
line_ids = fields.One2many(
'op.result.template.line', 'result_id', 'Session Lines')
####this is for semester
inter1_ids = fields.One2many(
'op.internal1', 'result_id', 'Internal 01')
inter2_ids = fields.One2many(
'op.internal2', 'result_id', 'Internal 02')
model_ids = fields.One2many(
'op.model', 'result_id', 'Model')
final_ids = fields.One2many(
'op.final', 'result_id', 'Semester')
state = fields.Selection(
[('normal', 'Normal'), ('semester', 'Semester')],
string='State', required=True, default='normal')
# pass_status_ids = fields.Many2many('op.pass.status', string='Pass Status')
@api.one
def generate_result(self):
data = self.read(['state'])[0]
if data['state'] == 'normal' :
####Write information in to Marksheet Register the place where result generate to.
marksheet_reg_id = self.env['op.marksheet.register'].create({
'name': 'Mark Sheet for %s' % self.line_ids.exam_session_id.name,
'exam_session_id': self.line_ids.exam_session_id.id,
'generated_date': fields.Date.today(),
'generated_by': self.env.uid,
'status': 'draft',
'course_id': self.line_ids.exam_session_id.course_id.name,
'batch_id': self.line_ids.exam_session_id.batch_id.name,
'exam_type': self.line_ids.exam_session_id.exam_type.name,
'semester_id': self.line_ids.exam_session_id.semester_id.name,
})
student_list = []####Define array to store
for exam_session in self.line_ids:####line_ids is table that located in Result generator which allow to choose exam session
total_exam = 0.0#global var
for exam in exam_session.exam_session_id:####exam_session.exam_lines is the table that list the exam or subject located in Result generator->Exam session
total_exam += exam.exam_ids.total_marks
for attd in exam.exam_ids.attendees_line:####exam.exam_id.attendees_line location that contant student name and mark in each subject
result_dict = {####this loop is to write information to result line
'exam_id': exam.exam_ids.id,
'exam_tmpl_id': exam.exam_ids.id,
'marks': attd.marks,####IMPORTANCE mark that student get in each subject THIS IS WHERE TO APPLY PERCENTAGES
'status': attd.marks >= exam.exam_ids.min_marks and####IMPORTANCE take the mark and decide pass or fail base on passing mark in each subject
'pass' or 'fail',
'per': (100 * attd.marks) / exam.exam_ids.total_marks,####NOT IMPORTANCE this can be delete, this take the mark student get and find the percentage of the subject student get in each subject
'student_id': attd.student_id.id,####student name
'total_marks': exam.exam_ids.total_marks,####the total mark of each subject that have been enter when created subject for exam
}
- 错误详情 -
Odoo 服务器错误
回溯(最近一次通话最后):
文件“/home/v4d/odoo/openerp/http.py”,第 650 行,在 _handle_exception 中返回 super(JsonRequest, self)._handle_exception(exception)
文件“/home/v4d/odoo/openerp/http.py”,第 687 行,在 dispatch result = self._call_function(**self.params)
文件“/home/v4d/odoo/openerp/http.py”,第 323 行,在 _call_function 返回 checked_call(self.db, *args, **kwargs)
文件“/home/v4d/odoo/openerp/service/model.py”,第 118 行,在包装器中返回 f(dbname, *args, **kwargs)
文件“/home/v4d/odoo/openerp/http.py”,第 316 行,checked_call 结果 = self.endpoint(*a, **kw)
文件“/home/v4d/odoo/openerp/http.py”,第 966 行,调用 return self.method(*args, **kw)
文件“/home/v4d/odoo/openerp/http.py”,第 516 行,在 response_wrap response = f(*args, **kw)
文件“/home/v4d/odoo/addons/web/controllers/main.py”,第 899 行,在 call_button action = self._call_kw(model, method, args, {})
文件“/home/v4d/odoo/addons/web/controllers/main.py”,第 887 行,在 _call_kw return getattr(request.registry.get(model), method)(request.cr, request.uid, *args , **kwargs)
文件“/home/v4d/odoo/openerp/api.py”,第 250 行,在包装器中返回 old_api(self, *args, **kwargs)
文件“/home/v4d/odoo/openerp/api.py”,第 421 行,在 old_api 结果 = new_api(recs, *args, **kwargs)
文件“/home/v4d/odoo/openerp/api.py”,第 425 行,在 new_api 结果 = [method(rec, *args, **kwargs) for rec in self]
文件“/home/v4d/odoo/addons/openeducat_exam/models/result_template.py”,第 71 行,在 generate_result total_exam +=exam.exam_ids.total_marks
文件“/home/v4d/odoo/openerp/fields.py”,第 821 行,在get record.ensure_one()
文件“/home/v4d/odoo/openerp/models.py”,第 5432 行,在 ensure_one 中引发 ValueError("Expected singleton: %s" % self)
ValueError:预期单例:op.exam(44, 45, 46)
我尝试了其他可以在 Internet 上找到的解决方案,但它似乎不起作用。请帮我处理这个问题。在此先感谢。