-
Notifications
You must be signed in to change notification settings - Fork 0
[ADD] event_service_base: base module for event service core models #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
chdh-odoo
wants to merge
1
commit into
main
Choose a base branch
from
master-full-stack-app-chdh
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+136
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import models |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| 'name': 'Event Service Base', | ||
| 'summary': 'Foundational business logic for service event management', | ||
| 'description': """ | ||
| Provides the foundational models and business logic for | ||
| service events and bookings, intended to be extended | ||
| by other modules. | ||
| """, | ||
| 'version': '1.0', | ||
| 'author': 'Dhruv', | ||
| 'license': 'LGPL-3', | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| from . import event_service | ||
| from . import event_service_registration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from community.odoo import fields, models | ||
|
|
||
|
|
||
| class EventService(models.Model): | ||
| _name = "event.service" | ||
| _description = "Event Service" | ||
|
|
||
| name = fields.Char(string="Name", required=True, index=True) | ||
| description = fields.HTML(string="Description") | ||
| price = fields.Float(string="Price", default=0.0) | ||
| active = fields.Boolean(string="Active", default=True) | ||
| category_id = fields.Many2one("event.service.category", string="Category", ondelete="restrict") | ||
| tag_ids = fields.Many2many("event.service.tag", string="Tags") | ||
| company_id = fields.Many2one("res.company", default=lambda self: self.env.company) | ||
| booking_ids = fields.One2many("event.service.registration", "service_id", string="Bookings") | ||
|
|
||
| class EventServiceCategory(models.Model): | ||
| _name = "event.service.category" | ||
| _description = "Event Service Category" | ||
|
|
||
| name = fields.Char(required=True) | ||
| active = fields.Boolean(default=True) | ||
|
|
||
| class EventServiceTag(models.Model): | ||
| _name = "event.service.tag" | ||
| _description = "Event Service Tag" | ||
|
|
||
| name = fields.Char(required=True) | ||
| color = fields.Integer() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import ValidationError | ||
|
|
||
|
|
||
| class EventServiceRegistration(models.Model): | ||
| _name = "event.service.registration" | ||
| _description = "Event Service Registration" | ||
|
|
||
| name = fields.Char(string="Event Name", readonly=True, copy=False) | ||
| quantity = fields.Integer(string="Number of Attendees", default=1) | ||
| currency_id = fields.Many2one("res.currency", related="company_id.currency_id", readonly=True) | ||
| amount = fields.Monetary(string="Total Amount", compute="_compute_amount", store=True, currency_field="currency_id") | ||
| booking_date = fields.Datetime(string="Booking Date", default=fields.Datetime.now, required=True) | ||
| state = fields.Selection([ | ||
| ('draft', 'Draft'), | ||
| ('confirmed', 'Confirmed'), | ||
| ('cancelled', 'Cancelled') | ||
| ], default = 'draft', readonly=True) | ||
| partner_id = fields.Many2one("res.partner", string="Partner", required=True, ondelete="restrict") | ||
| service_id = fields.Many2one("event.service", string="Service", required=True, ondelete="restrict") | ||
| company_id = fields.Many2one("res.company", default=lambda self: self.env.company, ondelete="restrict") | ||
|
|
||
| _unique_booking = models.Constraint( | ||
| "unique(partner_id, service_id)", | ||
| "You cannot register the same service twice.", | ||
| ) | ||
|
|
||
| @api.constrains("quantity") | ||
| def _check_quantity(self): | ||
| for record in self: | ||
| if record.quantity <= 0: | ||
| raise ValidationError( | ||
| "Number of attendees must be greater than zero." | ||
| ) | ||
|
|
||
| @api.depends('service_id.price', 'quantity') | ||
| def _compute_amount(self): | ||
| for record in self: | ||
| record.amount = record.quantity * record.service_id.price | ||
|
|
||
| @api.constrains("company_id", "service_id") | ||
| def _check_company_consistency(self): | ||
| for record in self: | ||
| if ( | ||
| record.service_id | ||
| and record.service_id.company_id != record.company_id | ||
| ): | ||
| raise ValidationError( | ||
| "The service and the booking must belong to the same company." | ||
| ) | ||
|
|
||
|
|
||
| @api.model_create_multi | ||
| def create(self, vals_list): | ||
| for vals in vals_list: | ||
| if not vals.get("name"): | ||
| vals["name"] = self.env["ir.sequence"].next_by_code( | ||
| "event.service.registration" | ||
| ) | ||
| return super().create(vals_list) | ||
|
|
||
| @api.constrains("booking_date") | ||
| def _check_booking_date(self): | ||
| now = fields.Datetime.now() | ||
| for record in self: | ||
| if record.booking_date and record.booking_date < now: | ||
| raise ValidationError( | ||
| "The booking date cannot be in the past." | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
| access_event_service_registration_user,event.service.registration user,model_event_service_registration,base.group_user,1,1,1,1 | ||
| access_event_service_user,event.service user,model_event_service,base.group_user,1,1,1,1 | ||
| access_event_service_category_user,event.service.category user,model_event_service_category,base.group_user,1,1,1,0 | ||
| access_event_service_tag_user,event.service.tag user,model_event_service_tag,base.group_user,1,1,1,0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import models |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| 'name': 'Event Service Website', | ||
| 'summary': 'Manage event services and customer bookings', | ||
| 'description': """ | ||
| - Definition of event services with pricing | ||
| - Service categories and tags | ||
| - Customer registrations for services | ||
| - Core business rules and validations for bookings | ||
|
|
||
| """, | ||
| 'version': '1.0', | ||
| 'depends': ['event_service_base', 'website', 'portal'], | ||
| 'author': 'Dhruv', | ||
| 'installable': True, | ||
| 'application': True, | ||
| 'license': 'LGPL-3', | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe not read only?