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" + ) 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") + ) 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..d10756319 --- /dev/null +++ b/pms/tests/test_pms_pricelist.py @@ -0,0 +1,39 @@ +from odoo.exceptions import ValidationError +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 = "advanced" + + # ACT + found_value = self.env["ir.config_parameter"].sudo().get_param(key) + + # ASSERT + 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()