mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms: add children capacity
This commit is contained in:
@@ -228,6 +228,10 @@ class PmsReservation(models.Model):
|
||||
store=True,
|
||||
readonly=False,
|
||||
)
|
||||
children_occupying = fields.Integer(
|
||||
string="Children occupying",
|
||||
)
|
||||
|
||||
children = fields.Integer(
|
||||
"Children",
|
||||
readonly=False,
|
||||
|
||||
@@ -309,8 +309,9 @@ class PmsReservationLine(models.Model):
|
||||
extra_bed = record.reservation_id.service_ids.filtered(
|
||||
lambda r: r.product_id.is_extra_bed is True
|
||||
)
|
||||
if record.reservation_id.adults > record.room_id.get_capacity(
|
||||
len(extra_bed)
|
||||
if (
|
||||
record.reservation_id.adults + record.reservation_id.children_occupying
|
||||
> record.room_id.get_capacity(len(extra_bed))
|
||||
):
|
||||
raise ValidationError(_("Persons can't be higher than room capacity"))
|
||||
# if record.reservation_id.adults == 0:
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
from datetime import timedelta
|
||||
import datetime
|
||||
|
||||
from freezegun import freeze_time
|
||||
|
||||
from odoo import fields
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
from .common import TestHotel
|
||||
|
||||
|
||||
@freeze_time("2012-01-14")
|
||||
class TestPmsReservations(TestHotel):
|
||||
def test_create_reservation(self):
|
||||
today = fields.date.today()
|
||||
checkin = today + timedelta(days=8)
|
||||
checkout = checkin + timedelta(days=11)
|
||||
checkin = today + datetime.timedelta(days=8)
|
||||
checkout = checkin + datetime.timedelta(days=11)
|
||||
demo_user = self.env.ref("base.user_demo")
|
||||
customer = self.env.ref("base.res_partner_12")
|
||||
reservation_vals = {
|
||||
@@ -30,6 +34,24 @@ class TestPmsReservations(TestHotel):
|
||||
)
|
||||
self.assertEqual(
|
||||
reservation.reservation_line_ids[-1].date,
|
||||
checkout - timedelta(1),
|
||||
checkout - datetime.timedelta(1),
|
||||
"Reservation lines don't end in the correct date",
|
||||
)
|
||||
|
||||
def test_manage_children_raise(self):
|
||||
|
||||
# ARRANGE
|
||||
PmsReservation = self.env["pms.reservation"]
|
||||
|
||||
# ACT & ASSERT
|
||||
with self.assertRaises(ValidationError), self.cr.savepoint():
|
||||
|
||||
PmsReservation.create(
|
||||
{
|
||||
"adults": 2,
|
||||
"children_occupying": 1,
|
||||
"checkin": datetime.datetime.now(),
|
||||
"checkout": datetime.datetime.now() + datetime.timedelta(days=1),
|
||||
"room_type_id": self.browse_ref("pms.pms_room_type_0").id,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -301,6 +301,10 @@
|
||||
name="children"
|
||||
attrs="{'invisible': [('reservation_type','in',('out'))]}"
|
||||
/>
|
||||
<field
|
||||
name="children_occupying"
|
||||
attrs="{'invisible': [('children', '=', 0)]}"
|
||||
/>
|
||||
<field name="qty_invoiced" invisible="1" />
|
||||
<field name="qty_to_invoice" invisible="1" />
|
||||
<field name="allowed_room_ids" invisible="1" />
|
||||
|
||||
Reference in New Issue
Block a user