Skip to content
Draft
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
2 changes: 2 additions & 0 deletions service_event_base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import controllers
17 changes: 17 additions & 0 deletions service_event_base/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
'name': 'Service Event Base',
'version': '1.0.0',
'summary': 'Base module for service event management',
'description': 'This module provides the foundational models and views for managing service events within the Odoo framework.',
'category': 'Services',
'depends': ['base', 'mail', 'event'],
'data': [
'views/event_service_menu_view.xml',
'views/event_service.xml',
'security/ir.model.access.csv'
],
'installable': True,
'application': True,
'author': 'Garvish',
'license': 'LGPL-3',
}
2 changes: 2 additions & 0 deletions service_event_base/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import event_registration
from . import event_service
38 changes: 38 additions & 0 deletions service_event_base/models/event_registration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError


class EventRegistration(models.Model):
_name = 'event.registrations'
_description = 'Event Registration'

attendee_name = fields.Char(string='Attendee Name', required=True)
partner_id = fields.Many2one('res.partner', string='Partner', index=True)
service_id = fields.Many2one('event.management', string='Event Service', ondelete='cascade', required=True)
state = fields.Selection([
('draft', 'Draft'),
('confirmed', 'Confirmed'),
('cancelled', 'Cancelled')
], string='Status', default='draft', required=True)
booking_date = fields.Datetime(string='Booking Date', default=fields.Datetime.now)
booking_amount = fields.Monetary(string='Booking Amount', currency_field='currency_id', compute='_compute_booking_amount', store=True, readonly=True)
currency_id = fields.Many2one('res.currency', string='Currency', related='service_id.currency_id', readonly=True)
company_id = fields.Many2one('res.company', string='Company', related='service_id.company_id', store=True, readonly=True)

_booking_service_check = models.Constraint(
'unique (service_id, partner_id)',
"Each partner can register only once for the same event service."
)

# Compute fields
@api.depends('service_id')
def _compute_booking_amount(self):
for record in self:
record.booking_amount = record.service_id.price

# Python constrains
@api.constrains('booking_date')
def _check_booking_date(self):
for record in self:
if record.booking_date and record.booking_date < fields.Datetime.now():
raise ValidationError(_("Booking date cannot be in the past."))
27 changes: 27 additions & 0 deletions service_event_base/models/event_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from odoo import api, fields, models, _


class EventService(models.Model):
_name = 'event.management'
_description = 'Event Management Service'

name = fields.Char(string='Event Name', required=True)
description = fields.Html(string='Description')
price = fields.Monetary(string='Price', currency_field='currency_id')
active = fields.Boolean(string='Active', default=True)
# Many2one relationship to event type from odoo standard event module
event_type_id = fields.Many2one('event.type', string='Event Type', ondelete='set null', index=True)
tag_ids = fields.Many2many('event.tag', string='Tags', compute='_compute_tag_ids')
company_id = fields.Many2one('res.company', required=True, default=lambda self: self.env.company)
booking_ids = fields.One2many('event.registrations', 'service_id', string='Bookings')
# You are never going to use multi-currency in a single company or change it either.
currency_id = fields.Many2one('res.currency', string='Currency', default=lambda self: self.company_id.currency_id, readonly=True)

@api.depends('event_type_id')
def _compute_tag_ids(self):
"""If you are changing the event type, also your tags are empty. In that
Case just assign the tags from event_type_id to current record. Already
done in standard event module."""
for record in self:
if not record.tag_ids and record.event_type_id:
record.tag_ids = record.event_type_id.tag_ids
3 changes: 3 additions & 0 deletions service_event_base/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_event_management_user,access.event.management.user,model_event_management,base.group_user,1,1,1,1
access_event_registrations_user,access.event.registrations.user,model_event_registrations,base.group_user,1,1,1,1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions service_event_base/views/event_service.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="view_service_event_list" model="ir.ui.view">
<field name="name">event.management.list</field>
<field name="model">event.management</field>
<field name="arch" type="xml">
<list string="Service Events">
<field name="name"/>
<field name="company_id"/>
<field name="tag_ids"/>
<field name="event_type_id"/>
</list>
</field>
</record>

<record id="view_service_event_form" model="ir.ui.view">
<field name="name">event.management.form</field>
<field name="model">event.management</field>
<field name="arch" type="xml">
<form string="Service Event">
<sheet>
<group>
<field name="name"/>
<field name="description"/>
<field name="price" widget="monetary" options="{'currency_field': 'currency_id'}"/>
<field name="company_id"/>
<field name="tag_ids" widget="many2many_tags"/>
<field name="event_type_id"/>
<field name="booking_ids"/>
</group>
</sheet>
</form>
</field>
</record>

</odoo>
27 changes: 27 additions & 0 deletions service_event_base/views/event_service_menu_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="action_service_event_list" model="ir.actions.act_window">
<field name="name">Service Events</field>
<field name="res_model">event.management</field>
<field name="view_mode">list,form</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
No service events found. Create your first one!
</p>
</field>
</record>

<menuitem id="menu_service_event_base"
name="Event Services"
sequence="10"
web_icon="service_event_base,static/description/icon.png"/>

<menuitem
id="menu_service_events"
name="Service Events"
parent="menu_service_event_base"
sequence="10"
action="action_service_event_list"/>

</odoo>