Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions openacademy/model/openacademy_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,41 @@
class Session(models.Model):
_name = 'openacademy.session'


def no_editable_states(self):
""" Return the states were the session should not be editable
This is used to be the value of the states attribute in the fields
model definition.
@return: a dictionary key = state, and value = list of attributes that
will be activate when the session is in the key-state.
"""
return {
'confirmed': [('readonly', True)],
'done': [('readonly', True)],
}

name = fields.Char(required=True)
start_date = fields.Date(default=fields.Date.today)
duration = fields.Float(digits=(6, 2), help="Duration in days")
seats = fields.Integer(string="Number of seats")
start_date = fields.Date(default=fields.Date.today, states=no_editable_states)
duration = fields.Float(digits=(6, 2), help="Duration in days", states=no_editable_states)
seats = fields.Integer(string="Number of seats", states=no_editable_states)
instructor_id = fields.Many2one('res.partner', string="Instructor",
domain=['|',
("instructor", "=", True),
("category_id.name", "ilike", "Teacher"),
])
], states=no_editable_states)
course_id = fields.Many2one('openacademy.course',
ondelete='cascade', string="Course", required=True)
attendee_ids = fields.Many2many('res.partner', string="Attendees")
ondelete='cascade', string="Course", required=True, states=no_editable_states)
attendee_ids = fields.Many2many('res.partner', string="Attendees", states=no_editable_states)
taken_seats = fields.Float(string="Taken seats", compute='_taken_seats',
store=True)
active = fields.Boolean(default=True)
store=True, states=no_editable_states)
active = fields.Boolean(default=True, states=no_editable_states)
end_date = fields.Date(string="End Date", store=True,
compute='_get_end_date', inverse='_set_end_date')
compute='_get_end_date', inverse='_set_end_date', states=no_editable_states)
hours = fields.Float(string="Duration in hours",
compute='_get_hours', inverse='_set_hours')
compute='_get_hours', inverse='_set_hours', states=no_editable_states)
attendees_count = fields.Integer(
string="Attendees count", compute='_get_attendees_count', store=True)
color = fields.Integer()
string="Attendees count", compute='_get_attendees_count', store=True, states=no_editable_states)
color = fields.Integer(states=no_editable_states)
state = fields.Selection([
('draft', 'Draft'),
('confirmed', 'Confirmed'),
Expand Down Expand Up @@ -103,7 +116,7 @@ def _set_hours(self):
@api.depends('attendee_ids')
def _get_attendees_count(self):
self.attendees_count = len(self.attendee_ids)

@api.one
def action_draft(self):
self.state = 'draft'
Expand Down
8 changes: 5 additions & 3 deletions openacademy/view/openacademy_session_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
string="Mark as done"
states="confirmed"
class="oe_highlight"/>
<field name="state" widget="statusbar"/>
<field name="state" widget="statusbar"/>
</header>
<sheet>
<group string="General">
<field name="course_id"/>
<field name="name"/>
<field name="name"
attrs="{'readonly':[('state','!=','draft')],}"
/>
<field name="taken_seats" widget="progressbar"/>
<field name="instructor_id"/>
<field name="instructor_id"/>
<field name="active"/>
</group>
<group string="Schedule">
Expand Down