[ADD] fixed price constraint between min and max price

This commit is contained in:
Pablo
2019-02-19 19:49:15 +01:00
parent d2bf3ae163
commit 1094dc266b

View File

@@ -1,7 +1,8 @@
# Copyright 2018 Alexandre Díaz <dev@redneboa.es>
# 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'