Skip to content

Commit

Permalink
[ADD]resource_booking_portal
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and adasatorres committed Oct 31, 2024
1 parent 071100f commit d99df14
Show file tree
Hide file tree
Showing 24 changed files with 1,162 additions and 0 deletions.
107 changes: 107 additions & 0 deletions resource_booking_portal/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
=======================
resource_booking_portal
=======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:8ad914e817c82df68edfc22189124e669f753f35ebd77cb05e6e5d05465a4c02
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcalendar-lightgray.png?logo=github
:target: https://github.com/OCA/calendar/tree/14.0/resource_booking_portal
:alt: OCA/calendar
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/calendar-14-0/calendar-14-0-resource_booking_portal
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/calendar&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This addon allows portal users to create bookings from the portal if they have the necessary permissions.

**Table of contents**

.. contents::
:local:

Usage
=====

#. You need a portal user with the "Create booking from portal" option active.

#. You can find this option on the "Access Rights" page,
but only if the user belongs to the portal user group.

#. Log in with the user mentioned above.

#. Go to **"My Account."**

#. In **"My Account,"** you will find a new section called **"Actions."**

#. In this section, there is a button to access the **create booking form.**
When you create a booking with this form, you must select the **subject** and **type**.
The **description** is optional.

#. When you use the **"Continue"** button, you can assign a date with your commercial representative.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/calendar/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/calendar/issues/new?body=module:%20resource_booking_portal%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Binhex

Contributors
~~~~~~~~~~~~


* `Binhex <https://www.binhex.cloud>`_:

* Adasat Torres de León <a.torres@binhex.cloud>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-adasatorres| image:: https://github.com/adasatorres.png?size=40px
:target: https://github.com/adasatorres
:alt: adasatorres

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-adasatorres|

This module is part of the `OCA/calendar <https://github.com/OCA/calendar/tree/14.0/resource_booking_portal>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions resource_booking_portal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import controllers
from . import models
from . import wizard
22 changes: 22 additions & 0 deletions resource_booking_portal/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "resource_booking_portal",
"summary": """
This addons allow create booking from portal.
""",
"author": "Odoo Community Association (OCA), Binhex",
"website": "https://github.com/OCA/calendar",
"maintainers": ["adasatorres"],
"category": "portal",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"depends": [
"resource_booking",
],
"data": [
"views/portal_templates.xml",
"views/res_users_views.xml",
"wizard/portal_wizard_views.xml",
],
}
3 changes: 3 additions & 0 deletions resource_booking_portal/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright 2024 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import portal
77 changes: 77 additions & 0 deletions resource_booking_portal/controllers/portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright 2024 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).


from datetime import datetime
from urllib.parse import quote_plus

from dateutil.parser import isoparse

from odoo.exceptions import ValidationError
from odoo.http import request, route
from odoo.tests.common import Form

from odoo.addons.portal.controllers import portal


class CustomerPortal(portal.CustomerPortal):
@route(
["/my/bookings/prepare/form"],
auth="user",
type="http",
website=True,
)
def portal_bookings_prepare_form(self):
values = {
"page_name": "create_booking",
"types": request.env["resource.booking.type"]
.sudo()
.search_read([], ["id", "name"]),
}
return request.render("resource_booking_portal.booking_create_form", values)

@route(
["/my/bookings/create"],
auth="user",
type="http",
method=["POST"],
website=True,
csrf=False,
)
def portal_bookings_create(self, **post):
Booking = request.env["resource.booking"].sudo()
BookingType = request.env["resource.booking.type"].sudo()
partner_id = request.env.user.partner_id
res = Booking.create(
{
"name": post.get("name"),
"type_id": BookingType.browse(int(post.get("type"))).id,
"partner_id": partner_id.id,
"combination_auto_assign": True,
"description": post.get("description", False),
"user_id": partner_id.user_id.id,
}
)
return request.redirect("/my/bookings/%s/schedule" % res.id)

@route(
["/my/bookings/<int:booking_id>/reserve"],
auth="user",
type="http",
method=["POST"],
website=True,
)
def portal_booking_reserve(self, booking_id, access_token, when, **kwargs):
booking_sudo = self._get_booking_sudo(booking_id, access_token)
when_tz_aware = isoparse(when)
when_naive = datetime.utcfromtimestamp(when_tz_aware.timestamp())
try:
with Form(booking_sudo) as booking_form:
booking_form.start = when_naive
except ValidationError as error:
url = booking_sudo.get_portal_url(

Check warning on line 72 in resource_booking_portal/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

resource_booking_portal/controllers/portal.py#L65-L72

Added lines #L65 - L72 were not covered by tests
suffix="/schedule/{:%Y/%m}".format(when_tz_aware),
query_string="&error={}".format(quote_plus(error.name)),
)
return request.redirect(url)
return request.redirect(booking_sudo.get_portal_url())

Check warning on line 77 in resource_booking_portal/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

resource_booking_portal/controllers/portal.py#L76-L77

Added lines #L76 - L77 were not covered by tests
125 changes: 125 additions & 0 deletions resource_booking_portal/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * resource_booking_portal
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-09-03 10:36+0000\n"
"PO-Revision-Date: 2024-09-03 11:38+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.4.4\n"

#. module: resource_booking_portal
#: model_terms:ir.ui.view,arch_db:resource_booking_portal.portal_my_home_menu
msgid "<span>Create booking</span>"
msgstr "<span>Crear reserva</span>"

#. module: resource_booking_portal
#: model_terms:ir.ui.view,arch_db:resource_booking_portal.portal_my_home
msgid "Actions"
msgstr "Acciones"

#. module: resource_booking_portal
#: model_terms:ir.ui.view,arch_db:resource_booking_portal.res_users_portal_form_view_inherit
msgid "Booking"
msgstr "Reserva"

#. module: resource_booking_portal
#: code:addons/resource_booking_portal/wizard/portal_wizard.py:0
#: model:ir.model.fields,field_description:resource_booking_portal.field_portal_wizard_user__booking_from_portal
#, python-format
msgid "Booking from portal"
msgstr "Reserva desde el portal"

#. module: resource_booking_portal
#: model:res.groups,name:resource_booking_portal.group_portal_sellers_bookings
msgid "Can create booking from portal"
msgstr "Puede crear reservas desde el portal"

#. module: resource_booking_portal
#: model_terms:ir.ui.view,arch_db:resource_booking_portal.booking_create_form
msgid "Continue"
msgstr "Continuar"

#. module: resource_booking_portal
#: model_terms:ir.ui.view,arch_db:resource_booking_portal.portal_my_home
msgid "Create a booking"
msgstr "Crear una reserva"

#. module: resource_booking_portal
#: code:addons/resource_booking_portal/models/res_users.py:0
#: model:ir.model.fields,field_description:resource_booking_portal.field_res_users__create_booking_from_portal
#, python-format
msgid "Create booking from portal"
msgstr "Crear reserva desde el portal"

#. module: resource_booking_portal
#: model_terms:ir.ui.view,arch_db:resource_booking_portal.booking_create_form
msgid "Description"
msgstr "Descripción"

#. module: resource_booking_portal
#: model:ir.model.fields,field_description:resource_booking_portal.field_portal_wizard_user__display_name
#: model:ir.model.fields,field_description:resource_booking_portal.field_res_users__display_name
msgid "Display Name"
msgstr "Nombre a mostrar"

#. module: resource_booking_portal
#: model:ir.model.fields,field_description:resource_booking_portal.field_portal_wizard_user__id
#: model:ir.model.fields,field_description:resource_booking_portal.field_res_users__id
msgid "ID"
msgstr "ID"

#. module: resource_booking_portal
#: model:ir.model.fields,field_description:resource_booking_portal.field_res_users__is_portal_user
msgid "Is Portal User"
msgstr "Es usuario de portal"

#. module: resource_booking_portal
#: model:ir.model.fields,field_description:resource_booking_portal.field_portal_wizard_user____last_update
#: model:ir.model.fields,field_description:resource_booking_portal.field_res_users____last_update
msgid "Last Modified on"
msgstr "Última modificación el"

#. module: resource_booking_portal
#: model_terms:ir.ui.view,arch_db:resource_booking_portal.booking_create_form
msgid "Name"
msgstr "Asunto"

#. module: resource_booking_portal
#: model_terms:ir.ui.view,arch_db:resource_booking_portal.res_users_portal_form_view_inherit
msgid "Portal"
msgstr "Portal"

#. module: resource_booking_portal
#: model:ir.model,name:resource_booking_portal.model_portal_wizard_user
msgid "Portal User Config"
msgstr "Configuración de usuario de portal"

#. module: resource_booking_portal
#: model_terms:ir.ui.view,arch_db:resource_booking_portal.booking_create_form
msgid "Resource Name"
msgstr "Asunto"

#. module: resource_booking_portal
#: model_terms:ir.ui.view,arch_db:resource_booking_portal.booking_create_confirmation
msgid "TEST"
msgstr ""

#. module: resource_booking_portal
#: model_terms:ir.ui.view,arch_db:resource_booking_portal.booking_create_form
msgid "Type"
msgstr "Tipo"

#. module: resource_booking_portal
#: model:ir.model,name:resource_booking_portal.model_res_users
msgid "Users"
msgstr "Usuarios"
3 changes: 3 additions & 0 deletions resource_booking_portal/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright 2024 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import res_users
16 changes: 16 additions & 0 deletions resource_booking_portal/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


class ResUsers(models.Model):
_inherit = "res.users"

create_booking_from_portal = fields.Boolean(
string="Create booking from portal",
)
is_portal_user = fields.Boolean(compute="_compute_is_portal_user")

def _compute_is_portal_user(self):
for record in self:
record.is_portal_user = record.has_group("base.group_portal")
4 changes: 4 additions & 0 deletions resource_booking_portal/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

* `Binhex <https://www.binhex.cloud>`_:

* Adasat Torres de León <a.torres@binhex.cloud>
1 change: 1 addition & 0 deletions resource_booking_portal/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This addon allows portal users to create bookings from the portal if they have the necessary permissions.
16 changes: 16 additions & 0 deletions resource_booking_portal/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#. You need a portal user with the "Create booking from portal" option active.

#. You can find this option on the "Access Rights" page,
but only if the user belongs to the portal user group.

#. Log in with the user mentioned above.

#. Go to **"My Account."**

#. In **"My Account,"** you will find a new section called **"Actions."**

#. In this section, there is a button to access the **create booking form.**
When you create a booking with this form, you must select the **subject** and **type**.
The **description** is optional.

#. When you use the **"Continue"** button, you can assign a date with your commercial representative.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d99df14

Please sign in to comment.