From 604234fb6cb0aacbf2160e81df96a6bd54020259 Mon Sep 17 00:00:00 2001 From: Pablo Date: Tue, 5 Mar 2019 01:34:44 +0100 Subject: [PATCH] [WIP] Add virtual pricelists --- hotel/models/inherited_product_pricelist.py | 5 ++++ .../models/product_pricelist/common.py | 28 ++++++++++++++++++- .../views/channel_product_pricelist_views.xml | 1 + .../inherited_product_pricelist_views.xml | 5 ++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/hotel/models/inherited_product_pricelist.py b/hotel/models/inherited_product_pricelist.py index 4df33a799..095a19cfa 100644 --- a/hotel/models/inherited_product_pricelist.py +++ b/hotel/models/inherited_product_pricelist.py @@ -2,11 +2,16 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models, fields, api + class ProductPricelist(models.Model): _inherit = 'product.pricelist' is_staff = fields.Boolean('Is Staff') + is_daily_plan = fields.Boolean('Daily Pricing Plan', default=True, + help = "Check if the pricing plan is daily. " + "Note that only daily plans can be edited on " + "the Hotel Calendar Management.") @api.multi @api.depends('name') def name_get(self): diff --git a/hotel_channel_connector/models/product_pricelist/common.py b/hotel_channel_connector/models/product_pricelist/common.py index 0a2603c4b..a1ea574c5 100644 --- a/hotel_channel_connector/models/product_pricelist/common.py +++ b/hotel_channel_connector/models/product_pricelist/common.py @@ -18,7 +18,6 @@ class ChannelProductPricelist(models.Model): string='Pricelist', required=True, ondelete='cascade') - is_daily_plan = fields.Boolean("Channel Daily Plan", default=True, old_name='wdaily_plan') @job(default_channel='root.channel') @api.multi @@ -54,6 +53,7 @@ class ChannelProductPricelist(models.Model): importer = work.component(usage='product.pricelist.importer') return importer.import_pricing_plans() + class ProductPricelist(models.Model): _inherit = 'product.pricelist' @@ -62,6 +62,28 @@ class ProductPricelist(models.Model): inverse_name='odoo_id', string='Hotel Channel Connector Bindings') + is_virtual_plan = fields.Boolean("Is a Virtual Pricing Plan", compute='_compute_virtual_plan', readonly="True", + help="A virtual plan is based on another Pricelist " + "with a fixed or percentage variation.") + + @api.depends('item_ids') + def _compute_virtual_plan(self): + for record in self: + record.is_virtual_plan = True + if any(item.applied_on != '3_global' + or (item.date_start or item.date_end) + or item.compute_price != 'formula' + or item.base != 'pricelist' + or not item.base_pricelist_id.is_daily_plan + or (item.price_discount != 0 and item.price_surcharge != 0) + or item.min_quantity != 0 + or item.price_round != 0 + or item.price_min_margin != 0 + or item.price_max_margin != 0 + for item in record.item_ids): + record.is_virtual_plan = False + + @api.multi @api.depends('name') def name_get(self): @@ -95,6 +117,8 @@ class ProductPricelist(models.Model): action['context'] = { 'default_odoo_id': self.id, 'default_name': self.name, + 'default_is_daily_plan': self.is_daily_plan, + 'default_is_virtual_plan': self.is_virtual_plan, } return action @@ -105,6 +129,7 @@ class ProductPricelist(models.Model): msg += _(" The pricelist [%s] should be delete from the channel manager.") % channel_bind_ids.get_external_id raise UserError(msg) + class BindingProductPricelistListener(Component): _name = 'binding.product.pricelist.listener' _inherit = 'base.connector.listener' @@ -116,6 +141,7 @@ class BindingProductPricelistListener(Component): for binding in record.channel_bind_ids: binding.update_plan_name() + class ChannelBindingProductPricelistListener(Component): _name = 'channel.binding.product.pricelist.listener' _inherit = 'base.connector.listener' diff --git a/hotel_channel_connector/views/channel_product_pricelist_views.xml b/hotel_channel_connector/views/channel_product_pricelist_views.xml index dbd91ec27..61810b308 100644 --- a/hotel_channel_connector/views/channel_product_pricelist_views.xml +++ b/hotel_channel_connector/views/channel_product_pricelist_views.xml @@ -13,6 +13,7 @@ + diff --git a/hotel_channel_connector/views/inherited_product_pricelist_views.xml b/hotel_channel_connector/views/inherited_product_pricelist_views.xml index 4a12b3f05..c059a6bea 100644 --- a/hotel_channel_connector/views/inherited_product_pricelist_views.xml +++ b/hotel_channel_connector/views/inherited_product_pricelist_views.xml @@ -21,6 +21,11 @@ confirm="Disconnecting will automatically delete the pricelist in the Channel. Do you want to proceed?" /> + + + + +