Merge pull request #13 from commitsun/14.0-pms_advanced_pricelist

[ADD] init_hook.py to activate advanced pricelist when pms is installed
This commit is contained in:
Darío Lodeiros
2020-11-15 16:38:45 +01:00
committed by GitHub
7 changed files with 75 additions and 0 deletions

View File

@@ -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

View File

@@ -72,4 +72,5 @@
"qweb": [
"static/src/xml/pms_base_templates.xml",
],
"post_init_hook": "post_init_hook",
}

10
pms/init_hook.py Normal file
View File

@@ -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"
)

View File

@@ -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

View File

@@ -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")
)

View File

@@ -20,3 +20,4 @@
#
##############################################################################
from . import test_pms_reservation
from . import test_pms_pricelist

View File

@@ -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()