Skip to content

Commit

Permalink
[ADD]pms_civitfun: module
Browse files Browse the repository at this point in the history
  • Loading branch information
DarioLodeiros committed Oct 5, 2023
1 parent 2ad566a commit 8df2741
Show file tree
Hide file tree
Showing 27 changed files with 2,030 additions and 0 deletions.
76 changes: 76 additions & 0 deletions pms_civitfun/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
============
PMS CIVITFUN
============

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fpms-lightgray.png?logo=github
:target: https://github.com/OCA/pms/tree/14.0/pms_housekeeping
:alt: OCA/pms
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/pms-14-0/pms-14-0-pms_housekeeping
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/293/14.0
:alt: Try me on Runbot

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

This module allows you to manage the checkin online with external Civitfun APP.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/pms/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/pms/issues/new?body=module:%20pms_housekeeping%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
~~~~~~~

* Commit [Sun]

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

* `Commit [Sun] <https://www.commitsun.com>`:

* Dario Lodeiros


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.

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions pms_civitfun/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import controllers
from . import datamodels
from . import services
from . import models
from . import http
26 changes: 26 additions & 0 deletions pms_civitfun/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "API PMS CIVITFUN",
"author": "Commit [Sun], Odoo Community Association (OCA)",
"website": "https://github.com/OCA/pms",
"category": "Generic Modules/Property Management System",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"depends": [
"pms",
"base_rest",
"base_rest_datamodel",
"web",
"auth_signup",
"auth_jwt_login",
"base_location",
],
"external_dependencies": {
"python": ["jwt", "simplejson", "marshmallow", "jose"],
},
"data": [
"data/auth_jwt_validator.xml",
"views/pms_property_views.xml",
"views/res_partner_id_category_views.xml",
],
"installable": True,
}
1 change: 1 addition & 0 deletions pms_civitfun/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import pms_rest
9 changes: 9 additions & 0 deletions pms_civitfun/controllers/pms_rest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from odoo.addons.base_rest.controllers import main


class BaseRestCivitfunApiController(main.RestController):
_root_path = "/civitfun/"
_collection_name = "civitfun.services"
_default_auth = "public"
_default_save_session = False
_default_cors = "*"
16 changes: 16 additions & 0 deletions pms_civitfun/data/auth_jwt_validator.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<odoo>
<data noupdate="1">
<record id="civitfun_validator" model="auth.jwt.validator">
<field name="name">civitfun</field>
<field name="audience">civitfun</field>
<field name="issuer">civitfun</field>
<field name="signature_type">secret</field>
<field name="secret_algorithm">HS256</field>
<field name="secret_key">civitfun_secret_key_example</field>
<field name="user_id_strategy">login</field>
<field name="static_user_id">1</field>
<field name="partner_id_strategy">email</field>
<field name="partner_id_required" eval="False" />
</record>
</data>
</odoo>
4 changes: 4 additions & 0 deletions pms_civitfun/datamodels/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import pms_checkin_partner
from . import pms_reservation
from . import pms_user
from . import pms_payment
46 changes: 46 additions & 0 deletions pms_civitfun/datamodels/pms_checkin_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from marshmallow import fields

from odoo.addons.datamodel.core import Datamodel
from odoo.addons.datamodel.fields import NestedModel


class CivitfunCheckinPartnerInfo(Datamodel):
_name = "civitfun.checkin.partner.info"

idCheckinGuest = fields.String(required=False, allow_none=True)
id = fields.String(required=False, allow_none=True)
position = fields.Integer(required=False, allow_none=True)
email = fields.String(required=False, allow_none=True)
lang = fields.String(required=False, allow_none=True)
language = fields.String(required=False, allow_none=True)
name = fields.String(required=False, allow_none=True)
surname = fields.String(required=False, allow_none=True)
secondSurname = fields.String(required=False, allow_none=True)
gender = fields.String(required=False, allow_none=True)
birthdate = fields.Date(required=False, allow_none=True)
nationality = fields.String(required=False, allow_none=True)
documentType = fields.String(required=False, allow_none=True)
documentNumber = fields.String(required=False, allow_none=True)
expeditionDate = fields.Date(required=False, allow_none=True)
expirationDate = fields.Date(required=False, allow_none=True)
assignedRoom = fields.Dict(required=False, allow_none=True)
customFields = fields.Dict(required=False, allow_none=True)
legalFields = fields.Dict(required=False, allow_none=True)
birthDate = fields.Date(required=False, allow_none=True)
files = fields.List(fields.Dict(), required=False, allow_none=True)


class CivitfunGuestMeta(Datamodel):
_name = "civitfun.guest.meta"

propertyId = fields.String(required=False, allow_none=True)
bookingIdentifier = fields.String(required=False, allow_none=True)
guests = fields.List(NestedModel("civitfun.checkin.partner.info"))


class CivitfunGuestMetaResult(Datamodel):
_name = "civitfun.guest.meta.result"

success = fields.Boolean(required=False, allow_none=True)
message = fields.String(required=False, allow_none=True)
guestIds = fields.List(fields.Dict(required=False, allow_none=True))
33 changes: 33 additions & 0 deletions pms_civitfun/datamodels/pms_payment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from marshmallow import fields

from odoo.addons.datamodel.core import Datamodel


class CivitfunPaymentSearch(Datamodel):
_name = "civitfun.payment.search"

propertyId = fields.String(required=False, allow_none=True)
bookingIdentifier = fields.String(required=False, allow_none=True)
process = fields.String(required=False, allow_none=True)
lang = fields.String(required=False, allow_none=True)
# guests = fields.List(NestedModel("civitfun.checkin.partner.info"))


class CivitfunPaymentInfo(Datamodel):
_name = "civitfun.payment.info"

success = fields.Boolean(required=False, allow_none=True)
message = fields.String(required=False, allow_none=True)
currency = fields.String(required=False, allow_none=True)
accounts = fields.List(fields.Dict(required=False, allow_none=True))


class CivitfunPaymentRegister(Datamodel):
_name = "civitfun.payment.register"

propertyId = fields.String(required=False, allow_none=True)
bookingIdentifier = fields.String(required=False, allow_none=True)
process = fields.String(required=False, allow_none=True)
paymentToken = fields.String(required=False, allow_none=True)
paymentCard = fields.Dict(required=False, allow_none=True)
accountIds = fields.List(fields.Dict(required=False, allow_none=True))
51 changes: 51 additions & 0 deletions pms_civitfun/datamodels/pms_reservation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from marshmallow import fields

from odoo.addons.datamodel.core import Datamodel
from odoo.addons.datamodel.fields import NestedModel


class CivitfunReservationSearchInfo(Datamodel):
_name = "civitfun.reservation.search.info"

propertyId = fields.String(required=False, allow_none=True)
bookingIdentifier = fields.String(required=False, allow_none=True)
bookingCode = fields.String(required=False, allow_none=True)
entranceDate = fields.String(required=False, allow_none=True)
departureDate = fields.String(required=False, allow_none=True)
bookingDate = fields.String(required=False, allow_none=True)


class CivitfunReservationInfo(Datamodel):
_name = "civitfun.reservation.info"

bookingIdentifier = fields.String(required=False, allow_none=True)
bookingCode = fields.String(required=False, allow_none=True)
status = fields.String(required=False, allow_none=True)
holder = fields.String(required=False, allow_none=True)
holderCountry = fields.String(required=False, allow_none=True)
email = fields.String(required=False, allow_none=True)
entrance = fields.String(required=False, allow_none=True)
entranceTime = fields.String(required=False, allow_none=True)
departure = fields.String(required=False, allow_none=True)
departureTime = fields.String(required=False, allow_none=True)
adults = fields.Integer(required=False, allow_none=True)
babies = fields.Integer(required=False, allow_none=True)
children = fields.Integer(required=False, allow_none=True)
regimeStay = fields.String(required=False, allow_none=True)
agency = fields.String(required=False, allow_none=True)
stayAmount = fields.Float(required=False, allow_none=True)
depositAmount = fields.Float(required=False, allow_none=True)
customerNotes = fields.String(required=False, allow_none=True)
roomTypes = fields.List(fields.Dict(required=False, allow_none=True))
reallocationPropertyId = fields.String(required=False, allow_none=True)
additionalInfo = fields.List(fields.Dict(required=False, allow_none=True))
guestsFilled = fields.Boolean(required=False, allow_none=True)
guests = fields.List(NestedModel("civitfun.checkin.partner.info"))


class CivitfunBookingResults(Datamodel):
_name = "civitfun.booking.results"

success = fields.Boolean(required=False, allow_none=True)
message = fields.String(required=False, allow_none=True)
bookings = fields.List(NestedModel("civitfun.reservation.info"))
15 changes: 15 additions & 0 deletions pms_civitfun/datamodels/pms_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from marshmallow import fields

from odoo.addons.datamodel.core import Datamodel


class CivitfunApiRestUserInput(Datamodel):
_name = "civitfun.api.rest.user.input"
propertyId = fields.String(required=True, allow_none=False)


class CivitfunApiRestUserOutput(Datamodel):
_name = "civitfun.api.rest.user.output"
status = fields.String(required=True, allow_none=False)
message = fields.String(required=True, allow_none=False)
token = fields.String(required=False, allow_none=True)
88 changes: 88 additions & 0 deletions pms_civitfun/http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from werkzeug.exceptions import (
BadRequest,
Forbidden,
HTTPException,
InternalServerError,
NotFound,
Unauthorized,
)

from odoo.exceptions import (
AccessDenied,
AccessError,
MissingError,
UserError,
ValidationError,
)
from odoo.http import HttpRequest, Root, SessionExpiredException
from odoo.loglevels import ustr

from odoo.addons.base_rest.http import HttpRestRequest, wrapJsonException


class HttpRestRequestCivitfun(HttpRestRequest):
def __init__(self, httprequest):
super(HttpRestRequestCivitfun, self).__init__(httprequest)

def _handle_exception(self, exception):
"""Called within an except block to allow converting exceptions
to abitrary responses. Anything returned (except None) will
be used as response."""
if isinstance(exception, SessionExpiredException):
# we don't want to return the login form as plain html page
# we want to raise a proper exception
return wrapJsonException(Unauthorized(ustr(exception)))
try:
return super(HttpRequest, self)._handle_exception(exception)
except MissingError as e:
extra_info = getattr(e, "rest_json_info", None)
return wrapJsonException(
NotFound(ustr(e)), include_description=True, extra_info=extra_info
)
except (AccessError, AccessDenied) as e:
extra_info = getattr(e, "rest_json_info", None)
return wrapJsonException(
Forbidden(ustr(e)), include_description=True, extra_info=extra_info
)
except (UserError, ValidationError) as e:
extra_info = getattr(e, "rest_json_info", None)
return wrapJsonException(
BadRequest(e.args[0]), include_description=True, extra_info=extra_info
)
except HTTPException as e:
extra_info = getattr(e, "rest_json_info", None)
return wrapJsonException(e, include_description=True, extra_info=extra_info)
except Unauthorized as e:
extra_info = getattr(e, "rest_json_info", None)
return (
wrapJsonException(e, include_description=True, extra_info=extra_info),
)

except Exception as e: # flake8: noqa: E722
extra_info = getattr(e, "rest_json_info", None)
return wrapJsonException(InternalServerError(e), extra_info=extra_info)


ori_get_request = Root.get_request


def get_request(self, httprequest):
if "civitfun" in httprequest.path:
if (
"HTTP_CIVITFUN_STANDARD3_REQUEST" in httprequest.environ
and httprequest.environ.get("Civitfun-Standard3-Request") == "authorization"
):
httprequest.environ["HTTP_AUTHORIZATION"] = httprequest.environ[
"Civitfun-Standard3-Request"
]
if (
"CONTENT_TYPE" in httprequest.environ
and httprequest.environ.get("CONTENT_TYPE") == "application/json"
and not len(httprequest.get_data().decode(httprequest.charset)) > 0
):
httprequest.environ["CONTENT_TYPE"] = "application/json-civitfun"
return HttpRestRequestCivitfun(httprequest)
return ori_get_request(self, httprequest)


Root.get_request = get_request
2 changes: 2 additions & 0 deletions pms_civitfun/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import pms_property
from . import res_partner_id_category
Loading

0 comments on commit 8df2741

Please sign in to comment.