diff --git a/service_event_base/__init__.py b/service_event_base/__init__.py new file mode 100644 index 0000000..f7209b1 --- /dev/null +++ b/service_event_base/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import controllers diff --git a/service_event_base/__manifest__.py b/service_event_base/__manifest__.py new file mode 100644 index 0000000..0789c3c --- /dev/null +++ b/service_event_base/__manifest__.py @@ -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', +} diff --git a/service_event_base/models/__init__.py b/service_event_base/models/__init__.py new file mode 100644 index 0000000..c9d45c1 --- /dev/null +++ b/service_event_base/models/__init__.py @@ -0,0 +1,2 @@ +from . import event_registration +from . import event_service diff --git a/service_event_base/models/event_registration.py b/service_event_base/models/event_registration.py new file mode 100644 index 0000000..3c50bf4 --- /dev/null +++ b/service_event_base/models/event_registration.py @@ -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.")) diff --git a/service_event_base/models/event_service.py b/service_event_base/models/event_service.py new file mode 100644 index 0000000..b1e9c29 --- /dev/null +++ b/service_event_base/models/event_service.py @@ -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 diff --git a/service_event_base/security/ir.model.access.csv b/service_event_base/security/ir.model.access.csv new file mode 100644 index 0000000..d625c55 --- /dev/null +++ b/service_event_base/security/ir.model.access.csv @@ -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 diff --git a/service_event_base/static/description/THEEKEEEBHAI.png b/service_event_base/static/description/THEEKEEEBHAI.png new file mode 100644 index 0000000..924f377 Binary files /dev/null and b/service_event_base/static/description/THEEKEEEBHAI.png differ diff --git a/service_event_base/views/event_service.xml b/service_event_base/views/event_service.xml new file mode 100644 index 0000000..e7c96ea --- /dev/null +++ b/service_event_base/views/event_service.xml @@ -0,0 +1,37 @@ + + + + + event.management.list + event.management + + + + + + + + + + + + event.management.form + event.management + +
+ + + + + + + + + + + +
+
+
+ +
diff --git a/service_event_base/views/event_service_menu_view.xml b/service_event_base/views/event_service_menu_view.xml new file mode 100644 index 0000000..2f6f772 --- /dev/null +++ b/service_event_base/views/event_service_menu_view.xml @@ -0,0 +1,27 @@ + + + + + Service Events + event.management + list,form + +

+ No service events found. Create your first one! +

+
+
+ + + + + +