mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms: add add exp date to jwt data
This commit is contained in:
committed by
Darío Lodeiros
parent
78da297eb4
commit
41a1df4fda
@@ -2,4 +2,3 @@ from . import controllers
|
||||
from . import datamodels
|
||||
from . import models
|
||||
from . import services
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from odoo.addons.base_rest.controllers import main
|
||||
|
||||
from ..lib_jwt.jwt_http import jwt_http
|
||||
from ..lib_jwt.validator import validator
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ class PmsReservationShortInfo(Datamodel):
|
||||
partner = fields.String(required=True, allow_none=False)
|
||||
checkin = fields.String(required=True, allow_none=False)
|
||||
checkout = fields.String(required=True, allow_none=False)
|
||||
preferred_room_id = fields.String(required=True, allow_none=False)
|
||||
room_type_id = fields.String(required=True, allow_none=False)
|
||||
preferredRoomId = fields.String(required=True, allow_none=False)
|
||||
roomTypeId = fields.String(required=True, allow_none=False)
|
||||
name = fields.String(required=True, allow_none=False)
|
||||
partner_requests = fields.String(required=False, allow_none=True)
|
||||
partnerRequests = fields.String(required=False, allow_none=True)
|
||||
pwaActionButtons = fields.Dict(required=False, allow_none=True)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import datetime
|
||||
|
||||
import simplejson as json
|
||||
|
||||
from odoo import http
|
||||
@@ -61,10 +63,7 @@ class JwtHttp:
|
||||
:param data=None data to return
|
||||
:param code=200 http status code
|
||||
"""
|
||||
print('response')
|
||||
print('response')
|
||||
print('response')
|
||||
print('response')
|
||||
|
||||
payload = json.dumps(
|
||||
{
|
||||
"success": success,
|
||||
@@ -108,9 +107,12 @@ class JwtHttp:
|
||||
|
||||
# login success, generate token
|
||||
user = request.env.user.read(return_fields)[0]
|
||||
token = validator.create_token(user)
|
||||
exp = datetime.datetime.utcnow() + datetime.timedelta(minutes=3)
|
||||
token = validator.create_token(user, exp)
|
||||
|
||||
return self.response(data={"user": user, "token": token})
|
||||
return self.response(
|
||||
data={"user": user, "exp": json.dumps(exp.isoformat()), "token": token}
|
||||
)
|
||||
|
||||
def do_logout(self, token):
|
||||
request.session.logout()
|
||||
|
||||
@@ -26,9 +26,8 @@ class Validator:
|
||||
# (in form company?)
|
||||
return "CHANGE THIS KEY"
|
||||
|
||||
def create_token(self, user):
|
||||
def create_token(self, user, exp):
|
||||
try:
|
||||
exp = datetime.datetime.utcnow() + datetime.timedelta(days=30)
|
||||
payload = {
|
||||
"exp": exp,
|
||||
"iat": datetime.datetime.utcnow(),
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
from . import res_users
|
||||
from . import jwt_access_token
|
||||
from . import pms_reservation
|
||||
|
||||
@@ -7,10 +7,7 @@ class JwtAccessToken(models.Model):
|
||||
_name = "jwt_provider.access_token"
|
||||
_description = "Store user access token for one-time-login"
|
||||
|
||||
token = fields.Char(
|
||||
"Access Token",
|
||||
required=True
|
||||
)
|
||||
token = fields.Char("Access Token", required=True)
|
||||
user_id = fields.Many2one(
|
||||
comodel_name="res.users",
|
||||
string="User",
|
||||
|
||||
61
pms_api_rest/models/pms_reservation.py
Normal file
61
pms_api_rest/models/pms_reservation.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import json
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class PmsReservation(models.Model):
|
||||
_inherit = "pms.reservation"
|
||||
|
||||
pwa_action_buttons = fields.Char(compute="_compute_pwa_action_buttons")
|
||||
|
||||
def _compute_pwa_action_buttons(self):
|
||||
"""Return ordered button list, where the first button is
|
||||
the preditive action, the next are active actions:
|
||||
- "Assign": Predictive: Reservation by assign
|
||||
Active- Idem
|
||||
- "checkin": Predictive- state 'confirm' and checkin day
|
||||
Active- Idem and assign
|
||||
- "checkout": Predictive- Pay, onboard and checkout day
|
||||
Active- Onboard and checkout day
|
||||
- "Paymen": Predictive- Onboard and pending amount > 0
|
||||
Active- pending amount > 0
|
||||
- "Invoice": Predictive- qty invoice > 0, onboard, pending amount = 0
|
||||
Active- qty invoice > 0
|
||||
- "Cancel": Predictive- Never
|
||||
Active- state in draft, confirm, onboard, full onboard
|
||||
"""
|
||||
for reservation in self:
|
||||
active_buttons = {}
|
||||
for k in ["Assign", "Checkin", "Checkout", "Payment", "Invoice", "Cancel"]:
|
||||
if k == "Assign":
|
||||
if reservation.to_assign:
|
||||
active_buttons[k] = True
|
||||
else:
|
||||
active_buttons[k] = False
|
||||
elif k == "Checkin":
|
||||
if reservation.allowed_checkin:
|
||||
active_buttons[k] = True
|
||||
else:
|
||||
active_buttons[k] = False
|
||||
elif k == "Checkout":
|
||||
if reservation.allowed_checkout:
|
||||
active_buttons[k] = True
|
||||
else:
|
||||
active_buttons[k] = False
|
||||
elif k == "Payment":
|
||||
if reservation.folio_pending_amount > 0:
|
||||
active_buttons[k] = True
|
||||
else:
|
||||
active_buttons[k] = False
|
||||
elif k == "Invoice":
|
||||
if reservation.invoice_status == "to invoice":
|
||||
active_buttons[k] = True
|
||||
else:
|
||||
active_buttons[k] = False
|
||||
elif k == "Cancel":
|
||||
if reservation.allowed_cancel:
|
||||
active_buttons[k] = True
|
||||
else:
|
||||
active_buttons[k] = False
|
||||
|
||||
reservation.pwa_action_buttons = json.dumps(active_buttons)
|
||||
@@ -1,7 +1,7 @@
|
||||
import logging
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import AccessDenied, ValidationError
|
||||
from odoo import api, fields, models
|
||||
from odoo.exceptions import AccessDenied
|
||||
|
||||
from ..lib_jwt.validator import validator
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_jwt_access_token,Read jwt access token,model_jwt_provider_access_token,,1,0,0,0
|
||||
access_jwt_access_token,Read jwt access token,model_jwt_provider_access_token,,1,0,0,0
|
||||
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import json
|
||||
|
||||
from odoo.addons.base_rest import restapi
|
||||
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
||||
from odoo.addons.component.core import Component
|
||||
@@ -15,7 +17,7 @@ class PmsReservationService(Component):
|
||||
[
|
||||
"/",
|
||||
],
|
||||
"GET"
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
input_param=Datamodel("pms.reservation.search.param"),
|
||||
@@ -30,8 +32,12 @@ class PmsReservationService(Component):
|
||||
domain.append(("id", "=", reservation_search_param.id))
|
||||
res = []
|
||||
PmsReservationShortInfo = self.env.datamodels["pms.reservation.short.info"]
|
||||
for reservation in self.env["pms.reservation"].sudo().search(
|
||||
domain,
|
||||
for reservation in (
|
||||
self.env["pms.reservation"]
|
||||
.sudo()
|
||||
.search(
|
||||
domain,
|
||||
)
|
||||
):
|
||||
res.append(
|
||||
PmsReservationShortInfo(
|
||||
@@ -39,13 +45,19 @@ class PmsReservationService(Component):
|
||||
partner=reservation.partner_id.name,
|
||||
checkin=str(reservation.checkin),
|
||||
checkout=str(reservation.checkout),
|
||||
preferred_room_id=reservation.preferred_room_id.name
|
||||
preferredRoomId=reservation.preferred_room_id.name
|
||||
if reservation.preferred_room_id
|
||||
else "",
|
||||
room_type_id=reservation.room_type_id.name
|
||||
roomTypeId=reservation.room_type_id.name
|
||||
if reservation.room_type_id
|
||||
else "",
|
||||
name=reservation.name,
|
||||
partnerRequests=reservation.partner_requests
|
||||
if reservation.partner_requests
|
||||
else "",
|
||||
pwaActionButtons=json.loads(reservation.pwa_action_buttons)
|
||||
if reservation.pwa_action_buttons
|
||||
else {},
|
||||
)
|
||||
)
|
||||
return res
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
# generated from manifests external_dependencies
|
||||
bs4
|
||||
jwt
|
||||
marshmallow
|
||||
pycountry
|
||||
simplejson
|
||||
xlrd
|
||||
|
||||
1
setup/pms_api_rest/odoo/addons/pms_api_rest
Symbolic link
1
setup/pms_api_rest/odoo/addons/pms_api_rest
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../pms_api_rest
|
||||
6
setup/pms_api_rest/setup.py
Normal file
6
setup/pms_api_rest/setup.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['setuptools-odoo'],
|
||||
odoo_addon=True,
|
||||
)
|
||||
Reference in New Issue
Block a user