From 50e8b7bf0365d25b313a1ad36b67c6603491bb50 Mon Sep 17 00:00:00 2001 From: padomi Date: Thu, 29 Oct 2020 13:40:40 +0100 Subject: [PATCH 1/7] [IMP] pms: add children capacity --- pms/models/pms_reservation.py | 4 ++++ pms/models/pms_reservation_line.py | 5 +++-- pms/tests/test_pms_reservation.py | 30 +++++++++++++++++++++++++---- pms/views/pms_reservation_views.xml | 4 ++++ 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index 10b8dc92e..df687a661 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -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, diff --git a/pms/models/pms_reservation_line.py b/pms/models/pms_reservation_line.py index a844d9f25..a8a9f140f 100644 --- a/pms/models/pms_reservation_line.py +++ b/pms/models/pms_reservation_line.py @@ -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: diff --git a/pms/tests/test_pms_reservation.py b/pms/tests/test_pms_reservation.py index 0e568ff83..3fc967ce9 100644 --- a/pms/tests/test_pms_reservation.py +++ b/pms/tests/test_pms_reservation.py @@ -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, + } + ) diff --git a/pms/views/pms_reservation_views.xml b/pms/views/pms_reservation_views.xml index 6cfd976e7..ce6b98f0f 100644 --- a/pms/views/pms_reservation_views.xml +++ b/pms/views/pms_reservation_views.xml @@ -301,6 +301,10 @@ name="children" attrs="{'invisible': [('reservation_type','in',('out'))]}" /> + From 4891c4de7c19800616a8ecb24a79705a190bb387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brais=20Abeij=C3=B3n?= Date: Fri, 6 Nov 2020 15:08:46 +0100 Subject: [PATCH 2/7] [WIP] pms: Add Test Case for advanced pricelist --- pms/tests/__init__.py | 1 + pms/tests/test_pms_pricelist.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 pms/tests/test_pms_pricelist.py diff --git a/pms/tests/__init__.py b/pms/tests/__init__.py index 09291fa9f..cfbd2f1f4 100644 --- a/pms/tests/__init__.py +++ b/pms/tests/__init__.py @@ -20,3 +20,4 @@ # ############################################################################## from . import test_pms_reservation +from . import test_pms_pricelist diff --git a/pms/tests/test_pms_pricelist.py b/pms/tests/test_pms_pricelist.py new file mode 100644 index 000000000..f1ed184d8 --- /dev/null +++ b/pms/tests/test_pms_pricelist.py @@ -0,0 +1,16 @@ +from odoo.tests import common, tagged + + +@tagged("standard", "nice") +class TestPmsPricelist(common.TransactionCase): + def test_advanced_pricelist_exists(self): + + # ARRANGE + key = "product.product_pricelist_setting" + value = "Advance" + + # ACT + found_value = self.env["ir.config_parameter"].sudo().get_param(key) + + # ASSERT + self.assertEqual(found_value, value, "The register wasn't created") From 91aa2d55f8475fcae943b97e02e46f92fd7c82cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brais=20Abeij=C3=B3n?= Date: Fri, 6 Nov 2020 15:36:46 +0100 Subject: [PATCH 3/7] [ADD] pms: Added init_hook.py to activate advanced pricelist when pms is installed --- pms/__init__.py | 1 + pms/__manifest__.py | 1 + pms/init_hook.py | 10 ++++++++++ 3 files changed, 12 insertions(+) create mode 100644 pms/init_hook.py diff --git a/pms/__init__.py b/pms/__init__.py index 3f3f8679b..8197a1c05 100644 --- a/pms/__init__.py +++ b/pms/__init__.py @@ -1,5 +1,6 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import models +from .init_hook import post_init_hook # from . import wizard diff --git a/pms/__manifest__.py b/pms/__manifest__.py index 965ad2ae1..bddefb43f 100644 --- a/pms/__manifest__.py +++ b/pms/__manifest__.py @@ -72,4 +72,5 @@ "qweb": [ "static/src/xml/pms_base_templates.xml", ], + "post_init_hook": "post_init_hook", } diff --git a/pms/init_hook.py b/pms/init_hook.py new file mode 100644 index 000000000..3e7e4c4f6 --- /dev/null +++ b/pms/init_hook.py @@ -0,0 +1,10 @@ +from odoo import SUPERUSER_ID +from odoo.api import Environment + + +def post_init_hook(cr, _): + with Environment.manage(): + env = Environment(cr, SUPERUSER_ID, {}) + env["ir.config_parameter"].sudo().set_param( + "product.product_pricelist_setting", "Advance" + ) From baa037621f5dfac098e0c06b0096067ca1a1dc44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Mon, 9 Nov 2020 14:45:20 +0100 Subject: [PATCH 4/7] [FIX] Called _compute_amount folio from reservation --- pms/models/pms_reservation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index df687a661..99fdde6d3 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -946,7 +946,7 @@ class PmsReservation(models.Model): _logger.info("Modified Reservation - No Penalty") record.write({"state": "cancelled", "cancelled_reason": cancel_reason}) # record._compute_cancelled_discount() - record.folio_id.compute_amount() + record.folio_id._compute_amount() def compute_cancelation_reason(self): self.ensure_one() From acacebfc7b5c6f3b4b0be2ccbda30768d9261fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brais=20Abeij=C3=B3n?= Date: Wed, 11 Nov 2020 12:03:37 +0100 Subject: [PATCH 5/7] [ADD] pms: Added init_hook.py to activate advanced pricelist when pms is installed --- pms/__init__.py | 1 + pms/__manifest__.py | 1 + pms/init_hook.py | 10 ++++++++++ 3 files changed, 12 insertions(+) create mode 100644 pms/init_hook.py diff --git a/pms/__init__.py b/pms/__init__.py index 3f3f8679b..8197a1c05 100644 --- a/pms/__init__.py +++ b/pms/__init__.py @@ -1,5 +1,6 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import models +from .init_hook import post_init_hook # from . import wizard diff --git a/pms/__manifest__.py b/pms/__manifest__.py index 965ad2ae1..bddefb43f 100644 --- a/pms/__manifest__.py +++ b/pms/__manifest__.py @@ -72,4 +72,5 @@ "qweb": [ "static/src/xml/pms_base_templates.xml", ], + "post_init_hook": "post_init_hook", } diff --git a/pms/init_hook.py b/pms/init_hook.py new file mode 100644 index 000000000..5f6e4e47a --- /dev/null +++ b/pms/init_hook.py @@ -0,0 +1,10 @@ +from odoo import SUPERUSER_ID +from odoo.api import Environment + + +def post_init_hook(cr, _): + with Environment.manage(): + env = Environment(cr, SUPERUSER_ID, {}) + env["ir.config_parameter"].sudo().set_param( + "product.product_pricelist_setting", "advanced" + ) From 710db94d1808fb98674833d0766a7134ce4384e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brais=20Abeij=C3=B3n?= Date: Wed, 11 Nov 2020 12:11:21 +0100 Subject: [PATCH 6/7] [IMP] add test to check if the value of product.product_pricelist_setting was modified or deleted --- pms/tests/test_pms_pricelist.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/pms/tests/test_pms_pricelist.py b/pms/tests/test_pms_pricelist.py index f1ed184d8..d10756319 100644 --- a/pms/tests/test_pms_pricelist.py +++ b/pms/tests/test_pms_pricelist.py @@ -1,3 +1,4 @@ +from odoo.exceptions import ValidationError from odoo.tests import common, tagged @@ -7,10 +8,32 @@ class TestPmsPricelist(common.TransactionCase): # ARRANGE key = "product.product_pricelist_setting" - value = "Advance" + value = "advanced" # ACT found_value = self.env["ir.config_parameter"].sudo().get_param(key) # ASSERT - self.assertEqual(found_value, value, "The register wasn't created") + self.assertEqual(found_value, value, "Parameter doesn't exist") + + def test_product_pricelist_setting_modified(self): + + # ARRANGE + key = "product.product_pricelist_setting" + value = "basic" + + # ACT & ASSERT + with self.assertRaises(ValidationError), self.cr.savepoint(): + self.env["ir.config_parameter"].set_param(key, value) + + def test_product_pricelist_setting_unlink(self): + + # ARRANGE + key = "product.product_pricelist_setting" + value = "advanced" + + # ACT & ASSERT + with self.assertRaises(ValidationError), self.cr.savepoint(): + self.env["ir.config_parameter"].search( + [("key", "=", key), ("value", "=", value)] + ).unlink() From 00f129811416803b1f0746a0f7f65c92ea553375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brais=20Abeij=C3=B3n?= Date: Wed, 11 Nov 2020 12:46:16 +0100 Subject: [PATCH 7/7] [ADD] inheritence of ir.config_parameter --- pms/models/__init__.py | 1 + pms/models/ir_config_parameter.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 pms/models/ir_config_parameter.py diff --git a/pms/models/__init__.py b/pms/models/__init__.py index 1547464c0..5343f0ca8 100644 --- a/pms/models/__init__.py +++ b/pms/models/__init__.py @@ -4,6 +4,7 @@ from . import ir_http from . import ir_sequence +from . import ir_config_parameter # from . import payment_return from . import pms_board_service_room_type diff --git a/pms/models/ir_config_parameter.py b/pms/models/ir_config_parameter.py new file mode 100644 index 000000000..a561369ac --- /dev/null +++ b/pms/models/ir_config_parameter.py @@ -0,0 +1,22 @@ +from odoo import _, api, models +from odoo.exceptions import ValidationError + + +class IrConfigParameter(models.Model): + _inherit = "ir.config_parameter" + + def unlink(self): + for record in self: + if ( + record.key == "product.product_pricelist_setting" + and record.value == "advanced" + ): + raise ValidationError(_("Cannot delete this parameter")) + return super().unlink() + + @api.constrains("key", "value") + def check_value(self): + if self.key == "product.product_pricelist_setting" and self.value != "advanced": + raise ValidationError( + _("The parameter Advanced price rules cannot be modified") + )