diff --git a/learning_center/models/__pycache__/__init__.cpython-312.pyc b/learning_center/models/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..d1f1900 Binary files /dev/null and b/learning_center/models/__pycache__/__init__.cpython-312.pyc differ diff --git a/learning_center/models/__pycache__/course_homework.cpython-312.pyc b/learning_center/models/__pycache__/course_homework.cpython-312.pyc new file mode 100644 index 0000000..d43fdd7 Binary files /dev/null and b/learning_center/models/__pycache__/course_homework.cpython-312.pyc differ diff --git a/learning_center/models/__pycache__/course_homework_submit.cpython-312.pyc b/learning_center/models/__pycache__/course_homework_submit.cpython-312.pyc new file mode 100644 index 0000000..bef74ce Binary files /dev/null and b/learning_center/models/__pycache__/course_homework_submit.cpython-312.pyc differ diff --git a/learning_center/models/__pycache__/course_teaching_class.cpython-312.pyc b/learning_center/models/__pycache__/course_teaching_class.cpython-312.pyc new file mode 100644 index 0000000..4ff25bb Binary files /dev/null and b/learning_center/models/__pycache__/course_teaching_class.cpython-312.pyc differ diff --git a/learning_center/models/course_homework.py b/learning_center/models/course_homework.py index 697fb0d..ffcb0eb 100644 --- a/learning_center/models/course_homework.py +++ b/learning_center/models/course_homework.py @@ -35,7 +35,11 @@ class CourseHomework(models.Model): teaching_class_id = fields.Many2one('course.teaching_class', string='教学班', ondelete='cascade', domain="[('course_id', '=', course_id)]") submit_ids = fields.One2many('course.homework.submit', 'homework_id', string='提交记录') +<<<<<<< HEAD score_item_ids = fields.One2many('course.score.item', 'homework_id', string='成绩项目') +======= + score_item_ids = fields.One2many('course.score.item', 'homework_id', string='成绩项') +>>>>>>> 0b2a587b69524dafde97f76bad27721afebdcddb # ====================== 新增:自动计算提交通道是否开启 ====================== @api.depends('state', 'deadline') @@ -82,6 +86,7 @@ class CourseHomework(models.Model): self.publish_time = fields.Datetime.now() # 1. 批量为本班学生生成空白未提交记录 self._auto_create_empty_submit() +<<<<<<< HEAD # 新增:自动生成对应作业的学生成绩明细 self._auto_create_homework_score_detail() # 2. 推送作业通知给学生 @@ -137,6 +142,39 @@ class CourseHomework(models.Model): if detail_vals_list: self.env['course.student.score.detail'].create(detail_vals_list) +======= + # 2. 推送作业通知给学生 + self._send_homework_notice_to_students() + + def _send_homework_notice_to_students(self): + """发布作业后推送消息给教学班学生""" + self.ensure_one() + if not self.teaching_class_id: + return + # 获取当前教学班所有已选课学生 + enrolls = self.env['course.teaching_class.enrollment'].search([ + ('teaching_class_id', '=', self.teaching_class_id.id), + ('state', '=', 'enrolled') + ]) + student_users = enrolls.mapped('student_id.user_id').filtered(lambda u: u) + if not student_users: + return + # 消息内容 + subject = f"新作业发布:{self.name}" + body = f""" +
课程:{self.course_id.name}
+作业名称:{self.name}
+截止时间:{self.deadline or '无'}
+作业要求:{self.requirement or '无'}
+ """ + # 发送消息(关联当前作业记录,学生在消息中心可直接跳转) + self.message_post( + subject=subject, + body=body, + partner_ids=student_users.mapped('partner_id').ids, + subtype_xmlid='mail.mt_comment' + ) +>>>>>>> 0b2a587b69524dafde97f76bad27721afebdcddb def _auto_create_empty_submit(self): """仅发布时执行:自动给教学班所有已选课学生生成空白未提交记录""" @@ -164,12 +202,16 @@ class CourseHomework(models.Model): batch_vals.append({ 'homework_id': self.id, 'student_id': stu_id, +<<<<<<< HEAD 'course_score_item_id':self.course_score_item_id.id, +======= +>>>>>>> 0b2a587b69524dafde97f76bad27721afebdcddb 'state': 'unsubmit' # 默认未提交 }) # 批量创建空白提交记录 submit_model.create(batch_vals) +<<<<<<< HEAD def _send_homework_notice_to_students(self): """发布作业后推送消息给教学班学生""" self.ensure_one() @@ -199,6 +241,8 @@ class CourseHomework(models.Model): subtype_xmlid='mail.mt_note' ) +======= +>>>>>>> 0b2a587b69524dafde97f76bad27721afebdcddb # ====================== 草稿/关闭作业 ====================== def action_draft(self): self.state = 'draft' @@ -325,6 +369,7 @@ class CourseHomework(models.Model): def create(self, vals): homework_record = super().create(vals) # 草稿状态不执行自动生成提交记录,移到action_publish +<<<<<<< HEAD target_a = self.env["course.score.item"].search([ ("name", "=", "作业"), @@ -336,4 +381,6 @@ class CourseHomework(models.Model): target_a.write({ "homework_ids": [(4, homework_record.id)] }) +======= +>>>>>>> 0b2a587b69524dafde97f76bad27721afebdcddb return homework_record \ No newline at end of file diff --git a/learning_center/models/course_homework_submit.py b/learning_center/models/course_homework_submit.py index a6d2ccb..589f2d6 100644 --- a/learning_center/models/course_homework_submit.py +++ b/learning_center/models/course_homework_submit.py @@ -93,7 +93,10 @@ class CourseHomeworkSubmit(models.Model): def create(self, vals): submit_rec = super().create(vals) self._check_submit_change_state(submit_rec) +<<<<<<< HEAD +======= +>>>>>>> 0b2a587b69524dafde97f76bad27721afebdcddb return submit_rec def write(self, vals):