mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD] hour format constrains
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
# Copyright 2019 Dario Lodeiros
|
# Copyright 2019 Dario Lodeiros
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
import re
|
import time
|
||||||
|
|
||||||
from odoo import _, api, fields, models
|
from odoo import _, api, fields, models
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
@@ -56,10 +56,30 @@ class PmsProperty(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Constraints and onchanges
|
# Constraints and onchanges
|
||||||
@api.constrains("default_arrival_hour", "default_departure_hour")
|
@api.constrains("default_arrival_hour")
|
||||||
def _check_hours(self):
|
def _check_arrival_hour(self):
|
||||||
r = re.compile("[0-2][0-9]:[0-5][0-9]")
|
for record in self:
|
||||||
if not r.match(self.default_arrival_hour):
|
try:
|
||||||
raise ValidationError(_("Invalid arrival hour (Format: HH:mm)"))
|
time.strptime(record.default_arrival_hour, "%H:%M")
|
||||||
if not r.match(self.default_departure_hour):
|
return True
|
||||||
raise ValidationError(_("Invalid departure hour (Format: HH:mm)"))
|
except ValueError:
|
||||||
|
raise ValidationError(
|
||||||
|
_(
|
||||||
|
"Format Arrival Hour (HH:MM) Error: %s",
|
||||||
|
record.default_arrival_hour,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.constrains("default_departure_hour")
|
||||||
|
def _check_departure_hour(self):
|
||||||
|
for record in self:
|
||||||
|
try:
|
||||||
|
time.strptime(record.default_departure_hour, "%H:%M")
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
raise ValidationError(
|
||||||
|
_(
|
||||||
|
"Format Departure Hour (HH:MM) Error: %s",
|
||||||
|
record.default_departure_hour,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
# Copyright 2017-2018 Alexandre Díaz
|
# Copyright 2017-2018 Alexandre Díaz
|
||||||
# Copyright 2017 Dario Lodeiros
|
# Copyright 2017 Dario Lodeiros
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime, time, timedelta
|
import time
|
||||||
|
|
||||||
from odoo import _, api, fields, models
|
from odoo import _, api, fields, models
|
||||||
from odoo.exceptions import UserError, ValidationError
|
from odoo.exceptions import UserError, ValidationError
|
||||||
@@ -39,7 +40,7 @@ class PmsReservation(models.Model):
|
|||||||
if folio and folio.reservation_ids:
|
if folio and folio.reservation_ids:
|
||||||
return folio.reservation_ids[0].checkout
|
return folio.reservation_ids[0].checkout
|
||||||
else:
|
else:
|
||||||
return fields.Date.today() + timedelta(1)
|
return fields.Date.today() + datetime.timedelta(1)
|
||||||
|
|
||||||
def _get_default_arrival_hour(self):
|
def _get_default_arrival_hour(self):
|
||||||
folio = False
|
folio = False
|
||||||
@@ -470,8 +471,8 @@ class PmsReservation(models.Model):
|
|||||||
for reservation in self:
|
for reservation in self:
|
||||||
checkin_hour = int(reservation.arrival_hour[0:2])
|
checkin_hour = int(reservation.arrival_hour[0:2])
|
||||||
checkin_minut = int(reservation.arrival_hour[3:5])
|
checkin_minut = int(reservation.arrival_hour[3:5])
|
||||||
checkin_time = time(checkin_hour, checkin_minut)
|
checkin_time = datetime.time(checkin_hour, checkin_minut)
|
||||||
reservation.checkin_datetime = datetime.combine(
|
reservation.checkin_datetime = datetime.datetime.combine(
|
||||||
reservation.checkin, checkin_time
|
reservation.checkin, checkin_time
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -480,8 +481,8 @@ class PmsReservation(models.Model):
|
|||||||
for reservation in self:
|
for reservation in self:
|
||||||
checkout_hour = int(reservation.departure_hour[0:2])
|
checkout_hour = int(reservation.departure_hour[0:2])
|
||||||
checkout_minut = int(reservation.departure_hour[3:5])
|
checkout_minut = int(reservation.departure_hour[3:5])
|
||||||
checkout_time = time(checkout_hour, checkout_minut)
|
checkout_time = datetime.time(checkout_hour, checkout_minut)
|
||||||
reservation.checkout_datetime = datetime.combine(
|
reservation.checkout_datetime = datetime.datetime.combine(
|
||||||
reservation.checkout, checkout_time
|
reservation.checkout, checkout_time
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -531,7 +532,7 @@ class PmsReservation(models.Model):
|
|||||||
cmds = []
|
cmds = []
|
||||||
days_diff = (reservation.checkout - reservation.checkin).days
|
days_diff = (reservation.checkout - reservation.checkin).days
|
||||||
for i in range(0, days_diff):
|
for i in range(0, days_diff):
|
||||||
idate = reservation.checkin + timedelta(days=i)
|
idate = reservation.checkin + datetime.timedelta(days=i)
|
||||||
old_line = reservation.reservation_line_ids.filtered(
|
old_line = reservation.reservation_line_ids.filtered(
|
||||||
lambda r: r.date == idate
|
lambda r: r.date == idate
|
||||||
)
|
)
|
||||||
@@ -914,6 +915,28 @@ class PmsReservation(models.Model):
|
|||||||
_("No person from reserve %s has arrived", record.name)
|
_("No person from reserve %s has arrived", record.name)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@api.constrains("arrival_hour")
|
||||||
|
def _check_arrival_hour(self):
|
||||||
|
for record in self:
|
||||||
|
try:
|
||||||
|
time.strptime(record.arrival_hour, "%H:%M")
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
raise ValidationError(
|
||||||
|
_("Format Arrival Hour (HH:MM) Error: %s", record.arrival_hour)
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.constrains("departure_hour")
|
||||||
|
def _check_departure_hour(self):
|
||||||
|
for record in self:
|
||||||
|
try:
|
||||||
|
time.strptime(record.departure_hour, "%H:%M")
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
raise ValidationError(
|
||||||
|
_("Format Departure Hour (HH:MM) Error: %s", record.departure_hour)
|
||||||
|
)
|
||||||
|
|
||||||
# @api.constrains("reservation_type", "partner_id")
|
# @api.constrains("reservation_type", "partner_id")
|
||||||
# def _check_partner_reservation(self):
|
# def _check_partner_reservation(self):
|
||||||
# for reservation in self:
|
# for reservation in self:
|
||||||
|
|||||||
Reference in New Issue
Block a user