From 1094dc266b77e343982438bd78d8db40cb939ba8 Mon Sep 17 00:00:00 2001 From: Pablo Date: Tue, 19 Feb 2019 19:49:15 +0100 Subject: [PATCH] [ADD] fixed price constraint between min and max price --- .../models/product_pricelist_item/common.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hotel_channel_connector/models/product_pricelist_item/common.py b/hotel_channel_connector/models/product_pricelist_item/common.py index 0dbc238c4..27741959d 100644 --- a/hotel_channel_connector/models/product_pricelist_item/common.py +++ b/hotel_channel_connector/models/product_pricelist_item/common.py @@ -1,7 +1,8 @@ # Copyright 2018 Alexandre Díaz # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, models, fields +from odoo import api, models, fields, _ +from odoo.exceptions import ValidationError from odoo.addons.queue_job.job import job from odoo.addons.component.core import Component from odoo.addons.component_event import skip_if @@ -49,6 +50,17 @@ class ProductPricelistItem(models.Model): inverse_name='odoo_id', string='Hotel Channel Connector Bindings') + @api.constrains('fixed_price') + def _check_fixed_price(self): + for record in self: + channel_room_type = self.env['channel.hotel.room.type'].search( + [('product_tmpl_id', '=', record.product_tmpl_id.id)]) + if record.fixed_price < channel_room_type.min_price or \ + record.fixed_price > channel_room_type.max_price: + msg = _("The room type '%s' limits the price between '%s' and '%s'.") \ + % (record.name, channel_room_type.min_price, channel_room_type.max_price) + raise ValidationError(msg) + class BindingProductPricelistItemListener(Component): _name = 'binding.product.pricelist.item.listener' _inherit = 'base.connector.listener'