From 098e040b6068a02c67a4ba2d34728c8a6b9d8832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Sun, 20 Nov 2022 10:13:00 +0100 Subject: [PATCH] [ADD]pms: pricelist pms enabled configuration --- pms/models/pms_availability_plan.py | 1 + pms/models/pms_cancelation_rule.py | 1 + pms/models/pms_folio.py | 6 +++- pms/models/pms_property.py | 1 + pms/models/pms_reservation.py | 2 ++ pms/models/pms_sale_channel.py | 1 + pms/models/product_pricelist.py | 5 ++++ pms/models/res_partner.py | 18 ++++++++++++ pms/views/product_pricelist_views.xml | 40 ++++++++++++++++++++++----- pms/wizards/pms_booking_duplicate.py | 2 ++ pms/wizards/pms_booking_engine.py | 7 ++++- pms/wizards/wizard_folio_changes.py | 1 + pms/wizards/wizard_massive_changes.py | 1 + 13 files changed, 77 insertions(+), 9 deletions(-) diff --git a/pms/models/pms_availability_plan.py b/pms/models/pms_availability_plan.py index 68065a699..133418e4a 100644 --- a/pms/models/pms_availability_plan.py +++ b/pms/models/pms_availability_plan.py @@ -39,6 +39,7 @@ class PmsAvailabilityPlan(models.Model): comodel_name="product.pricelist", inverse_name="availability_plan_id", check_pms_properties=True, + domain="[('is_pms_available', '=', True)]", ) rule_ids = fields.One2many( diff --git a/pms/models/pms_cancelation_rule.py b/pms/models/pms_cancelation_rule.py index 6e5bfd776..8bd0c53d3 100644 --- a/pms/models/pms_cancelation_rule.py +++ b/pms/models/pms_cancelation_rule.py @@ -20,6 +20,7 @@ class PmsCancelationRule(models.Model): comodel_name="product.pricelist", inverse_name="cancelation_rule_id", check_pms_properties=True, + domain="[('is_pms_available', '=', True)]", ) pms_property_ids = fields.Many2many( string="Properties", diff --git a/pms/models/pms_folio.py b/pms/models/pms_folio.py index cb92032b1..35c14e0de 100644 --- a/pms/models/pms_folio.py +++ b/pms/models/pms_folio.py @@ -872,7 +872,11 @@ class PmsFolio(models.Model): folio.pricelist_id = folio.reservation_ids.pricelist_id elif folio.agency_id and folio.agency_id.apply_pricelist: folio.pricelist_id = folio.agency_id.property_product_pricelist - elif folio.partner_id and folio.partner_id.property_product_pricelist: + elif ( + folio.partner_id + and folio.partner_id.property_product_pricelist + and folio.partner_id.property_product_pricelist.is_pms_available + ): folio.pricelist_id = folio.partner_id.property_product_pricelist elif not folio.pricelist_id: folio.pricelist_id = folio.pms_property_id.default_pricelist_id diff --git a/pms/models/pms_property.py b/pms/models/pms_property.py index e3aa603b6..e4b6da611 100644 --- a/pms/models/pms_property.py +++ b/pms/models/pms_property.py @@ -57,6 +57,7 @@ class PmsProperty(models.Model): help="The default pricelist used in this property.", comodel_name="product.pricelist", required=True, + domain="[('is_pms_available', '=', True)]", default=lambda self: self.env.ref("product.list0").id, ) default_arrival_hour = fields.Char( diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index 8f5303868..9fe16f460 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -209,6 +209,7 @@ class PmsReservation(models.Model): compute="_compute_pricelist_id", tracking=True, check_pms_properties=True, + domain="[('is_pms_available', '=', True)]", ) user_id = fields.Many2one( string="Reception Manager", @@ -1017,6 +1018,7 @@ class PmsReservation(models.Model): elif ( reservation.partner_id and reservation.partner_id.property_product_pricelist + and reservation.partner_id.property_product_pricelist.is_pms_available and ( not reservation.pricelist_id or not isinstance(reservation.id, models.NewId) diff --git a/pms/models/pms_sale_channel.py b/pms/models/pms_sale_channel.py index 1f60daab1..5049291af 100644 --- a/pms/models/pms_sale_channel.py +++ b/pms/models/pms_sale_channel.py @@ -25,6 +25,7 @@ class PmsSaleChannel(models.Model): column1="pms_sale_channel_id", column2="product_pricelist_id", check_pms_properties=True, + domain="[('is_pms_available', '=', True)]", ) pms_property_ids = fields.Many2many( string="Properties", diff --git a/pms/models/product_pricelist.py b/pms/models/product_pricelist.py index 1582e5b5a..1f2f57067 100644 --- a/pms/models/product_pricelist.py +++ b/pms/models/product_pricelist.py @@ -65,6 +65,11 @@ class ProductPricelist(models.Model): help="Items for which the pricelist is made up", check_pms_properties=True, ) + is_pms_available = fields.Boolean( + string="Available in PMS", + help="If the pricelist is available in the PMS", + default=True, + ) def _compute_price_rule_get_items( self, products_qty_partner, date, uom_id, prod_tmpl_ids, prod_ids, categ_ids diff --git a/pms/models/res_partner.py b/pms/models/res_partner.py index 6c89dbdd5..2cfea1be2 100644 --- a/pms/models/res_partner.py +++ b/pms/models/res_partner.py @@ -925,3 +925,21 @@ class ResPartner(models.Model): ): return True return False + + @api.constrains("is_agency", "property_product_pricelist") + def _check_agency_pricelist(self): + if any( + record.is_agency and not record.property_product_pricelist.is_pms_available + for record in self + ): + raise models.ValidationError( + _( + """ + Agency must have a PMS pricelist, please review the + pricelists configuration (%s) to allow it for PMS, + or the pricelist selected for the agencies: %s + """ + ), + ",".join(self.mapped("property_product_pricelis.name")), + "".join(self.mapped("name")), + ) diff --git a/pms/views/product_pricelist_views.xml b/pms/views/product_pricelist_views.xml index ff7870024..1e0028c86 100644 --- a/pms/views/product_pricelist_views.xml +++ b/pms/views/product_pricelist_views.xml @@ -4,27 +4,51 @@ product.pricelist - + + + + + + + + - - - - - - + + @@ -36,6 +60,7 @@ @@ -48,6 +73,7 @@ type="object" class="oe_stat_button mr-5" icon="fa-magic" + attrs="{'invisible': [('is_pms_available', '=', False)]}" >