0% found this document useful (0 votes)
3 views

Assignment_2.9_Customize_the_plugin_in_assignment_2.5

12

Uploaded by

linhvtkhe170509
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Assignment_2.9_Customize_the_plugin_in_assignment_2.5

12

Uploaded by

linhvtkhe170509
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

exercise.

py :

from odoo import models, fields, api

class StudentExercise(models.Model):

_name = 'student.exercise'

_description = 'Student Exercise'

_inherit = ['mail.thread']

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

description = fields.Text(string='Description')

due_date = fields.Date(string='Due Date')

is_completed = fields.Boolean(string='Completed', default=False)

attachment_ids = fields.Many2many('ir.attachment', string='Attachments')

status = fields.Selection([

('planning', 'Planning'),

('in_progress', 'In Progress'),

('review', 'Review'),

('postpone', 'Postpone'),

('submitted', 'Submitted')

], string='Status', default='planning')

@api.model

def create(self, vals):

record = super(StudentExercise, self).create(vals)

if vals.get('status') == 'submitted':

# Send notification

record._send_submission_notification()
return record

def write(self, vals):

res = super(StudentExercise, self).write(vals)

if 'status' in vals and vals.get('status') == 'submitted':

# Send notification

self._send_submission_notification()

return res

def _send_submission_notification(self):

for record in self:

message = f'The exercise "{record.name}" has been submitted.'

# Post the message to the user's inbox

record.message_post(body=message, subject="Exercise Submitted")

exercise_views.xml :

<odoo>

<data>

<!-- Action -->

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

<field name="name">Student Exercises</field>

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

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

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

<p class="o_view_nocontent_smiling_face">

Create your first student exercise


</p>

</field>

</record>

<!-- Menu Item -->

<menuitem id="menu_student_exercise_root" name="Student


Exercises" sequence="10"/>

<menuitem id="menu_student_exercises" name="Exercises"


parent="menu_student_exercise_root" action="action_student_exercise"/>

<!-- Tree View -->

<!-- Tree View -->

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

<field name="name">student.exercise.tree</field>

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

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

<tree string="Student Exercises">

<field name="name"/>

<field name="due_date"/>

<field name="is_completed"/>

<field name="status"/>

</tree>

</field>

</record>

<!-- Form View -->

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


<field name="name">student.exercise.form</field>

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

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

<form string="Student Exercise">

<sheet>

<group>

<field name="name"/>

<field name="description"/>

<field name="due_date"/>

<field name="is_completed"/>

<field name="attachment_ids"
widget="many2many_binary"/>

<field name="status"/>

</group>

</sheet>

</form>

</field>

</record>

</data>

</odoo>

__manifest__.py :

'name': 'Student Exercise Management',

'version': '1.0',

'category': 'Education',
'summary': 'A simple module for students to create and manage
exercises',

'description': 'This module allows students to create, view, and manage


exercises.',

'author': 'Your Name',

'depends': ['base', 'mail'],

'data': [

'security/ir.model.access.csv',

'views/exercise_views.xml',

],

'installable': True,

'application': True,

You might also like